#include <bits/extc++.h>
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
int N, Q, ans[100005], C;
vector<int> pos;
vector<tuple<int, int, int, int>> queries;
tree<pii, null_type, greater<pii>, rb_tree_tag, tree_order_statistics_node_update> st[400005];
void modify(int p, pii v, int i = 1, int L = 0, int R = C)
{
st[i].insert(v);
if (L + 1 < R)
{
int mid = (L + R) / 2;
if (p < pos[mid])
modify(p, v, i << 1, L, mid);
else
modify(p, v, i << 1 | 1, mid, R);
}
}
int query(int p, int c, int i = 1, int L = 0, int R = C)
{
if (p <= pos[L])
return st[i].order_of_key(pii(c, 0));
else
{
int mid = (L + R) / 2;
if (p < pos[mid])
return query(p, c, i << 1, L, mid) + query(p, c, i << 1 | 1, mid, R);
else
return query(p, c, i << 1 | 1, mid, R);
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> N >> Q;
for (int i = 1; i <= N; i++)
{
int S, T;
cin >> S >> T;
pos.emplace_back(T);
queries.emplace_back(make_tuple(S, Q + i, T, 0));
}
for (int i = 1; i <= Q; i++)
{
int X, Y, Z;
cin >> X >> Y >> Z;
pos.emplace_back(Y);
queries.emplace_back(make_tuple(X, i, Y, Z));
}
pos.emplace_back(1'000'000'000);
sort(pos.begin(), pos.end());
pos.resize(unique(pos.begin(), pos.end()) - pos.begin());
C = pos.size();
sort(queries.begin(), queries.end(), greater<>());
for (auto [a, i, b, c] : queries)
{
// cerr << i << ' ' << a << ' ' << b << ' ' << c << '\n';
if (i > Q)
modify(b, pii(a + b, i));
else
ans[i] = query(b, c);
}
for (int i = 1; i <= Q; i++)
cout << ans[i] << '\n';
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:66:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
66 | for (auto [a, i, b, c] : queries)
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
37844 KB |
Output is correct |
2 |
Correct |
31 ms |
37884 KB |
Output is correct |
3 |
Correct |
26 ms |
37896 KB |
Output is correct |
4 |
Correct |
26 ms |
37780 KB |
Output is correct |
5 |
Correct |
28 ms |
37876 KB |
Output is correct |
6 |
Correct |
32 ms |
37780 KB |
Output is correct |
7 |
Correct |
41 ms |
40688 KB |
Output is correct |
8 |
Correct |
42 ms |
40652 KB |
Output is correct |
9 |
Correct |
45 ms |
40652 KB |
Output is correct |
10 |
Correct |
33 ms |
38932 KB |
Output is correct |
11 |
Correct |
41 ms |
40624 KB |
Output is correct |
12 |
Correct |
35 ms |
38868 KB |
Output is correct |
13 |
Correct |
40 ms |
40736 KB |
Output is correct |
14 |
Correct |
41 ms |
40688 KB |
Output is correct |
15 |
Correct |
41 ms |
40652 KB |
Output is correct |
16 |
Correct |
40 ms |
40576 KB |
Output is correct |
17 |
Correct |
30 ms |
38484 KB |
Output is correct |
18 |
Correct |
33 ms |
38532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1774 ms |
154768 KB |
Output is correct |
2 |
Correct |
1741 ms |
154732 KB |
Output is correct |
3 |
Correct |
1751 ms |
154812 KB |
Output is correct |
4 |
Correct |
354 ms |
73648 KB |
Output is correct |
5 |
Correct |
1337 ms |
154052 KB |
Output is correct |
6 |
Correct |
361 ms |
72816 KB |
Output is correct |
7 |
Correct |
1900 ms |
154792 KB |
Output is correct |
8 |
Correct |
1618 ms |
151856 KB |
Output is correct |
9 |
Correct |
1639 ms |
151816 KB |
Output is correct |
10 |
Correct |
1303 ms |
154016 KB |
Output is correct |
11 |
Correct |
286 ms |
56752 KB |
Output is correct |
12 |
Correct |
277 ms |
62232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1774 ms |
154768 KB |
Output is correct |
2 |
Correct |
1741 ms |
154732 KB |
Output is correct |
3 |
Correct |
1751 ms |
154812 KB |
Output is correct |
4 |
Correct |
354 ms |
73648 KB |
Output is correct |
5 |
Correct |
1337 ms |
154052 KB |
Output is correct |
6 |
Correct |
361 ms |
72816 KB |
Output is correct |
7 |
Correct |
1900 ms |
154792 KB |
Output is correct |
8 |
Correct |
1618 ms |
151856 KB |
Output is correct |
9 |
Correct |
1639 ms |
151816 KB |
Output is correct |
10 |
Correct |
1303 ms |
154016 KB |
Output is correct |
11 |
Correct |
286 ms |
56752 KB |
Output is correct |
12 |
Correct |
277 ms |
62232 KB |
Output is correct |
13 |
Correct |
1795 ms |
155416 KB |
Output is correct |
14 |
Correct |
1747 ms |
155148 KB |
Output is correct |
15 |
Correct |
1730 ms |
154840 KB |
Output is correct |
16 |
Correct |
389 ms |
73904 KB |
Output is correct |
17 |
Correct |
1419 ms |
154408 KB |
Output is correct |
18 |
Correct |
355 ms |
72788 KB |
Output is correct |
19 |
Correct |
1792 ms |
155404 KB |
Output is correct |
20 |
Correct |
1808 ms |
155200 KB |
Output is correct |
21 |
Correct |
2165 ms |
154228 KB |
Output is correct |
22 |
Correct |
1329 ms |
153904 KB |
Output is correct |
23 |
Correct |
220 ms |
56736 KB |
Output is correct |
24 |
Correct |
267 ms |
62212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
37844 KB |
Output is correct |
2 |
Correct |
31 ms |
37884 KB |
Output is correct |
3 |
Correct |
26 ms |
37896 KB |
Output is correct |
4 |
Correct |
26 ms |
37780 KB |
Output is correct |
5 |
Correct |
28 ms |
37876 KB |
Output is correct |
6 |
Correct |
32 ms |
37780 KB |
Output is correct |
7 |
Correct |
41 ms |
40688 KB |
Output is correct |
8 |
Correct |
42 ms |
40652 KB |
Output is correct |
9 |
Correct |
45 ms |
40652 KB |
Output is correct |
10 |
Correct |
33 ms |
38932 KB |
Output is correct |
11 |
Correct |
41 ms |
40624 KB |
Output is correct |
12 |
Correct |
35 ms |
38868 KB |
Output is correct |
13 |
Correct |
40 ms |
40736 KB |
Output is correct |
14 |
Correct |
41 ms |
40688 KB |
Output is correct |
15 |
Correct |
41 ms |
40652 KB |
Output is correct |
16 |
Correct |
40 ms |
40576 KB |
Output is correct |
17 |
Correct |
30 ms |
38484 KB |
Output is correct |
18 |
Correct |
33 ms |
38532 KB |
Output is correct |
19 |
Correct |
1774 ms |
154768 KB |
Output is correct |
20 |
Correct |
1741 ms |
154732 KB |
Output is correct |
21 |
Correct |
1751 ms |
154812 KB |
Output is correct |
22 |
Correct |
354 ms |
73648 KB |
Output is correct |
23 |
Correct |
1337 ms |
154052 KB |
Output is correct |
24 |
Correct |
361 ms |
72816 KB |
Output is correct |
25 |
Correct |
1900 ms |
154792 KB |
Output is correct |
26 |
Correct |
1618 ms |
151856 KB |
Output is correct |
27 |
Correct |
1639 ms |
151816 KB |
Output is correct |
28 |
Correct |
1303 ms |
154016 KB |
Output is correct |
29 |
Correct |
286 ms |
56752 KB |
Output is correct |
30 |
Correct |
277 ms |
62232 KB |
Output is correct |
31 |
Correct |
1795 ms |
155416 KB |
Output is correct |
32 |
Correct |
1747 ms |
155148 KB |
Output is correct |
33 |
Correct |
1730 ms |
154840 KB |
Output is correct |
34 |
Correct |
389 ms |
73904 KB |
Output is correct |
35 |
Correct |
1419 ms |
154408 KB |
Output is correct |
36 |
Correct |
355 ms |
72788 KB |
Output is correct |
37 |
Correct |
1792 ms |
155404 KB |
Output is correct |
38 |
Correct |
1808 ms |
155200 KB |
Output is correct |
39 |
Correct |
2165 ms |
154228 KB |
Output is correct |
40 |
Correct |
1329 ms |
153904 KB |
Output is correct |
41 |
Correct |
220 ms |
56736 KB |
Output is correct |
42 |
Correct |
267 ms |
62212 KB |
Output is correct |
43 |
Runtime error |
137 ms |
91500 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |