| ||||||||||
| 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 | |||||||||
红队农民和蓝队农民可以站在同一个位置吗?我写了个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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator