#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;
const int MAXQ = 1e5;
const int MAXVAL = 1e9;
int N, Q, ans[MAXQ+10];
pii A[MAXN+10];
struct Data { int x, y, z, num; };
Data B[MAXQ+10];
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 Node1
{
int val; Node1 *lc, *rc;
Node1() : val(0), lc(NULL), rc(NULL) {}
};
int query1(Node1 *node, int tl, int tr, int xl, int xr)
{
if(xr<tl || tr<xl) return 0;
if(xl<=tl && tr<=xr) return node->val;
int mid=tl+tr>>1;
int ret=0;
if(node->lc!=NULL) ret+=query1(node->lc, tl, mid, xl, xr);
if(node->rc!=NULL) ret+=query1(node->rc, mid+1, tr, xl, xr);
return ret;
}
void update1(Node1 *node, int tl, int tr, int x)
{
if(tl==tr)
{
node->val++;
return;
}
int mid=tl+tr>>1;
if(x<=mid)
{
if(node->lc==NULL) node->lc=new Node1();
update1(node->lc, tl, mid, x);
}
else
{
if(node->rc==NULL) node->rc=new Node1();
update1(node->rc, mid+1, tr, x);
}
node->val++;
}
Node1 *tree[MAXN+10];
void update2(int y, int x) { for(; y<=ycomp.size(); y+=(y&-y)) update1(tree[y], 1, xcomp.size(), x); }
int query2(int y, int xl, int xr) { int ret=0; for(; y>0; y-=(y&-y)) ret+=query1(tree[y], 1, xcomp.size(), xl, xr); return ret; }
int query2(int yl, int yr, int xl, int xr) { return query2(yr, xl, xr)-query2(yl-1, xl, xr); }
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].num=i;
xcomp.push_back(MAXVAL);
ycomp.push_back(MAXVAL);
for(i=0; i<=ycomp.size(); i++) tree[i]=new Node1();
sort(xcomp.begin(), xcomp.end());
sort(ycomp.begin(), ycomp.end());
xcomp.erase(unique(xcomp.begin(), xcomp.end()), xcomp.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++) update2(getycomp(A[it].second), getxcomp(A[it].first));
ans[B[i].num]=query2(getycomp(B[i].y), getycomp(MAXVAL), getxcomp(B[i].x), getxcomp(MAXVAL));
}
for(i=1; i<=Q; i++) printf("%d\n", ans[i]);
}
Compilation message
examination.cpp: In function 'int query1(Node1*, int, int, int, int)':
examination.cpp:32:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
examination.cpp: In function 'void update1(Node1*, int, int, int)':
examination.cpp:46:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
examination.cpp: In function 'void update2(int, int)':
examination.cpp:61:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
void update2(int y, int x) { for(; y<=ycomp.size(); y+=(y&-y)) update1(tree[y], 1, xcomp.size(), x); }
~^~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:75:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0; i<=ycomp.size(); i++) tree[i]=new Node1();
~^~~~~~~~~~~~~~
examination.cpp:67:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
examination.cpp:69: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:70: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:71: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].num=i;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
20 ms |
4728 KB |
Output is correct |
8 |
Correct |
20 ms |
4800 KB |
Output is correct |
9 |
Correct |
20 ms |
4728 KB |
Output is correct |
10 |
Correct |
9 ms |
1400 KB |
Output is correct |
11 |
Correct |
9 ms |
1400 KB |
Output is correct |
12 |
Correct |
5 ms |
632 KB |
Output is correct |
13 |
Correct |
21 ms |
4728 KB |
Output is correct |
14 |
Correct |
21 ms |
4728 KB |
Output is correct |
15 |
Correct |
22 ms |
4856 KB |
Output is correct |
16 |
Correct |
6 ms |
760 KB |
Output is correct |
17 |
Correct |
8 ms |
980 KB |
Output is correct |
18 |
Correct |
4 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1843 ms |
233344 KB |
Output is correct |
2 |
Correct |
1840 ms |
233732 KB |
Output is correct |
3 |
Correct |
1765 ms |
233828 KB |
Output is correct |
4 |
Correct |
330 ms |
30828 KB |
Output is correct |
5 |
Correct |
287 ms |
27424 KB |
Output is correct |
6 |
Correct |
98 ms |
9324 KB |
Output is correct |
7 |
Correct |
1560 ms |
233136 KB |
Output is correct |
8 |
Correct |
1553 ms |
233652 KB |
Output is correct |
9 |
Correct |
1317 ms |
233440 KB |
Output is correct |
10 |
Correct |
153 ms |
11884 KB |
Output is correct |
11 |
Correct |
210 ms |
17848 KB |
Output is correct |
12 |
Correct |
72 ms |
8940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1843 ms |
233344 KB |
Output is correct |
2 |
Correct |
1840 ms |
233732 KB |
Output is correct |
3 |
Correct |
1765 ms |
233828 KB |
Output is correct |
4 |
Correct |
330 ms |
30828 KB |
Output is correct |
5 |
Correct |
287 ms |
27424 KB |
Output is correct |
6 |
Correct |
98 ms |
9324 KB |
Output is correct |
7 |
Correct |
1560 ms |
233136 KB |
Output is correct |
8 |
Correct |
1553 ms |
233652 KB |
Output is correct |
9 |
Correct |
1317 ms |
233440 KB |
Output is correct |
10 |
Correct |
153 ms |
11884 KB |
Output is correct |
11 |
Correct |
210 ms |
17848 KB |
Output is correct |
12 |
Correct |
72 ms |
8940 KB |
Output is correct |
13 |
Correct |
1553 ms |
233912 KB |
Output is correct |
14 |
Correct |
1813 ms |
234380 KB |
Output is correct |
15 |
Correct |
1870 ms |
233564 KB |
Output is correct |
16 |
Correct |
282 ms |
31364 KB |
Output is correct |
17 |
Correct |
272 ms |
27688 KB |
Output is correct |
18 |
Correct |
101 ms |
9320 KB |
Output is correct |
19 |
Correct |
1610 ms |
234308 KB |
Output is correct |
20 |
Correct |
1677 ms |
233968 KB |
Output is correct |
21 |
Correct |
1285 ms |
234008 KB |
Output is correct |
22 |
Correct |
155 ms |
11880 KB |
Output is correct |
23 |
Correct |
203 ms |
17732 KB |
Output is correct |
24 |
Correct |
70 ms |
8936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
20 ms |
4728 KB |
Output is correct |
8 |
Correct |
20 ms |
4800 KB |
Output is correct |
9 |
Correct |
20 ms |
4728 KB |
Output is correct |
10 |
Correct |
9 ms |
1400 KB |
Output is correct |
11 |
Correct |
9 ms |
1400 KB |
Output is correct |
12 |
Correct |
5 ms |
632 KB |
Output is correct |
13 |
Correct |
21 ms |
4728 KB |
Output is correct |
14 |
Correct |
21 ms |
4728 KB |
Output is correct |
15 |
Correct |
22 ms |
4856 KB |
Output is correct |
16 |
Correct |
6 ms |
760 KB |
Output is correct |
17 |
Correct |
8 ms |
980 KB |
Output is correct |
18 |
Correct |
4 ms |
632 KB |
Output is correct |
19 |
Correct |
1843 ms |
233344 KB |
Output is correct |
20 |
Correct |
1840 ms |
233732 KB |
Output is correct |
21 |
Correct |
1765 ms |
233828 KB |
Output is correct |
22 |
Correct |
330 ms |
30828 KB |
Output is correct |
23 |
Correct |
287 ms |
27424 KB |
Output is correct |
24 |
Correct |
98 ms |
9324 KB |
Output is correct |
25 |
Correct |
1560 ms |
233136 KB |
Output is correct |
26 |
Correct |
1553 ms |
233652 KB |
Output is correct |
27 |
Correct |
1317 ms |
233440 KB |
Output is correct |
28 |
Correct |
153 ms |
11884 KB |
Output is correct |
29 |
Correct |
210 ms |
17848 KB |
Output is correct |
30 |
Correct |
72 ms |
8940 KB |
Output is correct |
31 |
Correct |
1553 ms |
233912 KB |
Output is correct |
32 |
Correct |
1813 ms |
234380 KB |
Output is correct |
33 |
Correct |
1870 ms |
233564 KB |
Output is correct |
34 |
Correct |
282 ms |
31364 KB |
Output is correct |
35 |
Correct |
272 ms |
27688 KB |
Output is correct |
36 |
Correct |
101 ms |
9320 KB |
Output is correct |
37 |
Correct |
1610 ms |
234308 KB |
Output is correct |
38 |
Correct |
1677 ms |
233968 KB |
Output is correct |
39 |
Correct |
1285 ms |
234008 KB |
Output is correct |
40 |
Correct |
155 ms |
11880 KB |
Output is correct |
41 |
Correct |
203 ms |
17732 KB |
Output is correct |
42 |
Correct |
70 ms |
8936 KB |
Output is correct |
43 |
Correct |
1657 ms |
275372 KB |
Output is correct |
44 |
Correct |
1681 ms |
275384 KB |
Output is correct |
45 |
Correct |
2032 ms |
275552 KB |
Output is correct |
46 |
Correct |
318 ms |
38508 KB |
Output is correct |
47 |
Correct |
308 ms |
33308 KB |
Output is correct |
48 |
Correct |
97 ms |
9196 KB |
Output is correct |
49 |
Correct |
1631 ms |
275360 KB |
Output is correct |
50 |
Correct |
1415 ms |
275252 KB |
Output is correct |
51 |
Correct |
1268 ms |
275132 KB |
Output is correct |
52 |
Correct |
198 ms |
14512 KB |
Output is correct |
53 |
Correct |
237 ms |
23208 KB |
Output is correct |