结果用 long long。
# include <stdio.h>
# include <string.h>
# include <algorithm>
using namespace std;
# define B 1005
# define N 1000005
int n, m, k, a[B];
int r[N], x[N], y[N];
bool cmp(int i, int j)
{
return x[i]^x[j] ? x[i]>x[j] : y[i]>y[j];
}
/********************************************************/
int getsum(int x)
{
int ret = 0;
while (x > 0) ret += a[x], x -= x&(-x);
return ret;
}
void inc(int x)
{
while (x <= m) ++ a[x], x += x&(-x);
}
/********************************************************/
int main()
{
int ii, T, i, xx;
long long int ans;
scanf("%d", &T);
for (ii = 1; ii <= T; ++ii)
{
scanf("%d%d%d", &n, &m, &k);
memset(a+1, 0, sizeof(a[0])*m);
for (i = 0; i < k; ++i)
r[i] = i, scanf("%d%d", &x[i], &y[i]);
sort(r, r+k, cmp);
ans = 0;
for (i = 0; i < k; ++i)
ans += getsum(y[r[i]]-1), inc(y[r[i]]);
printf("Test case %d: %lld\n", ii, ans);
}
return 0;
}
posted on 2012-09-02 13:53
yajunw 阅读(193)
评论(0) 编辑 收藏 引用