标签:des style blog java color os
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2250 Accepted Submission(s): 1092
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 using namespace std; 6 #define N 100005 7 8 int c[N]; 9 int ans[N]; 10 11 struct mem{ 12 int l, r; 13 int val; 14 int id; 15 }a[N]; 16 17 struct node{ 18 int num; 19 int id; 20 }b[N]; 21 22 bool cmp1(mem a,mem b){ 23 return a.val<b.val; 24 } 25 26 bool cmp2(node a,node b){ 27 return a.num<b.num; 28 } 29 30 int lowbit(int x){ 31 return x&(-x); 32 } 33 34 void update(int x){ 35 while(x<N){ 36 c[x]++; 37 x+=lowbit(x); 38 } 39 } 40 41 int get_sum(int x){ 42 int ans=0; 43 while(x>0){ 44 ans+=c[x]; 45 x-=lowbit(x); 46 } 47 return ans; 48 } 49 50 main() 51 { 52 int i, j, k, kase=1; 53 int t; 54 int n, m; 55 cin>>t; 56 while(t--){ 57 cin>>n>>m; 58 memset(c,0,sizeof(c)); 59 for(i=1;i<=n;i++){ 60 scanf("%d",&b[i].num); 61 b[i].id=i; 62 } 63 for(i=1;i<=m;i++){ 64 scanf("%d %d %d",&a[i].l,&a[i].r,&a[i].val); 65 a[i].l++; 66 a[i].r++; 67 a[i].id=i; 68 ans[i]=0; 69 } 70 sort(a+1,a+m+1,cmp1); 71 sort(b+1,b+n+1,cmp2); 72 k=1; 73 for(i=1;i<=m;i++){ 74 while(k<=n&&a[i].val>=b[k].num){ 75 update(b[k].id); 76 k++; 77 } 78 ans[a[i].id]=get_sum(a[i].r)-get_sum(a[i].l-1); 79 } 80 printf("Case %d:\n",kase++); 81 for(i=1;i<=m;i++) 82 printf("%d\n",ans[i]); 83 } 84 }
HDU 4417 类似求逆序数的树状数组,布布扣,bubuko.com
标签:des style blog java color os
原文地址:http://www.cnblogs.com/qq1012662902/p/3855729.html