比赛 |
4043级2023省选练习赛3 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
考试 |
最终得分 |
100 |
用户昵称 |
HeSn |
运行时间 |
6.344 s |
代码语言 |
C++ |
内存使用 |
14.89 MiB |
提交时间 |
2023-03-08 20:50:42 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n, m, q, b[MAXN], c[MAXN], ans[MAXN], id[MAXN];
struct node {
int x, y, s, id;
} a[MAXN], a1[MAXN];
bool cmp(node x, node y) {
return x.s == y.s ? x.id < y.id : x.s > y.s;
}
int lowbit(int x) {
return x & -x;
}
void add(int x, int k) {
for (int i = x; i <= m; i += lowbit(i))
c[i] += k;
}
int query(int x) {
int sum = 0;
for (int i = x; i; i -= lowbit(i)) {
sum += c[i];
}
return sum;
}
void cdq(int l, int r) {
if (l == r) {
return;
}
int mid = (l + r) / 2, tp = 0;
cdq(l, mid);
cdq(mid + 1, r);
for(int k = l, i = l, j = mid + 1; k <= r; k ++) {
if(j > r || (i <= mid && a[i].x >= a[j].x)) {
if(!a[i].id) {
add(m - a[i].y + 1, 1), id[++ tp] = m - a[i].y + 1;
}
a1[k] = a[i ++];
}
else {
if (a[j].id) {
ans[a[j].id] += query(m - a[j].y + 1);
}
a1[k] = a[j ++];
}
}
for (int i = l; i <= r; i ++) {
a[i] = a1[i];
}
while(tp) {
add(id[tp --], -1);
}
}
int main() {
freopen("Examination.in", "r", stdin);
freopen("Examination.out", "w", stdout);
cin >> n >> q;
for(int i = 1; i <= n; i ++) {
cin >> a[i].x >> a[i].y;
a[i].s = a[i].x + a[i].y;
b[i] = a[i].y;
}
for(int i = n + 1; i <= n + q; i ++) {
cin >> a[i].x >> a[i].y >> a[i].s;
a[i].id = i - n;
b[i] = a[i].y;
}
sort(a + 1, a + n + q + 1, cmp);
sort(b + 1, b + n + q + 1);
m = unique(b + 1, b + n + q + 1) - b - 1;
for (int i = 1; i <= n + q; i ++) {
a[i].y = lower_bound(b + 1, b + m + 1, a[i].y) - b;
}
cdq(1, n + q);
for (int i = 1; i <= q; i ++) {
cout << ans[i] << endl;
}
return 0;
}