只是简单的求逆序数,还是re一次,wa一次。
re注意的是两个岛各最多1000城市,所以路可以有1e6
wa注意的是交叉点的数量可以很多,会超int。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1e6+5;
int x, y, n, tree[maxn];
struct node
{
int x, y;
bool operator < (const node &a) const
{
if(x == a.x) return y < a.y;
return x < a.x;
}
}a[maxn];
int lowbit(int x) { return x&(-x); }
void update(int pos, int val)
{
while(pos < maxn)
{
tree[pos] += val;
pos += lowbit(pos);
}
}
int query(int pos)
{
int sum = 0;
while(pos)
{
sum += tree[pos];
pos -= lowbit(pos);
}
return sum;
}
int main(void)
{
int t, ca = 1;
cin >> t;
while(t--)
{
long long ans = 0;
memset(tree, 0, sizeof(tree));
scanf("%d%d%d", &x, &y, &n);
for(int i = 0; i < n; i++)
scanf("%d%d", &a[i].x, &a[i].y);
sort(a, a+n);
for(int i = 0; i < n; i++)
{
ans += i-query(a[i].y);
update(a[i].y, 1);
}
printf("Test case %d: %lld\n", ca++, ans);
}
return 0;
}
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 26393 | Accepted: 7167 |
Description
Input
Output
Test case (case number): (number of crossings)
Sample Input
1 3 4 4 1 4 2 3 3 2 3 1
Sample Output
Test case 1: 5
Source
1万+



被折叠的 条评论
为什么被折叠?



