#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int INF = 2e9 + 5;
int n, q;
pair<int, int> A[maxn];
pair<int, int> cp[maxn];
vector<int> FW[maxn], fake[maxn];
vector<int> qq[maxn];
pair<int, int> pos[maxn];
int ans[maxn];
void fadd(int x, int y) {
for(x; x <= n; x += x&(-x)){
fake[x].push_back(y);
}
}
void add(int x, int y){
for(x; x <= n; x += x&(-x)){
for(int idx = upper_bound(fake[x].begin(), fake[x].end(), y) - fake[x].begin() - 1; idx < fake[x].size(); idx += idx&(-idx)) {
FW[x][idx]++;
}
}
}
int query(int x, int y){
int re = 0;
for(x; x > 0; x -= x&(-x)) {
for(int idx = upper_bound(fake[x].begin(), fake[x].end(), y) - fake[x].begin() - 1; idx > 0; idx -= idx&(-idx)) {
re += FW[x][idx];
}
}
return re;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; i++)
{
cin >> A[i].first >> A[i].second;
A[i].first *= -1;
A[i].second *= -1;
}
sort(A + 1, A + n + 1);
for(int i = 1; i <= n; i++){
cp[i] = {A[i].second, i};
}
sort(cp + 1, cp + n + 1);
for (int i = 1; i <= q; i++)
{
int x, y, c;
cin >> x >> y >> c;
x *= -1;
y *= -1;
c *= -1;
qq[upper_bound(A + 1, A + n + 1, make_pair(x, n)) - A-1].push_back(i);
pos[i] = {upper_bound(cp+1, cp+n+1, make_pair(y, n)) - cp - 1, c};
}
for(int i = 1; i <= n; i++){
// cout << cp[i].first << endl;
A[cp[i].second] = {i, A[cp[i].second].first + A[cp[i].second].second};
}
for(int i = 1; i <= n; i++){
fadd(A[i].first, A[i].second);
}
for(int i = 1; i <= n; i++){
fake[i].push_back(-INF);
sort(fake[i].begin(), fake[i].end());
fake[i].erase(unique(fake[i].begin(), fake[i].end()), fake[i].end());
FW[i].assign(fake[i].size(), 0);
}
for(int i = 1; i <= n; i++){
add(A[i].first, A[i].second);
for(auto v: qq[i]){
ans[v] = query(pos[v].first, pos[v].second);
}
}
for(int i = 1; i <= q; i++)cout << ans[i] << "\n";
}
Compilation message
examination.cpp: In function 'void fadd(int, int)':
examination.cpp:20:9: warning: statement has no effect [-Wunused-value]
20 | for(x; x <= n; x += x&(-x)){
| ^
examination.cpp: In function 'void add(int, int)':
examination.cpp:26:9: warning: statement has no effect [-Wunused-value]
26 | for(x; x <= n; x += x&(-x)){
| ^
examination.cpp:27:97: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int idx = upper_bound(fake[x].begin(), fake[x].end(), y) - fake[x].begin() - 1; idx < fake[x].size(); idx += idx&(-idx)) {
| ~~~~^~~~~~~~~~~~~~~~
examination.cpp: In function 'int query(int, int)':
examination.cpp:35:9: warning: statement has no effect [-Wunused-value]
35 | for(x; x > 0; x -= x&(-x)) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Correct |
7 ms |
14420 KB |
Output is correct |
5 |
Correct |
6 ms |
14420 KB |
Output is correct |
6 |
Correct |
7 ms |
14420 KB |
Output is correct |
7 |
Correct |
12 ms |
14900 KB |
Output is correct |
8 |
Correct |
12 ms |
14804 KB |
Output is correct |
9 |
Correct |
12 ms |
14804 KB |
Output is correct |
10 |
Correct |
13 ms |
14804 KB |
Output is correct |
11 |
Correct |
10 ms |
14804 KB |
Output is correct |
12 |
Correct |
9 ms |
14804 KB |
Output is correct |
13 |
Correct |
11 ms |
14804 KB |
Output is correct |
14 |
Correct |
11 ms |
14804 KB |
Output is correct |
15 |
Correct |
12 ms |
14804 KB |
Output is correct |
16 |
Correct |
10 ms |
14804 KB |
Output is correct |
17 |
Correct |
10 ms |
14804 KB |
Output is correct |
18 |
Correct |
8 ms |
14804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
311 ms |
32588 KB |
Output is correct |
2 |
Correct |
301 ms |
32576 KB |
Output is correct |
3 |
Correct |
291 ms |
32596 KB |
Output is correct |
4 |
Correct |
214 ms |
32576 KB |
Output is correct |
5 |
Correct |
205 ms |
30780 KB |
Output is correct |
6 |
Correct |
95 ms |
29120 KB |
Output is correct |
7 |
Correct |
281 ms |
31732 KB |
Output is correct |
8 |
Correct |
275 ms |
32600 KB |
Output is correct |
9 |
Correct |
252 ms |
31844 KB |
Output is correct |
10 |
Correct |
172 ms |
30404 KB |
Output is correct |
11 |
Correct |
183 ms |
31664 KB |
Output is correct |
12 |
Correct |
70 ms |
28744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
311 ms |
32588 KB |
Output is correct |
2 |
Correct |
301 ms |
32576 KB |
Output is correct |
3 |
Correct |
291 ms |
32596 KB |
Output is correct |
4 |
Correct |
214 ms |
32576 KB |
Output is correct |
5 |
Correct |
205 ms |
30780 KB |
Output is correct |
6 |
Correct |
95 ms |
29120 KB |
Output is correct |
7 |
Correct |
281 ms |
31732 KB |
Output is correct |
8 |
Correct |
275 ms |
32600 KB |
Output is correct |
9 |
Correct |
252 ms |
31844 KB |
Output is correct |
10 |
Correct |
172 ms |
30404 KB |
Output is correct |
11 |
Correct |
183 ms |
31664 KB |
Output is correct |
12 |
Correct |
70 ms |
28744 KB |
Output is correct |
13 |
Correct |
328 ms |
32600 KB |
Output is correct |
14 |
Correct |
323 ms |
32588 KB |
Output is correct |
15 |
Correct |
297 ms |
32584 KB |
Output is correct |
16 |
Correct |
245 ms |
32472 KB |
Output is correct |
17 |
Correct |
227 ms |
30784 KB |
Output is correct |
18 |
Correct |
99 ms |
29132 KB |
Output is correct |
19 |
Correct |
326 ms |
32596 KB |
Output is correct |
20 |
Correct |
342 ms |
32624 KB |
Output is correct |
21 |
Correct |
310 ms |
32192 KB |
Output is correct |
22 |
Correct |
172 ms |
30480 KB |
Output is correct |
23 |
Correct |
178 ms |
31572 KB |
Output is correct |
24 |
Correct |
71 ms |
28744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Correct |
7 ms |
14420 KB |
Output is correct |
5 |
Correct |
6 ms |
14420 KB |
Output is correct |
6 |
Correct |
7 ms |
14420 KB |
Output is correct |
7 |
Correct |
12 ms |
14900 KB |
Output is correct |
8 |
Correct |
12 ms |
14804 KB |
Output is correct |
9 |
Correct |
12 ms |
14804 KB |
Output is correct |
10 |
Correct |
13 ms |
14804 KB |
Output is correct |
11 |
Correct |
10 ms |
14804 KB |
Output is correct |
12 |
Correct |
9 ms |
14804 KB |
Output is correct |
13 |
Correct |
11 ms |
14804 KB |
Output is correct |
14 |
Correct |
11 ms |
14804 KB |
Output is correct |
15 |
Correct |
12 ms |
14804 KB |
Output is correct |
16 |
Correct |
10 ms |
14804 KB |
Output is correct |
17 |
Correct |
10 ms |
14804 KB |
Output is correct |
18 |
Correct |
8 ms |
14804 KB |
Output is correct |
19 |
Correct |
311 ms |
32588 KB |
Output is correct |
20 |
Correct |
301 ms |
32576 KB |
Output is correct |
21 |
Correct |
291 ms |
32596 KB |
Output is correct |
22 |
Correct |
214 ms |
32576 KB |
Output is correct |
23 |
Correct |
205 ms |
30780 KB |
Output is correct |
24 |
Correct |
95 ms |
29120 KB |
Output is correct |
25 |
Correct |
281 ms |
31732 KB |
Output is correct |
26 |
Correct |
275 ms |
32600 KB |
Output is correct |
27 |
Correct |
252 ms |
31844 KB |
Output is correct |
28 |
Correct |
172 ms |
30404 KB |
Output is correct |
29 |
Correct |
183 ms |
31664 KB |
Output is correct |
30 |
Correct |
70 ms |
28744 KB |
Output is correct |
31 |
Correct |
328 ms |
32600 KB |
Output is correct |
32 |
Correct |
323 ms |
32588 KB |
Output is correct |
33 |
Correct |
297 ms |
32584 KB |
Output is correct |
34 |
Correct |
245 ms |
32472 KB |
Output is correct |
35 |
Correct |
227 ms |
30784 KB |
Output is correct |
36 |
Correct |
99 ms |
29132 KB |
Output is correct |
37 |
Correct |
326 ms |
32596 KB |
Output is correct |
38 |
Correct |
342 ms |
32624 KB |
Output is correct |
39 |
Correct |
310 ms |
32192 KB |
Output is correct |
40 |
Correct |
172 ms |
30480 KB |
Output is correct |
41 |
Correct |
178 ms |
31572 KB |
Output is correct |
42 |
Correct |
71 ms |
28744 KB |
Output is correct |
43 |
Correct |
339 ms |
32772 KB |
Output is correct |
44 |
Correct |
338 ms |
32836 KB |
Output is correct |
45 |
Correct |
326 ms |
32752 KB |
Output is correct |
46 |
Correct |
240 ms |
32792 KB |
Output is correct |
47 |
Correct |
245 ms |
31764 KB |
Output is correct |
48 |
Correct |
98 ms |
28860 KB |
Output is correct |
49 |
Correct |
351 ms |
31940 KB |
Output is correct |
50 |
Correct |
316 ms |
32808 KB |
Output is correct |
51 |
Correct |
300 ms |
31932 KB |
Output is correct |
52 |
Correct |
190 ms |
31464 KB |
Output is correct |
53 |
Correct |
182 ms |
32704 KB |
Output is correct |