#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using ll = long long;
using namespace std;
using namespace __gnu_pbds;
using indexed_set = tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>;
const int MAXN = 100'001;
indexed_set t[4*MAXN];
int val[MAXN], ans[MAXN], n, q;
void sequpd(int u, int k) {
u += n;
for (;u >= 1; u /= 2) {
t[u].insert(k);
}
}
int segqry(int l, int r, int k) {
int res = 0;
l += n; r += n;
while (l <= r) {
if (l % 2 == 1) {
res += t[l].size() - t[l].order_of_key(k);
l++;
}
if (r % 2 == 0) {
res += t[r].size() - t[r].order_of_key(k);
r--;
}
l /= 2; r /= 2;
}
return res;
}
void solve() {
cin >> n >> q;
vector<array<int, 3>> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i][0] >> v[i][1];
v[i][2] = -1;
}
sort(v.begin(), v.end(), [](auto a, auto b){
return a[1] < b[1];
});
for (int i = 0; i < n; i++) {
v[i][2] = i+1;
val[i+1] = v[i][1];
}
sort(v.begin(), v.end(), [](auto a, auto b){
return a[0] > b[0];
});
vector<array<int, 4>> qrys(q);
for (int i = 0; i < q; i++) {
cin >> qrys[i][0] >> qrys[i][1] >> qrys[i][2];
qrys[i][3] = i;
}
sort(qrys.begin(), qrys.end(), [](auto a, auto b){
return a[0] > b[0];
});
int idx = 0;
for (auto [x, y, z, i] : qrys) {
while (idx < n && v[idx][0] >= x) {
sequpd(v[idx][2], v[idx][0] + v[idx][1]);
idx++;
}
int pos = lower_bound(val+1, val+n+1, y) - val;
ans[i] = segqry(pos, n, z);
}
for (int i = 0; i < q; i++) {
cout << ans[i] << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
32348 KB |
Output is correct |
2 |
Correct |
18 ms |
32348 KB |
Output is correct |
3 |
Correct |
17 ms |
32348 KB |
Output is correct |
4 |
Correct |
19 ms |
32348 KB |
Output is correct |
5 |
Correct |
19 ms |
32348 KB |
Output is correct |
6 |
Correct |
18 ms |
32204 KB |
Output is correct |
7 |
Correct |
28 ms |
34324 KB |
Output is correct |
8 |
Correct |
27 ms |
34384 KB |
Output is correct |
9 |
Correct |
26 ms |
34396 KB |
Output is correct |
10 |
Correct |
25 ms |
34312 KB |
Output is correct |
11 |
Correct |
24 ms |
34140 KB |
Output is correct |
12 |
Correct |
27 ms |
34108 KB |
Output is correct |
13 |
Correct |
29 ms |
34344 KB |
Output is correct |
14 |
Correct |
26 ms |
34128 KB |
Output is correct |
15 |
Correct |
28 ms |
34268 KB |
Output is correct |
16 |
Correct |
27 ms |
34128 KB |
Output is correct |
17 |
Correct |
26 ms |
34308 KB |
Output is correct |
18 |
Correct |
25 ms |
34140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
985 ms |
121424 KB |
Output is correct |
2 |
Correct |
968 ms |
121228 KB |
Output is correct |
3 |
Correct |
994 ms |
121424 KB |
Output is correct |
4 |
Correct |
1010 ms |
120664 KB |
Output is correct |
5 |
Correct |
699 ms |
120652 KB |
Output is correct |
6 |
Correct |
747 ms |
119888 KB |
Output is correct |
7 |
Correct |
1148 ms |
121276 KB |
Output is correct |
8 |
Correct |
1184 ms |
121128 KB |
Output is correct |
9 |
Correct |
1028 ms |
121172 KB |
Output is correct |
10 |
Correct |
543 ms |
120432 KB |
Output is correct |
11 |
Correct |
972 ms |
120408 KB |
Output is correct |
12 |
Correct |
493 ms |
119364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
985 ms |
121424 KB |
Output is correct |
2 |
Correct |
968 ms |
121228 KB |
Output is correct |
3 |
Correct |
994 ms |
121424 KB |
Output is correct |
4 |
Correct |
1010 ms |
120664 KB |
Output is correct |
5 |
Correct |
699 ms |
120652 KB |
Output is correct |
6 |
Correct |
747 ms |
119888 KB |
Output is correct |
7 |
Correct |
1148 ms |
121276 KB |
Output is correct |
8 |
Correct |
1184 ms |
121128 KB |
Output is correct |
9 |
Correct |
1028 ms |
121172 KB |
Output is correct |
10 |
Correct |
543 ms |
120432 KB |
Output is correct |
11 |
Correct |
972 ms |
120408 KB |
Output is correct |
12 |
Correct |
493 ms |
119364 KB |
Output is correct |
13 |
Correct |
1303 ms |
121620 KB |
Output is correct |
14 |
Correct |
1281 ms |
121760 KB |
Output is correct |
15 |
Correct |
1202 ms |
121320 KB |
Output is correct |
16 |
Correct |
1115 ms |
120916 KB |
Output is correct |
17 |
Correct |
748 ms |
120972 KB |
Output is correct |
18 |
Correct |
719 ms |
120036 KB |
Output is correct |
19 |
Correct |
1310 ms |
121680 KB |
Output is correct |
20 |
Correct |
1209 ms |
121812 KB |
Output is correct |
21 |
Correct |
1372 ms |
121728 KB |
Output is correct |
22 |
Correct |
540 ms |
120404 KB |
Output is correct |
23 |
Correct |
977 ms |
120296 KB |
Output is correct |
24 |
Correct |
441 ms |
119380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
32348 KB |
Output is correct |
2 |
Correct |
18 ms |
32348 KB |
Output is correct |
3 |
Correct |
17 ms |
32348 KB |
Output is correct |
4 |
Correct |
19 ms |
32348 KB |
Output is correct |
5 |
Correct |
19 ms |
32348 KB |
Output is correct |
6 |
Correct |
18 ms |
32204 KB |
Output is correct |
7 |
Correct |
28 ms |
34324 KB |
Output is correct |
8 |
Correct |
27 ms |
34384 KB |
Output is correct |
9 |
Correct |
26 ms |
34396 KB |
Output is correct |
10 |
Correct |
25 ms |
34312 KB |
Output is correct |
11 |
Correct |
24 ms |
34140 KB |
Output is correct |
12 |
Correct |
27 ms |
34108 KB |
Output is correct |
13 |
Correct |
29 ms |
34344 KB |
Output is correct |
14 |
Correct |
26 ms |
34128 KB |
Output is correct |
15 |
Correct |
28 ms |
34268 KB |
Output is correct |
16 |
Correct |
27 ms |
34128 KB |
Output is correct |
17 |
Correct |
26 ms |
34308 KB |
Output is correct |
18 |
Correct |
25 ms |
34140 KB |
Output is correct |
19 |
Correct |
985 ms |
121424 KB |
Output is correct |
20 |
Correct |
968 ms |
121228 KB |
Output is correct |
21 |
Correct |
994 ms |
121424 KB |
Output is correct |
22 |
Correct |
1010 ms |
120664 KB |
Output is correct |
23 |
Correct |
699 ms |
120652 KB |
Output is correct |
24 |
Correct |
747 ms |
119888 KB |
Output is correct |
25 |
Correct |
1148 ms |
121276 KB |
Output is correct |
26 |
Correct |
1184 ms |
121128 KB |
Output is correct |
27 |
Correct |
1028 ms |
121172 KB |
Output is correct |
28 |
Correct |
543 ms |
120432 KB |
Output is correct |
29 |
Correct |
972 ms |
120408 KB |
Output is correct |
30 |
Correct |
493 ms |
119364 KB |
Output is correct |
31 |
Correct |
1303 ms |
121620 KB |
Output is correct |
32 |
Correct |
1281 ms |
121760 KB |
Output is correct |
33 |
Correct |
1202 ms |
121320 KB |
Output is correct |
34 |
Correct |
1115 ms |
120916 KB |
Output is correct |
35 |
Correct |
748 ms |
120972 KB |
Output is correct |
36 |
Correct |
719 ms |
120036 KB |
Output is correct |
37 |
Correct |
1310 ms |
121680 KB |
Output is correct |
38 |
Correct |
1209 ms |
121812 KB |
Output is correct |
39 |
Correct |
1372 ms |
121728 KB |
Output is correct |
40 |
Correct |
540 ms |
120404 KB |
Output is correct |
41 |
Correct |
977 ms |
120296 KB |
Output is correct |
42 |
Correct |
441 ms |
119380 KB |
Output is correct |
43 |
Correct |
1251 ms |
123728 KB |
Output is correct |
44 |
Correct |
1091 ms |
123784 KB |
Output is correct |
45 |
Correct |
1123 ms |
123916 KB |
Output is correct |
46 |
Correct |
1059 ms |
122196 KB |
Output is correct |
47 |
Correct |
672 ms |
122192 KB |
Output is correct |
48 |
Correct |
759 ms |
119732 KB |
Output is correct |
49 |
Correct |
1174 ms |
123472 KB |
Output is correct |
50 |
Correct |
1092 ms |
123476 KB |
Output is correct |
51 |
Correct |
1112 ms |
123492 KB |
Output is correct |
52 |
Correct |
479 ms |
121936 KB |
Output is correct |
53 |
Correct |
831 ms |
121228 KB |
Output is correct |