hdu 3015 树状数组+离散化

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <algorithm>
  4. using namespace std;
  5. struct data
  6. {
  7. __int64 order;
  8. __int64 orign;
  9. __int64 rank;
  10. };
  11. data heigh[100100], coor[100100];
  12. int cmp(const void *a, const void *b)
  13. {
  14. return ( (*(data *)a).order - (*(data *)b).order );
  15. }
  16. int cmp1(const void *a, const void *b)
  17. {
  18. return (*(data *)a).orign - (*(data *)b).orign;
  19. }
  20. /*__int64 cmp1(const void *a, const void *b)
  21. {
  22. }*/
  23. int main()
  24. {
  25. freopen("read.txt", "r", stdin);
  26. __int64 n;
  27. while(~scanf("%d", &n) )
  28. {
  29. for(int i=1; i<=n; i++)
  30. {
  31. scanf("%I64d", &coor[i].orign);
  32. scanf("%I64d", &heigh[i].orign);
  33. coor[i].order = i;
  34. heigh[i].order = i;
  35. }
  36. qsort(coor, n, sizeof(coor[0]), cmp1);
  37. qsort(heigh, n, sizeof(heigh[0]), cmp1);
  38. int sign1, sign2, flag1, flag2;
  39. sign1 = sign2 = 1;
  40. flag1 = coor[1].orign, flag2 = heigh[1].orign;
  41. for(int i=1; i<=n; i++)
  42. {
  43. if(coor[i].orign != flag1)
  44. {
  45. flag1 = coor[i].orign;
  46. coor[i].rank = i+1;
  47. sign1 = i+1;
  48. }
  49. else
  50. coor[i].rank = sign1;
  51. if(heigh[i].orign != flag2)
  52. {
  53. flag2 = heigh[i].orign;
  54. heigh[i].rank = i+1;
  55. sign2 = i+1;
  56. }
  57. else
  58. heigh[i].rank = sign2;
  59. }
  60. //qsort(coor, n, sizeof(coor[0]), cmp);
  61. //qsort(heigh, n, sizeof(heigh[0]), cmp);
  62. //前面是对的, 但是我不知道怎么离散化。
  63. }
  64. return 0;
  65. }

来自为知笔记(Wiz)

附件列表

时间: 2024-10-13 05:35:32

hdu 3015 树状数组+离散化的相关文章

HDU 1394 树状数组+离散化求逆序数

对于求逆序数问题,学会去利用树状数组进行转换求解方式,是很必要的. 一般来说我们求解逆序数,是在给定一串序列里,用循环的方式找到每一个数之前有多少个比它大的数,算法的时间复杂度为o(n2). 那么我们通过树状数组可以明显提高时间效率. 我们可以按照排列的顺序依次将数字放入树状数组中,并依次更新预与之相关联的树状数组元素.那么在将其更新完毕后,我们知道每个数对应的树状数组元素的左边的数肯定比它小,我们在以序列顺序依次更新树状数组时,如果有值在它前面出现,那么它对应的树状数组元素(在这个题目里存放的

hdu 5792 树状数组+离散化+思维

题目大意: Given a sequence A with length n,count how many quadruple (a,b,c,d) satisfies: a≠b≠c≠d,1≤a<b≤n,1≤c<d≤n,Aa<Ab,Ac>Ada≠b≠c≠d,1≤a<b≤n,1≤c<d≤n,Aa<Ab,Ac>Ad. A1,A2?AnA1,A2?An.  1≤n≤500001≤n≤50000  0≤Ai≤1e9 基本思路: 最朴素的思想就是算出所有顺序对所有逆序对

Segment Game (hdu 5372 树状数组+离散化)

Segment Game Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 534    Accepted Submission(s): 132 Problem Description Lillian is a clever girl so that she has lots of fans and often receives gift

hdu 3333(树状数组 + 离散化 + hash)

Turing Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3847    Accepted Submission(s): 1306 Problem Description After inventing Turing Tree, 3xian always felt boring when solving problems a

[hdu 4417]树状数组+离散化+离线处理

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 把数字离散化,一个查询拆成两个查询,每次查询一个前缀的和.主要问题是这个数组是静态的,如果带修改操作就不能离线了. //http://acm.hdu.edu.cn/showproblem.php?pid=4417 #include<bits/stdc++.h> using namespace std; const int maxn=100005; int tree[maxn]; int N;

Swaps and Inversions HDU - 6318 树状数组+离散化

#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> using namespace std; typedef long long ll; const int N=1e5+10; int a[N]; int ra[N]; int tr[N]; int n,x,y; int sz; int lowbit(int x) { return x&-x; } void

C - The Battle of Chibi HDU - 5542 (树状数组+离散化)

Cao Cao made up a big army and was going to invade the whole South China. Yu Zhou was worried about it. He thought the only way to beat Cao Cao is to have a spy in Cao Cao's army. But all generals and soldiers of Cao Cao were loyal, it's impossible t

hdu4325 树状数组+离散化

http://acm.hdu.edu.cn/showproblem.php?pid=4325 Problem Description As is known to all, the blooming time and duration varies between different kinds of flowers. Now there is a garden planted full of flowers. The gardener wants to know how many flower

HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences                                  Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)