比赛 |
树状数组练习 |
评测结果 |
AAAAAAAAAA |
题目名称 |
公路交叉 |
最终得分 |
100 |
用户昵称 |
LikableP |
运行时间 |
1.072 s |
代码语言 |
C++ |
内存使用 |
3.13 MiB |
提交时间 |
2025-06-11 21:33:01 |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long ll;
#define isdigit(ch) ((ch) >= '0' && (ch) <= '9')
#define lowbit(x) (x & -x)
template <typename T> T read() {
T res = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ 48);
return res * f;
}
const int MAXN = 1010;
struct SEQ {
int x, y;
} seq[MAXN * MAXN];
int n, m, k;
ll ans;
int tree[MAXN];
void add(int x, int y) {
for (; x <= m; x += lowbit(x)) tree[x] += y;
}
int ask(int x) {
int res = 0;
for (; x; x -= lowbit(x)) res += tree[x];
return res;
}
int T;
int main() {
freopen("road.in", "r", stdin);
freopen("road.out", "w", stdout);
T = read<int>();
for (int _ = 1; _ <= T; ++_) {
memset(tree, 0, sizeof tree);
ans = 0;
n = read<int>(), m = read<int>(), k = read<int>();
for (int i = 1; i <= k; ++i) {
seq[i].x = read<int>(), seq[i].y = read<int>();
}
::std::sort(seq + 1, seq + k + 1, [](SEQ x, SEQ y) {
if (x.x != y.x) return x.x < y.x;
return x.y < y.y;
});
for (int i = k; i >= 1; --i) {
ans += ask(seq[i].y - 1);
add(seq[i].y, 1);
}
printf("Test case %d: %lld\n", _, ans);
}
return 0;
}