#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
struct Data
{
int x, y, p, s;
};
int N, Q;
vector<Data> V;
vector<int> comp;
int ans[MAXN+10];
int getcomp(int x) { return lower_bound(comp.begin(), comp.end(), x)-comp.begin()+1; }
int tree[MAXN+10];
void update(int i, int k) { for(i=N-i+1; i<=N; i+=(i&-i)) tree[i]+=k; }
int query(int i) { int ret=0; for(i=N-i+1; i>0; i-=(i&-i)) ret+=tree[i]; return ret; }
void flush(int i) { for(i=N-i+1; i<=N; i+=(i&-i)) tree[i]=0; }
void solve(int l, int r)
{
if(l==r) return;
int mid=l+r>>1;
solve(l, mid);
solve(mid+1, r);
vector<Data> L, R;
for(int i=l; i<=mid; i++) if(V[i].p==0) L.push_back(V[i]);
for(int i=mid+1; i<=r; i++) if(V[i].p) R.push_back(V[i]);
sort(L.begin(), L.end(), [&](const Data &p, const Data &q) { return p.x>q.x; });
sort(R.begin(), R.end(), [&](const Data &p, const Data &q) { return p.x>q.x; });
for(int i=0, j=0; i<R.size(); i++)
{
for(; j<L.size() && L[j].x>=R[i].x; j++)
{
update(getcomp(L[j].y), 1);
}
ans[R[i].p]+=query(getcomp(R[i].y));
}
for(int j=0; j<L.size(); j++) flush(getcomp(L[j].y));
}
int main()
{
scanf("%d%d", &N, &Q);
for(int i=1; i<=N; i++)
{
int x, y;
scanf("%d%d", &x, &y);
V.push_back({x, y, 0, x+y});
comp.push_back(y);
}
for(int i=1; i<=Q; i++)
{
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
V.push_back({x, y, i, z});
}
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
sort(V.begin(), V.end(), [&](const Data &p, const Data &q)
{
if(p.s!=q.s) return p.s>q.s;
return p.p<q.p;
});
solve(0, V.size()-1);
for(int i=1; i<=Q; i++) printf("%d\n", ans[i]);
}
Compilation message
examination.cpp: In function 'void solve(int, int)':
examination.cpp:30:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
30 | int mid=l+r>>1;
| ~^~
examination.cpp:40:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Data>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i=0, j=0; i<R.size(); i++)
| ~^~~~~~~~~
examination.cpp:42:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Data>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(; j<L.size() && L[j].x>=R[i].x; j++)
| ~^~~~~~~~~
examination.cpp:48:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Data>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int j=0; j<L.size(); j++) flush(getcomp(L[j].y));
| ~^~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
53 | scanf("%d%d", &N, &Q);
| ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
57 | scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
64 | scanf("%d%d%d", &x, &y, &z);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
12 ms |
768 KB |
Output is correct |
8 |
Correct |
12 ms |
768 KB |
Output is correct |
9 |
Correct |
12 ms |
768 KB |
Output is correct |
10 |
Correct |
8 ms |
640 KB |
Output is correct |
11 |
Correct |
11 ms |
640 KB |
Output is correct |
12 |
Correct |
6 ms |
640 KB |
Output is correct |
13 |
Correct |
11 ms |
768 KB |
Output is correct |
14 |
Correct |
11 ms |
768 KB |
Output is correct |
15 |
Correct |
11 ms |
768 KB |
Output is correct |
16 |
Correct |
8 ms |
732 KB |
Output is correct |
17 |
Correct |
7 ms |
640 KB |
Output is correct |
18 |
Correct |
4 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
498 ms |
9736 KB |
Output is correct |
2 |
Correct |
500 ms |
9692 KB |
Output is correct |
3 |
Correct |
497 ms |
9820 KB |
Output is correct |
4 |
Correct |
259 ms |
9436 KB |
Output is correct |
5 |
Correct |
404 ms |
9692 KB |
Output is correct |
6 |
Correct |
216 ms |
9436 KB |
Output is correct |
7 |
Correct |
487 ms |
9692 KB |
Output is correct |
8 |
Correct |
476 ms |
9928 KB |
Output is correct |
9 |
Correct |
473 ms |
9820 KB |
Output is correct |
10 |
Correct |
352 ms |
9692 KB |
Output is correct |
11 |
Correct |
207 ms |
9436 KB |
Output is correct |
12 |
Correct |
161 ms |
9436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
498 ms |
9736 KB |
Output is correct |
2 |
Correct |
500 ms |
9692 KB |
Output is correct |
3 |
Correct |
497 ms |
9820 KB |
Output is correct |
4 |
Correct |
259 ms |
9436 KB |
Output is correct |
5 |
Correct |
404 ms |
9692 KB |
Output is correct |
6 |
Correct |
216 ms |
9436 KB |
Output is correct |
7 |
Correct |
487 ms |
9692 KB |
Output is correct |
8 |
Correct |
476 ms |
9928 KB |
Output is correct |
9 |
Correct |
473 ms |
9820 KB |
Output is correct |
10 |
Correct |
352 ms |
9692 KB |
Output is correct |
11 |
Correct |
207 ms |
9436 KB |
Output is correct |
12 |
Correct |
161 ms |
9436 KB |
Output is correct |
13 |
Correct |
581 ms |
7752 KB |
Output is correct |
14 |
Correct |
586 ms |
11764 KB |
Output is correct |
15 |
Correct |
506 ms |
12252 KB |
Output is correct |
16 |
Correct |
306 ms |
9564 KB |
Output is correct |
17 |
Correct |
492 ms |
9824 KB |
Output is correct |
18 |
Correct |
229 ms |
9564 KB |
Output is correct |
19 |
Correct |
586 ms |
10744 KB |
Output is correct |
20 |
Correct |
619 ms |
11004 KB |
Output is correct |
21 |
Correct |
598 ms |
10588 KB |
Output is correct |
22 |
Correct |
352 ms |
11356 KB |
Output is correct |
23 |
Correct |
207 ms |
11104 KB |
Output is correct |
24 |
Correct |
161 ms |
10460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
12 ms |
768 KB |
Output is correct |
8 |
Correct |
12 ms |
768 KB |
Output is correct |
9 |
Correct |
12 ms |
768 KB |
Output is correct |
10 |
Correct |
8 ms |
640 KB |
Output is correct |
11 |
Correct |
11 ms |
640 KB |
Output is correct |
12 |
Correct |
6 ms |
640 KB |
Output is correct |
13 |
Correct |
11 ms |
768 KB |
Output is correct |
14 |
Correct |
11 ms |
768 KB |
Output is correct |
15 |
Correct |
11 ms |
768 KB |
Output is correct |
16 |
Correct |
8 ms |
732 KB |
Output is correct |
17 |
Correct |
7 ms |
640 KB |
Output is correct |
18 |
Correct |
4 ms |
640 KB |
Output is correct |
19 |
Correct |
498 ms |
9736 KB |
Output is correct |
20 |
Correct |
500 ms |
9692 KB |
Output is correct |
21 |
Correct |
497 ms |
9820 KB |
Output is correct |
22 |
Correct |
259 ms |
9436 KB |
Output is correct |
23 |
Correct |
404 ms |
9692 KB |
Output is correct |
24 |
Correct |
216 ms |
9436 KB |
Output is correct |
25 |
Correct |
487 ms |
9692 KB |
Output is correct |
26 |
Correct |
476 ms |
9928 KB |
Output is correct |
27 |
Correct |
473 ms |
9820 KB |
Output is correct |
28 |
Correct |
352 ms |
9692 KB |
Output is correct |
29 |
Correct |
207 ms |
9436 KB |
Output is correct |
30 |
Correct |
161 ms |
9436 KB |
Output is correct |
31 |
Correct |
581 ms |
7752 KB |
Output is correct |
32 |
Correct |
586 ms |
11764 KB |
Output is correct |
33 |
Correct |
506 ms |
12252 KB |
Output is correct |
34 |
Correct |
306 ms |
9564 KB |
Output is correct |
35 |
Correct |
492 ms |
9824 KB |
Output is correct |
36 |
Correct |
229 ms |
9564 KB |
Output is correct |
37 |
Correct |
586 ms |
10744 KB |
Output is correct |
38 |
Correct |
619 ms |
11004 KB |
Output is correct |
39 |
Correct |
598 ms |
10588 KB |
Output is correct |
40 |
Correct |
352 ms |
11356 KB |
Output is correct |
41 |
Correct |
207 ms |
11104 KB |
Output is correct |
42 |
Correct |
161 ms |
10460 KB |
Output is correct |
43 |
Correct |
641 ms |
12716 KB |
Output is correct |
44 |
Correct |
632 ms |
12680 KB |
Output is correct |
45 |
Correct |
628 ms |
13788 KB |
Output is correct |
46 |
Correct |
312 ms |
10716 KB |
Output is correct |
47 |
Correct |
523 ms |
11228 KB |
Output is correct |
48 |
Correct |
216 ms |
7388 KB |
Output is correct |
49 |
Correct |
616 ms |
13760 KB |
Output is correct |
50 |
Correct |
611 ms |
12764 KB |
Output is correct |
51 |
Correct |
594 ms |
13660 KB |
Output is correct |
52 |
Correct |
462 ms |
10912 KB |
Output is correct |
53 |
Correct |
215 ms |
11996 KB |
Output is correct |