#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
namespace __gnu_pbds{
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
}
using namespace __gnu_pbds;
struct QUERY {
int x, y, z, num;
} b[100005];
struct GRADE {
int x, y;
} a[100005];
int res[100005];
bool cmp(QUERY aa, QUERY bb) {
return aa.x > bb.x;
}
bool cmp2(GRADE aa, GRADE bb) {
return aa.x > bb.x;
}
ordered_set t[800005];
map<int, int> mm;
void update(int v, int tl, int tr, int x, int y) {
if (tl == tr) {
t[v].insert(y);
return;
}
int mid = (tl + tr) / 2;
if (mid >= x) update(v * 2, tl, mid, x, y);
else update(v * 2 + 1, mid + 1, tr, x, y);
t[v].insert(y);
}
int sum(int v, int tl, int tr, int l, int r, int x) {
if (l > r) return 0;
if (tl == l && tr == r) {
return t[v].size() - t[v].order_of_key(x);
}
int mid = (tl + tr) / 2;
return sum(v * 2, tl, mid, l, min(r, mid), x) + sum(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r, x);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, q, z = 0;
cin >> n >> q;
vector<int> v;
for (int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].y;
v.push_back(a[i].y);
}
sort(a + 1, a + n + 1, cmp2);
for (int i = 0; i < q; i++) {
cin >> b[i].x >> b[i].y >> b[i].z;
v.push_back(b[i].y);
b[i].num = i;
}
sort(v.begin(), v.end());
for (int w : v) {
if (!mm.count(w)) {
mm[w] = ++z;
}
}
sort(b, b + q, cmp);
int j = 1;
for (int i = 0; i < q; i++) {
while (a[j].x >= b[i].x && j <= n) {
update(1, 1, z, mm[a[j].y], a[j].x + a[j].y);
j++;
}
res[b[i].num] = sum(1, 1, z, mm[b[i].y], z, b[i].z);
}
for (int i = 0; i < q; i++) cout << res[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
63036 KB |
Output is correct |
2 |
Correct |
37 ms |
63068 KB |
Output is correct |
3 |
Correct |
39 ms |
62980 KB |
Output is correct |
4 |
Correct |
39 ms |
62900 KB |
Output is correct |
5 |
Correct |
39 ms |
63056 KB |
Output is correct |
6 |
Correct |
38 ms |
63068 KB |
Output is correct |
7 |
Correct |
54 ms |
65360 KB |
Output is correct |
8 |
Correct |
53 ms |
65356 KB |
Output is correct |
9 |
Correct |
53 ms |
65368 KB |
Output is correct |
10 |
Correct |
48 ms |
63824 KB |
Output is correct |
11 |
Correct |
48 ms |
65364 KB |
Output is correct |
12 |
Correct |
40 ms |
63832 KB |
Output is correct |
13 |
Correct |
52 ms |
65252 KB |
Output is correct |
14 |
Correct |
51 ms |
65360 KB |
Output is correct |
15 |
Correct |
55 ms |
65360 KB |
Output is correct |
16 |
Correct |
56 ms |
65360 KB |
Output is correct |
17 |
Correct |
39 ms |
63320 KB |
Output is correct |
18 |
Correct |
40 ms |
63568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1156 ms |
153084 KB |
Output is correct |
2 |
Correct |
1167 ms |
153364 KB |
Output is correct |
3 |
Correct |
1089 ms |
153328 KB |
Output is correct |
4 |
Correct |
253 ms |
88524 KB |
Output is correct |
5 |
Correct |
868 ms |
153380 KB |
Output is correct |
6 |
Correct |
236 ms |
88276 KB |
Output is correct |
7 |
Correct |
1148 ms |
153304 KB |
Output is correct |
8 |
Correct |
1042 ms |
150220 KB |
Output is correct |
9 |
Correct |
1041 ms |
150180 KB |
Output is correct |
10 |
Correct |
868 ms |
153332 KB |
Output is correct |
11 |
Correct |
128 ms |
76240 KB |
Output is correct |
12 |
Correct |
208 ms |
80812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1156 ms |
153084 KB |
Output is correct |
2 |
Correct |
1167 ms |
153364 KB |
Output is correct |
3 |
Correct |
1089 ms |
153328 KB |
Output is correct |
4 |
Correct |
253 ms |
88524 KB |
Output is correct |
5 |
Correct |
868 ms |
153380 KB |
Output is correct |
6 |
Correct |
236 ms |
88276 KB |
Output is correct |
7 |
Correct |
1148 ms |
153304 KB |
Output is correct |
8 |
Correct |
1042 ms |
150220 KB |
Output is correct |
9 |
Correct |
1041 ms |
150180 KB |
Output is correct |
10 |
Correct |
868 ms |
153332 KB |
Output is correct |
11 |
Correct |
128 ms |
76240 KB |
Output is correct |
12 |
Correct |
208 ms |
80812 KB |
Output is correct |
13 |
Correct |
1270 ms |
153228 KB |
Output is correct |
14 |
Correct |
1269 ms |
153292 KB |
Output is correct |
15 |
Correct |
1350 ms |
153276 KB |
Output is correct |
16 |
Correct |
318 ms |
88268 KB |
Output is correct |
17 |
Correct |
1184 ms |
153244 KB |
Output is correct |
18 |
Correct |
263 ms |
88528 KB |
Output is correct |
19 |
Correct |
1604 ms |
153228 KB |
Output is correct |
20 |
Correct |
1626 ms |
153252 KB |
Output is correct |
21 |
Correct |
1641 ms |
152304 KB |
Output is correct |
22 |
Correct |
1047 ms |
153040 KB |
Output is correct |
23 |
Correct |
144 ms |
76188 KB |
Output is correct |
24 |
Correct |
200 ms |
80848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
63036 KB |
Output is correct |
2 |
Correct |
37 ms |
63068 KB |
Output is correct |
3 |
Correct |
39 ms |
62980 KB |
Output is correct |
4 |
Correct |
39 ms |
62900 KB |
Output is correct |
5 |
Correct |
39 ms |
63056 KB |
Output is correct |
6 |
Correct |
38 ms |
63068 KB |
Output is correct |
7 |
Correct |
54 ms |
65360 KB |
Output is correct |
8 |
Correct |
53 ms |
65356 KB |
Output is correct |
9 |
Correct |
53 ms |
65368 KB |
Output is correct |
10 |
Correct |
48 ms |
63824 KB |
Output is correct |
11 |
Correct |
48 ms |
65364 KB |
Output is correct |
12 |
Correct |
40 ms |
63832 KB |
Output is correct |
13 |
Correct |
52 ms |
65252 KB |
Output is correct |
14 |
Correct |
51 ms |
65360 KB |
Output is correct |
15 |
Correct |
55 ms |
65360 KB |
Output is correct |
16 |
Correct |
56 ms |
65360 KB |
Output is correct |
17 |
Correct |
39 ms |
63320 KB |
Output is correct |
18 |
Correct |
40 ms |
63568 KB |
Output is correct |
19 |
Correct |
1156 ms |
153084 KB |
Output is correct |
20 |
Correct |
1167 ms |
153364 KB |
Output is correct |
21 |
Correct |
1089 ms |
153328 KB |
Output is correct |
22 |
Correct |
253 ms |
88524 KB |
Output is correct |
23 |
Correct |
868 ms |
153380 KB |
Output is correct |
24 |
Correct |
236 ms |
88276 KB |
Output is correct |
25 |
Correct |
1148 ms |
153304 KB |
Output is correct |
26 |
Correct |
1042 ms |
150220 KB |
Output is correct |
27 |
Correct |
1041 ms |
150180 KB |
Output is correct |
28 |
Correct |
868 ms |
153332 KB |
Output is correct |
29 |
Correct |
128 ms |
76240 KB |
Output is correct |
30 |
Correct |
208 ms |
80812 KB |
Output is correct |
31 |
Correct |
1270 ms |
153228 KB |
Output is correct |
32 |
Correct |
1269 ms |
153292 KB |
Output is correct |
33 |
Correct |
1350 ms |
153276 KB |
Output is correct |
34 |
Correct |
318 ms |
88268 KB |
Output is correct |
35 |
Correct |
1184 ms |
153244 KB |
Output is correct |
36 |
Correct |
263 ms |
88528 KB |
Output is correct |
37 |
Correct |
1604 ms |
153228 KB |
Output is correct |
38 |
Correct |
1626 ms |
153252 KB |
Output is correct |
39 |
Correct |
1641 ms |
152304 KB |
Output is correct |
40 |
Correct |
1047 ms |
153040 KB |
Output is correct |
41 |
Correct |
144 ms |
76188 KB |
Output is correct |
42 |
Correct |
200 ms |
80848 KB |
Output is correct |
43 |
Correct |
1750 ms |
164304 KB |
Output is correct |
44 |
Correct |
1712 ms |
164300 KB |
Output is correct |
45 |
Correct |
1714 ms |
164296 KB |
Output is correct |
46 |
Correct |
295 ms |
88500 KB |
Output is correct |
47 |
Correct |
1342 ms |
164304 KB |
Output is correct |
48 |
Correct |
280 ms |
88268 KB |
Output is correct |
49 |
Correct |
2023 ms |
164304 KB |
Output is correct |
50 |
Correct |
1693 ms |
164248 KB |
Output is correct |
51 |
Correct |
1777 ms |
164304 KB |
Output is correct |
52 |
Correct |
1351 ms |
164028 KB |
Output is correct |
53 |
Correct |
195 ms |
76396 KB |
Output is correct |