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

【求助】 为什么会RE?

Posted by YoungNeal at 2018-02-15 14:01:27 on Problem 3067
#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;

int T,n,m,k,sum;
int f[1005],b[1005];

struct Node{
	int x,y;
}node[100005];

int query(int x){
	int tot=0;
	for(;x;x-=x&-x)
		tot+=f[x];
	return tot;
}

void add(int x){
	for(;x<=m;x+=x&-x)
		f[x]++;
}

bool cmp(const int &a,const int &b){
	if(node[a].x==node[b].x) return node[a].y<node[b].x;
	return node[a].y>node[b].y;
}

signed main(){
	scanf("%lld",&T);
	for(int p=1;p<=T;p++){
		printf("Test case %lld: ",p);
		memset(f,0,sizeof f);
		sum=0;
		scanf("%lld%lld%lld",&n,&m,&k);
		for(int i=1;i<=k;i++)
			scanf("%lld%lld",&node[i].x,&node[i].y),b[i]=i;
		sort(b+1,b+1+k,cmp);
		for(int i=1;i<=k;i++){
			sum+=query(b[i]);
			add(b[i]);
		}
		printf("%lld\n",sum);
	}
	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