Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

可以AC的代码

Posted by yc5_yc at 2012-08-29 22:01:41 on Problem 3067
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator