Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
可以AC的代码#include <cstdio> #include <string.h> #include <algorithm> using namespace std; const int KMax=1000100; struct line {int u,v;}A[KMax]; int N,M,K; long long F[KMax]; inline int lowbit(int a) {return a&(a^(a-1));} bool cmp(line a,line b) {return a.u<b.u||(a.u==b.u&&a.v<b.v);} void Let(int a,int x) {for(int p=a;p<=M;p+=lowbit(p))F[p]+=(long long)x;} long long sum(int a) {long long ret=0;for(int p=a;p;p-=lowbit(p))ret+=F[p];return ret;} int main() { int T; scanf("%d",&T); for(int I=1;I<=T;I++) { scanf("%d%d%d",&N,&M,&K); memset(F,0,sizeof(F)); for(int i=1;i<=K;i++) scanf("%d%d",&(A[i].u),&(A[i].v)); sort(A+1,A+K+1,cmp); long long cnt=0; for(int i=1;i<=K;i++) { cnt+=(long long)sum(M)-sum(A[i].v); Let(A[i].v,1); } printf("Test case %d: %I64d\n",I,cnt); } getchar();getchar();getchar();getchar(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator