#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, Z, id; };
int N, Q, ans[MAXN+10];
pii A[MAXN+10];
Data B[MAXN+10];
struct Query { int x, y, num; };
vector<Query> todo;
vector<int> xcomp, ycomp;
int getxcomp(int x) { return lower_bound(xcomp.begin(), xcomp.end(), x)-xcomp.begin()+1; }
int getycomp(int y) { return lower_bound(ycomp.begin(), ycomp.end(), y)-ycomp.begin()+1; }
struct BIT
{
int tree[MAXN+10];
BIT() { memset(tree, 0, sizeof(tree)); }
void update(int i) { for(; i<=ycomp.size(); i+=(i&-i)) tree[i]++; }
int query(int i) { int ret=0; for(; i>0; i-=(i&-i)) ret+=tree[i]; return ret; }
void fflush(int i) { for(; i<=ycomp.size(); i+=(i&-i)) tree[i]=0; }
} bit;
void solve(int s, int e)
{
int i, j;
if(s+1==e) return;
int mid=s+e>>1;
solve(s, mid);
vector<Query> a, b;
for(i=s; i<mid; i++) if(todo[i].num==0) b.push_back(todo[i]);
for(i=mid; i<e; i++) if(todo[i].num!=0) a.push_back(todo[i]);
sort(a.begin(), a.end(), [&](const Query &p, const Query &q) { return p.x>q.x; });
sort(b.begin(), b.end(), [&](const Query &p, const Query &q) { return p.x>q.x; });
for(i=0, j=0; i<a.size(); i++)
{
for(; j<b.size() && b[j].x>=a[i].x; j++) bit.update(b[j].y);
ans[a[i].num]+=bit.query(ycomp.size())-bit.query(a[i].y-1);
}
for(j=0; j<b.size(); j++) bit.fflush(b[j].y);
solve(mid, e);
}
int main()
{
int i, j;
scanf("%d%d", &N, &Q);
for(i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second), xcomp.push_back(A[i].first), ycomp.push_back(A[i].second);
for(i=1; i<=Q; i++) scanf("%d%d%d", &B[i].X, &B[i].Y, &B[i].Z), B[i].id=i;
sort(xcomp.begin(), xcomp.end()); xcomp.erase(unique(xcomp.begin(), xcomp.end()), xcomp.end());
sort(ycomp.begin(), ycomp.end()); ycomp.erase(unique(ycomp.begin(), ycomp.end()), ycomp.end());
sort(A+1, A+N+1, [&](const pii &p, const pii &q) { return p.first+p.second>q.first+q.second; });
sort(B+1, B+Q+1, [&](const Data &p, const Data &q) { return p.Z>q.Z; });
int it=1;
for(i=1; i<=Q; i++)
{
for(; it<=N && A[it].first+A[it].second>=B[i].Z; it++) todo.push_back({getxcomp(A[it].first), getycomp(A[it].second), 0});
todo.push_back({getxcomp(B[i].X), getycomp(B[i].Y), B[i].id});
}
solve(0, todo.size());
for(i=1; i<=Q; i++) printf("%d\n", ans[i]);
}
Compilation message
examination.cpp: In member function 'void BIT::update(int)':
examination.cpp:27:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
void update(int i) { for(; i<=ycomp.size(); i+=(i&-i)) tree[i]++; }
~^~~~~~~~~~~~~~
examination.cpp: In member function 'void BIT::fflush(int)':
examination.cpp:29:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
void fflush(int i) { for(; i<=ycomp.size(); i+=(i&-i)) tree[i]=0; }
~^~~~~~~~~~~~~~
examination.cpp: In function 'void solve(int, int)':
examination.cpp:37:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=s+e>>1;
~^~
examination.cpp:47:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0, j=0; i<a.size(); i++)
~^~~~~~~~~
examination.cpp:49:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; j<b.size() && b[j].x>=a[i].x; j++) bit.update(b[j].y);
~^~~~~~~~~
examination.cpp:52:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0; j<b.size(); j++) bit.fflush(b[j].y);
~^~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:58:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
examination.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &Q);
~~~~~^~~~~~~~~~~~~~~~
examination.cpp:61:94: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second), xcomp.push_back(A[i].first), ycomp.push_back(A[i].second);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:62:67: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=Q; i++) scanf("%d%d%d", &B[i].X, &B[i].Y, &B[i].Z), B[i].id=i;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
760 KB |
Output is correct |
7 |
Correct |
12 ms |
1144 KB |
Output is correct |
8 |
Correct |
11 ms |
1144 KB |
Output is correct |
9 |
Correct |
12 ms |
1248 KB |
Output is correct |
10 |
Correct |
10 ms |
1148 KB |
Output is correct |
11 |
Correct |
10 ms |
1144 KB |
Output is correct |
12 |
Correct |
7 ms |
1016 KB |
Output is correct |
13 |
Correct |
11 ms |
1272 KB |
Output is correct |
14 |
Correct |
11 ms |
1272 KB |
Output is correct |
15 |
Correct |
10 ms |
1144 KB |
Output is correct |
16 |
Correct |
8 ms |
1144 KB |
Output is correct |
17 |
Correct |
9 ms |
1144 KB |
Output is correct |
18 |
Correct |
6 ms |
1016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
346 ms |
13008 KB |
Output is correct |
2 |
Correct |
343 ms |
12928 KB |
Output is correct |
3 |
Correct |
342 ms |
13152 KB |
Output is correct |
4 |
Correct |
245 ms |
12256 KB |
Output is correct |
5 |
Correct |
272 ms |
12248 KB |
Output is correct |
6 |
Correct |
186 ms |
11480 KB |
Output is correct |
7 |
Correct |
338 ms |
13016 KB |
Output is correct |
8 |
Correct |
331 ms |
13024 KB |
Output is correct |
9 |
Correct |
334 ms |
12812 KB |
Output is correct |
10 |
Correct |
224 ms |
12256 KB |
Output is correct |
11 |
Correct |
216 ms |
12264 KB |
Output is correct |
12 |
Correct |
141 ms |
11588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
346 ms |
13008 KB |
Output is correct |
2 |
Correct |
343 ms |
12928 KB |
Output is correct |
3 |
Correct |
342 ms |
13152 KB |
Output is correct |
4 |
Correct |
245 ms |
12256 KB |
Output is correct |
5 |
Correct |
272 ms |
12248 KB |
Output is correct |
6 |
Correct |
186 ms |
11480 KB |
Output is correct |
7 |
Correct |
338 ms |
13016 KB |
Output is correct |
8 |
Correct |
331 ms |
13024 KB |
Output is correct |
9 |
Correct |
334 ms |
12812 KB |
Output is correct |
10 |
Correct |
224 ms |
12256 KB |
Output is correct |
11 |
Correct |
216 ms |
12264 KB |
Output is correct |
12 |
Correct |
141 ms |
11588 KB |
Output is correct |
13 |
Correct |
392 ms |
12492 KB |
Output is correct |
14 |
Correct |
388 ms |
13232 KB |
Output is correct |
15 |
Correct |
354 ms |
13016 KB |
Output is correct |
16 |
Correct |
292 ms |
11476 KB |
Output is correct |
17 |
Correct |
314 ms |
11472 KB |
Output is correct |
18 |
Correct |
202 ms |
11456 KB |
Output is correct |
19 |
Correct |
387 ms |
12524 KB |
Output is correct |
20 |
Correct |
401 ms |
12752 KB |
Output is correct |
21 |
Correct |
389 ms |
12664 KB |
Output is correct |
22 |
Correct |
233 ms |
12196 KB |
Output is correct |
23 |
Correct |
226 ms |
12248 KB |
Output is correct |
24 |
Correct |
140 ms |
11480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
760 KB |
Output is correct |
7 |
Correct |
12 ms |
1144 KB |
Output is correct |
8 |
Correct |
11 ms |
1144 KB |
Output is correct |
9 |
Correct |
12 ms |
1248 KB |
Output is correct |
10 |
Correct |
10 ms |
1148 KB |
Output is correct |
11 |
Correct |
10 ms |
1144 KB |
Output is correct |
12 |
Correct |
7 ms |
1016 KB |
Output is correct |
13 |
Correct |
11 ms |
1272 KB |
Output is correct |
14 |
Correct |
11 ms |
1272 KB |
Output is correct |
15 |
Correct |
10 ms |
1144 KB |
Output is correct |
16 |
Correct |
8 ms |
1144 KB |
Output is correct |
17 |
Correct |
9 ms |
1144 KB |
Output is correct |
18 |
Correct |
6 ms |
1016 KB |
Output is correct |
19 |
Correct |
346 ms |
13008 KB |
Output is correct |
20 |
Correct |
343 ms |
12928 KB |
Output is correct |
21 |
Correct |
342 ms |
13152 KB |
Output is correct |
22 |
Correct |
245 ms |
12256 KB |
Output is correct |
23 |
Correct |
272 ms |
12248 KB |
Output is correct |
24 |
Correct |
186 ms |
11480 KB |
Output is correct |
25 |
Correct |
338 ms |
13016 KB |
Output is correct |
26 |
Correct |
331 ms |
13024 KB |
Output is correct |
27 |
Correct |
334 ms |
12812 KB |
Output is correct |
28 |
Correct |
224 ms |
12256 KB |
Output is correct |
29 |
Correct |
216 ms |
12264 KB |
Output is correct |
30 |
Correct |
141 ms |
11588 KB |
Output is correct |
31 |
Correct |
392 ms |
12492 KB |
Output is correct |
32 |
Correct |
388 ms |
13232 KB |
Output is correct |
33 |
Correct |
354 ms |
13016 KB |
Output is correct |
34 |
Correct |
292 ms |
11476 KB |
Output is correct |
35 |
Correct |
314 ms |
11472 KB |
Output is correct |
36 |
Correct |
202 ms |
11456 KB |
Output is correct |
37 |
Correct |
387 ms |
12524 KB |
Output is correct |
38 |
Correct |
401 ms |
12752 KB |
Output is correct |
39 |
Correct |
389 ms |
12664 KB |
Output is correct |
40 |
Correct |
233 ms |
12196 KB |
Output is correct |
41 |
Correct |
226 ms |
12248 KB |
Output is correct |
42 |
Correct |
140 ms |
11480 KB |
Output is correct |
43 |
Correct |
439 ms |
14392 KB |
Output is correct |
44 |
Correct |
431 ms |
14396 KB |
Output is correct |
45 |
Correct |
420 ms |
15220 KB |
Output is correct |
46 |
Correct |
296 ms |
12672 KB |
Output is correct |
47 |
Correct |
333 ms |
12784 KB |
Output is correct |
48 |
Correct |
184 ms |
10448 KB |
Output is correct |
49 |
Correct |
410 ms |
15200 KB |
Output is correct |
50 |
Correct |
428 ms |
14432 KB |
Output is correct |
51 |
Correct |
406 ms |
15024 KB |
Output is correct |
52 |
Correct |
300 ms |
12768 KB |
Output is correct |
53 |
Correct |
226 ms |
13052 KB |
Output is correct |