#include <bits/stdc++.h>
using namespace std;
int segmenta[262144], segmentb[262144];
unordered_map<int,int> compressa, compressb;
void update(int x, int pos, int *segment) {
pos += 131072;
while (pos > 0) {
segment[pos] += x; pos /= 2;
}
}
int range(int a, int b, int *segment) {
int val = 0;
a += 131072; b += 131072;
while (a <= b) {
if (a%2 == 1) {val += segment[a++];}
if (b%2 == 0) {val += segment[b--];}
a/=2; b/=2;
}
return val;
}
void compress(vector<int> &arr, unordered_map<int,int> &compress) {
sort(arr.begin(), arr.end());
int count = 0; compress[arr[0]] = 0;
for (int i=1;i<arr.size();i++) {
if (arr[i] > arr[i-1]) {
count++;
compress[arr[i]] = count;
}
}
}
bool comp(vector<int> a, vector<int> b) {
return a[2] > b[2];
}
void querycompress(vector<vector<int>> &q, vector<int> &arra, vector<int> &arrb) {
int pos;
for (int i=0;i<q.size();i++) {
pos = lower_bound(arra.begin(), arra.end(), q[i][0]) - arra.begin();
if (pos == arra.size()) {
q[i][0] = compressa[arra[pos-1]] + 1;
} else {
q[i][0] = compressa[arra[pos]];
}
pos = lower_bound(arrb.begin(), arrb.end(), q[i][1]) - arrb.begin();
if (pos == arrb.size()) {
q[i][1] = compressb[arrb[pos-1]] + 1;
} else {
q[i][1] = compressb[arrb[pos]];
}
}
}
int main() {
int n, q; cin >> n >> q;
vector<vector<int>> ppl(n, vector<int>(3));
vector<int> arra(n), arrb(n), ansvec(q), query(4);
vector<vector<int>> aq, bq;
for (int i=0;i<n;i++) {
cin >> ppl[i][0] >> ppl[i][1];
ppl[i][2] = ppl[i][0] + ppl[i][1];
arra[i] = ppl[i][0]; arrb[i] = ppl[i][1];
}
for (int i=0;i<q;i++) {
cin >> query[0] >> query[1] >> query[2]; query[3] = i;
if (query[2] <= query[0] + query[1]) {
aq.push_back(query);
} else {
bq.push_back(query);
}
}
compress(arra, compressa); compress(arrb, compressb);
for (int i=0;i<n;i++) {
ppl[i][0] = compressa[ppl[i][0]];
ppl[i][1] = compressb[ppl[i][1]];
}
querycompress(aq, arra, arrb); querycompress(bq, arra, arrb);
for (int i=0;i<262144;i++) {segmentb[i] = 0;}
sort(ppl.begin(), ppl.end(), greater<vector<int>>());
sort(aq.begin(), aq.end(), greater<vector<int>>());
int tracker = 0;
for (int i=0;i<aq.size();i++) {
while (tracker < n && ppl[tracker][0] >= aq[i][0]) {
update(1, ppl[tracker][1], segmentb);
tracker++;
}
ansvec[aq[i][3]] = range(aq[i][1], 131071, segmentb);
}
for (int i=0;i<262144;i++) {segmenta[i] = 0; segmentb[i] = 0;}
sort(ppl.begin(), ppl.end(), comp);
sort(bq.begin(), bq.end(), comp);
tracker = 0;
for (int i=0;i<bq.size();i++) {
while (tracker < n && ppl[tracker][2] >= bq[i][2]) {
update(1, ppl[tracker][1], segmentb);
update(1, ppl[tracker][0], segmenta);
tracker++;
}
ansvec[bq[i][3]] = range(bq[i][1], 131071, segmentb) - range(0, bq[i][0] - 1, segmenta);
}
for (int i: ansvec) {
cout << i << '\n';
}
}
Compilation message
examination.cpp: In function 'void compress(std::vector<int>&, std::unordered_map<int, int>&)':
examination.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int i=1;i<arr.size();i++) {
| ~^~~~~~~~~~~
examination.cpp: In function 'void querycompress(std::vector<std::vector<int> >&, std::vector<int>&, std::vector<int>&)':
examination.cpp:46:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int i=0;i<q.size();i++) {
| ~^~~~~~~~~
examination.cpp:48:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | if (pos == arra.size()) {
| ~~~~^~~~~~~~~~~~~~
examination.cpp:54:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | if (pos == arrb.size()) {
| ~~~~^~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:95:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for (int i=0;i<aq.size();i++) {
| ~^~~~~~~~~~
examination.cpp:108:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
108 | for (int i=0;i<bq.size();i++) {
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
9 ms |
3276 KB |
Output is correct |
8 |
Correct |
9 ms |
3092 KB |
Output is correct |
9 |
Correct |
10 ms |
3056 KB |
Output is correct |
10 |
Correct |
8 ms |
2908 KB |
Output is correct |
11 |
Correct |
9 ms |
2908 KB |
Output is correct |
12 |
Correct |
6 ms |
2908 KB |
Output is correct |
13 |
Correct |
9 ms |
3056 KB |
Output is correct |
14 |
Correct |
8 ms |
3260 KB |
Output is correct |
15 |
Correct |
9 ms |
3164 KB |
Output is correct |
16 |
Correct |
6 ms |
2908 KB |
Output is correct |
17 |
Correct |
8 ms |
3068 KB |
Output is correct |
18 |
Correct |
5 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
268 ms |
22028 KB |
Output is correct |
2 |
Correct |
261 ms |
21764 KB |
Output is correct |
3 |
Correct |
295 ms |
21948 KB |
Output is correct |
4 |
Correct |
195 ms |
18824 KB |
Output is correct |
5 |
Correct |
220 ms |
18800 KB |
Output is correct |
6 |
Correct |
181 ms |
15992 KB |
Output is correct |
7 |
Correct |
256 ms |
22024 KB |
Output is correct |
8 |
Correct |
241 ms |
21988 KB |
Output is correct |
9 |
Correct |
252 ms |
21604 KB |
Output is correct |
10 |
Correct |
211 ms |
18432 KB |
Output is correct |
11 |
Correct |
203 ms |
18656 KB |
Output is correct |
12 |
Correct |
137 ms |
15616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
268 ms |
22028 KB |
Output is correct |
2 |
Correct |
261 ms |
21764 KB |
Output is correct |
3 |
Correct |
295 ms |
21948 KB |
Output is correct |
4 |
Correct |
195 ms |
18824 KB |
Output is correct |
5 |
Correct |
220 ms |
18800 KB |
Output is correct |
6 |
Correct |
181 ms |
15992 KB |
Output is correct |
7 |
Correct |
256 ms |
22024 KB |
Output is correct |
8 |
Correct |
241 ms |
21988 KB |
Output is correct |
9 |
Correct |
252 ms |
21604 KB |
Output is correct |
10 |
Correct |
211 ms |
18432 KB |
Output is correct |
11 |
Correct |
203 ms |
18656 KB |
Output is correct |
12 |
Correct |
137 ms |
15616 KB |
Output is correct |
13 |
Correct |
297 ms |
22236 KB |
Output is correct |
14 |
Correct |
267 ms |
23296 KB |
Output is correct |
15 |
Correct |
247 ms |
22788 KB |
Output is correct |
16 |
Correct |
252 ms |
19900 KB |
Output is correct |
17 |
Correct |
261 ms |
19740 KB |
Output is correct |
18 |
Correct |
171 ms |
16352 KB |
Output is correct |
19 |
Correct |
302 ms |
23224 KB |
Output is correct |
20 |
Correct |
275 ms |
23228 KB |
Output is correct |
21 |
Correct |
312 ms |
23380 KB |
Output is correct |
22 |
Correct |
231 ms |
19288 KB |
Output is correct |
23 |
Correct |
210 ms |
19300 KB |
Output is correct |
24 |
Correct |
139 ms |
15840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
9 ms |
3276 KB |
Output is correct |
8 |
Correct |
9 ms |
3092 KB |
Output is correct |
9 |
Correct |
10 ms |
3056 KB |
Output is correct |
10 |
Correct |
8 ms |
2908 KB |
Output is correct |
11 |
Correct |
9 ms |
2908 KB |
Output is correct |
12 |
Correct |
6 ms |
2908 KB |
Output is correct |
13 |
Correct |
9 ms |
3056 KB |
Output is correct |
14 |
Correct |
8 ms |
3260 KB |
Output is correct |
15 |
Correct |
9 ms |
3164 KB |
Output is correct |
16 |
Correct |
6 ms |
2908 KB |
Output is correct |
17 |
Correct |
8 ms |
3068 KB |
Output is correct |
18 |
Correct |
5 ms |
2908 KB |
Output is correct |
19 |
Correct |
268 ms |
22028 KB |
Output is correct |
20 |
Correct |
261 ms |
21764 KB |
Output is correct |
21 |
Correct |
295 ms |
21948 KB |
Output is correct |
22 |
Correct |
195 ms |
18824 KB |
Output is correct |
23 |
Correct |
220 ms |
18800 KB |
Output is correct |
24 |
Correct |
181 ms |
15992 KB |
Output is correct |
25 |
Correct |
256 ms |
22024 KB |
Output is correct |
26 |
Correct |
241 ms |
21988 KB |
Output is correct |
27 |
Correct |
252 ms |
21604 KB |
Output is correct |
28 |
Correct |
211 ms |
18432 KB |
Output is correct |
29 |
Correct |
203 ms |
18656 KB |
Output is correct |
30 |
Correct |
137 ms |
15616 KB |
Output is correct |
31 |
Correct |
297 ms |
22236 KB |
Output is correct |
32 |
Correct |
267 ms |
23296 KB |
Output is correct |
33 |
Correct |
247 ms |
22788 KB |
Output is correct |
34 |
Correct |
252 ms |
19900 KB |
Output is correct |
35 |
Correct |
261 ms |
19740 KB |
Output is correct |
36 |
Correct |
171 ms |
16352 KB |
Output is correct |
37 |
Correct |
302 ms |
23224 KB |
Output is correct |
38 |
Correct |
275 ms |
23228 KB |
Output is correct |
39 |
Correct |
312 ms |
23380 KB |
Output is correct |
40 |
Correct |
231 ms |
19288 KB |
Output is correct |
41 |
Correct |
210 ms |
19300 KB |
Output is correct |
42 |
Correct |
139 ms |
15840 KB |
Output is correct |
43 |
Correct |
352 ms |
29192 KB |
Output is correct |
44 |
Correct |
370 ms |
29204 KB |
Output is correct |
45 |
Correct |
330 ms |
29184 KB |
Output is correct |
46 |
Correct |
288 ms |
22932 KB |
Output is correct |
47 |
Correct |
281 ms |
22968 KB |
Output is correct |
48 |
Correct |
217 ms |
15976 KB |
Output is correct |
49 |
Correct |
333 ms |
29076 KB |
Output is correct |
50 |
Correct |
373 ms |
28924 KB |
Output is correct |
51 |
Correct |
367 ms |
28928 KB |
Output is correct |
52 |
Correct |
305 ms |
22972 KB |
Output is correct |
53 |
Correct |
251 ms |
22020 KB |
Output is correct |