| Time Limit: 1000MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
Description
Input
Output
Test case (case number): (number of crossings)
Sample Input
1 3 4 4 1 4 2 3 3 2 3 1
Sample Output
Test case 1: 5
#include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> #define maxn 1010 using namespace std; #define in __int64 int n,m,k; in a[maxn]; struct node { in e,w; }ww[maxn*maxn]; in cmp(node a,node b) { if(a.e==b.e) return a.w > b.w; return a.e>b.e; } int lowbit(int x) //求出二进制中末尾第一个不为0的数的位置k,x+=2^k. { return x&(-x); //return x&(x^(x-1)); } void insert(int p) //构建树状数组 { while(p<=n) { a[p]+=1; p+=lowbit(p); } } in sum(int end) //求1到end区间的和 { in s=0; while(end>0) { s+=a[end]; end-=lowbit(end); } return s; } int main() { int t; int V=0; int i; scanf("%d",&t); while(t--) { V++; in ans=0; memset(a,0,sizeof(a)); scanf("%d%d%d",&n,&m,&k); for(i=1;i<=k;i++) scanf("%I64d %I64d",&ww[i].e,&ww[i].w); sort(ww+1,ww+k+1,cmp); for(i=1;i<=k;i++) { insert(ww[i].w); ans+=sum(ww[i].w-1); } printf("Test case %d: %I64d\n",V,ans); } return 0; }
248



被折叠的 条评论
为什么被折叠?



