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

红队农民和蓝队农民可以站在同一个位置吗?

Posted by temp_ptr at 2011-12-29 23:41:32 on Problem 1794
我写了个2个树状数组的代码,不知道为啥WA了
#include <iostream>
#include <fstream>
using namespace std;
typedef long long lld;//cao!
const int N = 60002;
int c1[N], c2[N], nlimit, Y[N];
inline int lowbit(int i)
{
	return i & (i ^ (i - 1));
}
void update(int* c, int i, int value)
{
	for(; i < N; i += lowbit(i))		c[i] += value;
}
lld sum(int* c, int i)
{
	lld ret(0);
	for(; i > 0; i -= lowbit(i))		ret += c[i];
	return ret;
}
int main()
{
	int t, n, m, a, b, i;
	fstream fin("1794.txt");
	//fin>>t;
	scanf("%d", &t);
	for(int fuck = 1; fuck <= t; fuck++)
	{
		memset(c1, 0, sizeof(c1));
		memset(c2, 0, sizeof(c2));
		memset(Y, 0, sizeof(Y));
		lld ans = 0;
		//fin>>n>>m;
		scanf("%d %d", &n, &m);
		nlimit = n + m + 1;
		for(i = 0; i < n; i++)
		{
			//fin>>a>>b;
			scanf("%d %d", &a, &b);
			Y[b]++;
			update(c1, a, 1);
			update(c2, b, 1);
		}
		for(i = 0; i < m; i++)
		{
			//fin>>a>>b;
			scanf("%d %d", &a, &b);
			ans += (Y[b] + abs(sum(c1, a) - sum(c2, b)));
		}
		printf("Scenario #%d:\n%lld\n\n", fuck, ans);
	}
	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