#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define fi first
#define se second
#define all(v) v.begin(), v.end()
struct fenwick {
vector<int> T; int sz;
fenwick(int N) { sz = N; T.resize(N + 1); }
void upd(int x) {
for(int i=x; i<=sz; i+=(i&-i)) ++T[i];
}
int get(int x) {
int s = 0;
for(int i=x; i>=1; i-=(i&-i)) s += T[i];
return s;
}
int sum(int l, int r) {
return get(r) - get(l-1);
}
};
struct q1 { int x, y, z, ty, id; };
struct q2 { int x, y, ty, id; };
pii A[100009];
int ans[100009];
vector<int> xs, ys;
inline int getx(int x) { return lower_bound(all(xs), x) - xs.begin() + 1; }
inline int gety(int y) { return lower_bound(all(ys), y) - ys.begin() + 1; }
int main() {
vector<q1> Q1;
vector<q2> Q2;
int N, Q; scanf("%d%d",&N,&Q);
for(int i=0; i<N; i++) {
int X, Y; scanf("%d%d",&X,&Y);
xs.push_back(X); ys.push_back(Y);
Q1.push_back({X, Y, X+Y, 0, i});
Q2.push_back({X, Y, 0, i});
A[i] = {X, Y};
}
for(int i=0; i<Q; i++) {
int X, Y, Z; scanf("%d%d%d",&X,&Y,&Z);
xs.push_back(X); ys.push_back(Y);
if(X + Y > Z) Q2.push_back({X, Y, 1, i});
else Q1.push_back({X, Y, Z, 1, i});
}
sort(all(xs)); xs.resize(unique(all(xs)) - xs.begin());
sort(all(ys)); ys.resize(unique(all(ys)) - ys.begin());
sort(all(Q1), [&](q1 A, q1 B) {
if(A.z == B.z) return A.ty < B.ty;
return A.z > B.z;
});
sort(all(Q2), [&](q2 A, q2 B) {
if(A.x == B.x) return A.ty < B.ty;
return A.x > B.x;
});
int xsz = xs.size(), ysz = ys.size(), cnt = 0;
fenwick XF(xsz), YF(ysz);
for(auto& it: Q1) {
if(it.ty == 0) {
++cnt;
XF.upd(getx(it.x));
YF.upd(gety(it.y));
}
if(it.ty == 1) {
ans[it.id] = cnt - XF.get(getx(it.x) - 1) - YF.get(gety(it.y) - 1);
}
}
fenwick F(ysz);
for(auto& it: Q2) {
if(it.ty == 0) {
F.upd(gety(it.y));
}
if(it.ty == 1) {
ans[it.id] = F.sum(gety(it.y), ysz);
}
}
for(int i=0; i<Q; i++) printf("%d\n", ans[i]);
return 0;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:36:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int N, Q; scanf("%d%d",&N,&Q);
~~~~~^~~~~~~~~~~~~~
examination.cpp:38:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int X, Y; scanf("%d%d",&X,&Y);
~~~~~^~~~~~~~~~~~~~
examination.cpp:45:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int X, Y, Z; scanf("%d%d%d",&X,&Y,&Z);
~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
8 ms |
768 KB |
Output is correct |
8 |
Correct |
7 ms |
768 KB |
Output is correct |
9 |
Correct |
10 ms |
768 KB |
Output is correct |
10 |
Correct |
7 ms |
768 KB |
Output is correct |
11 |
Correct |
8 ms |
768 KB |
Output is correct |
12 |
Correct |
6 ms |
768 KB |
Output is correct |
13 |
Correct |
10 ms |
912 KB |
Output is correct |
14 |
Correct |
8 ms |
896 KB |
Output is correct |
15 |
Correct |
9 ms |
896 KB |
Output is correct |
16 |
Correct |
6 ms |
768 KB |
Output is correct |
17 |
Correct |
10 ms |
896 KB |
Output is correct |
18 |
Correct |
7 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
10240 KB |
Output is correct |
2 |
Correct |
256 ms |
10160 KB |
Output is correct |
3 |
Correct |
228 ms |
10088 KB |
Output is correct |
4 |
Correct |
134 ms |
10080 KB |
Output is correct |
5 |
Correct |
196 ms |
10464 KB |
Output is correct |
6 |
Correct |
117 ms |
10208 KB |
Output is correct |
7 |
Correct |
221 ms |
12556 KB |
Output is correct |
8 |
Correct |
235 ms |
12516 KB |
Output is correct |
9 |
Correct |
205 ms |
12408 KB |
Output is correct |
10 |
Correct |
146 ms |
11592 KB |
Output is correct |
11 |
Correct |
153 ms |
11704 KB |
Output is correct |
12 |
Correct |
93 ms |
10668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
10240 KB |
Output is correct |
2 |
Correct |
256 ms |
10160 KB |
Output is correct |
3 |
Correct |
228 ms |
10088 KB |
Output is correct |
4 |
Correct |
134 ms |
10080 KB |
Output is correct |
5 |
Correct |
196 ms |
10464 KB |
Output is correct |
6 |
Correct |
117 ms |
10208 KB |
Output is correct |
7 |
Correct |
221 ms |
12556 KB |
Output is correct |
8 |
Correct |
235 ms |
12516 KB |
Output is correct |
9 |
Correct |
205 ms |
12408 KB |
Output is correct |
10 |
Correct |
146 ms |
11592 KB |
Output is correct |
11 |
Correct |
153 ms |
11704 KB |
Output is correct |
12 |
Correct |
93 ms |
10668 KB |
Output is correct |
13 |
Correct |
247 ms |
13448 KB |
Output is correct |
14 |
Correct |
201 ms |
13036 KB |
Output is correct |
15 |
Correct |
202 ms |
12696 KB |
Output is correct |
16 |
Correct |
145 ms |
12660 KB |
Output is correct |
17 |
Correct |
159 ms |
12776 KB |
Output is correct |
18 |
Correct |
109 ms |
11364 KB |
Output is correct |
19 |
Correct |
232 ms |
13472 KB |
Output is correct |
20 |
Correct |
245 ms |
14452 KB |
Output is correct |
21 |
Correct |
216 ms |
13296 KB |
Output is correct |
22 |
Correct |
153 ms |
11708 KB |
Output is correct |
23 |
Correct |
135 ms |
11616 KB |
Output is correct |
24 |
Correct |
83 ms |
10728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
8 ms |
768 KB |
Output is correct |
8 |
Correct |
7 ms |
768 KB |
Output is correct |
9 |
Correct |
10 ms |
768 KB |
Output is correct |
10 |
Correct |
7 ms |
768 KB |
Output is correct |
11 |
Correct |
8 ms |
768 KB |
Output is correct |
12 |
Correct |
6 ms |
768 KB |
Output is correct |
13 |
Correct |
10 ms |
912 KB |
Output is correct |
14 |
Correct |
8 ms |
896 KB |
Output is correct |
15 |
Correct |
9 ms |
896 KB |
Output is correct |
16 |
Correct |
6 ms |
768 KB |
Output is correct |
17 |
Correct |
10 ms |
896 KB |
Output is correct |
18 |
Correct |
7 ms |
768 KB |
Output is correct |
19 |
Correct |
212 ms |
10240 KB |
Output is correct |
20 |
Correct |
256 ms |
10160 KB |
Output is correct |
21 |
Correct |
228 ms |
10088 KB |
Output is correct |
22 |
Correct |
134 ms |
10080 KB |
Output is correct |
23 |
Correct |
196 ms |
10464 KB |
Output is correct |
24 |
Correct |
117 ms |
10208 KB |
Output is correct |
25 |
Correct |
221 ms |
12556 KB |
Output is correct |
26 |
Correct |
235 ms |
12516 KB |
Output is correct |
27 |
Correct |
205 ms |
12408 KB |
Output is correct |
28 |
Correct |
146 ms |
11592 KB |
Output is correct |
29 |
Correct |
153 ms |
11704 KB |
Output is correct |
30 |
Correct |
93 ms |
10668 KB |
Output is correct |
31 |
Correct |
247 ms |
13448 KB |
Output is correct |
32 |
Correct |
201 ms |
13036 KB |
Output is correct |
33 |
Correct |
202 ms |
12696 KB |
Output is correct |
34 |
Correct |
145 ms |
12660 KB |
Output is correct |
35 |
Correct |
159 ms |
12776 KB |
Output is correct |
36 |
Correct |
109 ms |
11364 KB |
Output is correct |
37 |
Correct |
232 ms |
13472 KB |
Output is correct |
38 |
Correct |
245 ms |
14452 KB |
Output is correct |
39 |
Correct |
216 ms |
13296 KB |
Output is correct |
40 |
Correct |
153 ms |
11708 KB |
Output is correct |
41 |
Correct |
135 ms |
11616 KB |
Output is correct |
42 |
Correct |
83 ms |
10728 KB |
Output is correct |
43 |
Correct |
275 ms |
16824 KB |
Output is correct |
44 |
Correct |
327 ms |
16768 KB |
Output is correct |
45 |
Correct |
250 ms |
16620 KB |
Output is correct |
46 |
Correct |
192 ms |
13684 KB |
Output is correct |
47 |
Correct |
212 ms |
14444 KB |
Output is correct |
48 |
Correct |
93 ms |
11252 KB |
Output is correct |
49 |
Correct |
239 ms |
16560 KB |
Output is correct |
50 |
Correct |
247 ms |
16736 KB |
Output is correct |
51 |
Correct |
247 ms |
16620 KB |
Output is correct |
52 |
Correct |
197 ms |
14304 KB |
Output is correct |
53 |
Correct |
182 ms |
12524 KB |
Output is correct |