#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, q, ans[N], cnt = 0;
map <int, int> compress;
vector <int> vecm, veci;
struct data {
int math, infor, sum;
bool operator < (const data &rhs) const {
return sum > rhs.sum;
}
} a[N];
struct Query {
int a, b, c, id;
bool operator < (const Query &rhs) const {
return c > rhs.c;
}
} queries[N];
struct DynamicIT {
int s, e, mid, sum;
DynamicIT *l, *r;
DynamicIT (int _s, int _e) {
s = _s; e = _e; mid = (s + e) / 2; sum = 0;
l = r = NULL;
}
void update (int pos) {
if (s == e) {
sum++;
return;
}
if (pos <= mid) {
if (l == NULL) l = new DynamicIT(s, mid);
l -> update(pos);
}
else {
if (r == NULL) r = new DynamicIT(mid + 1, e);
r -> update(pos);
}
sum = 0;
if (l != NULL) sum += l -> sum;
if (r != NULL) sum += r -> sum;
}
int query (int Start, int End) {
if (Start > e || End < s) return 0;
if (Start <= s && e <= End) return sum;
int res = 0;
if (l != NULL) res += l -> query(Start, End);
if (r != NULL) res += r -> query(Start, End);
return res;
}
};
DynamicIT* bit[N];
void update (int x, int y) {
for (int i = x; i > 0; i -= i & -i) bit[i] -> update(y);
}
int get_value (int x, int y) {
int ans = 0;
for (int i = x; i < N; i += i & -i) ans += bit[i] -> query(y, N);
return ans;
}
int main(){
scanf("%d %d", &n, &q);
for (int i = 1; i <= n; i++) {
scanf("%d %d", &a[i].math, &a[i].infor);
a[i].sum = a[i].math + a[i].infor;
vecm.push_back(a[i].math);
veci.push_back(a[i].infor);
}
for (int i = 1; i <= q; i++) {
scanf("%d %d %d", &queries[i].a, &queries[i].b, &queries[i].c);
queries[i].id = i;
vecm.push_back(queries[i].a);
veci.push_back(queries[i].b);
}
sort(a + 1, a + n + 1);
sort(queries + 1, queries + q + 1);
sort(vecm.begin(), vecm.end());
sort(veci.begin(), veci.end());
//Compress coordinate
compress[vecm[0]] = ++cnt;
for (int i = 1; i < vecm.size(); i++) if (vecm[i] > vecm[i - 1]) compress[vecm[i]] = ++cnt;
for (int i = 1; i <= n; i++) a[i].math = compress[a[i].math];
for (int i = 1; i <= q; i++) queries[i].a = compress[queries[i].a];
cnt = 0; compress.clear();
compress[veci[0]] = ++cnt;
for (int i = 1; i < veci.size(); i++) if (veci[i] > veci[i - 1]) compress[veci[i]] = ++cnt;
for (int i = 1; i <= n; i++) a[i].infor = compress[a[i].infor];
for (int i = 1; i <= q; i++) queries[i].b = compress[queries[i].b];
//
for (int i = 1; i < N; i++) bit[i] = new DynamicIT(1, N);
int ptr = 1;
for (int i = 1; i <= q; i++) {
while (ptr <= n && a[ptr].sum >= queries[i].c) {
update(a[ptr].math, a[ptr].infor);
ptr++;
}
ans[queries[i].id] = get_value(queries[i].a, queries[i].b);
}
for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
return 0;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:99:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < vecm.size(); i++) if (vecm[i] > vecm[i - 1]) compress[vecm[i]] = ++cnt;
~~^~~~~~~~~~~~~
examination.cpp:105:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < veci.size(); i++) if (veci[i] > veci[i - 1]) compress[veci[i]] = ++cnt;
~~^~~~~~~~~~~~~
examination.cpp:77: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:79:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &a[i].math, &a[i].infor);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:86:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &queries[i].a, &queries[i].b, &queries[i].c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
11264 KB |
Output is correct |
2 |
Correct |
18 ms |
11264 KB |
Output is correct |
3 |
Correct |
15 ms |
11264 KB |
Output is correct |
4 |
Correct |
14 ms |
11264 KB |
Output is correct |
5 |
Correct |
14 ms |
11236 KB |
Output is correct |
6 |
Correct |
16 ms |
11364 KB |
Output is correct |
7 |
Correct |
44 ms |
20344 KB |
Output is correct |
8 |
Correct |
47 ms |
20216 KB |
Output is correct |
9 |
Correct |
44 ms |
20216 KB |
Output is correct |
10 |
Correct |
27 ms |
15324 KB |
Output is correct |
11 |
Correct |
22 ms |
12928 KB |
Output is correct |
12 |
Correct |
19 ms |
11512 KB |
Output is correct |
13 |
Correct |
55 ms |
20344 KB |
Output is correct |
14 |
Correct |
45 ms |
20216 KB |
Output is correct |
15 |
Correct |
46 ms |
20344 KB |
Output is correct |
16 |
Correct |
24 ms |
12132 KB |
Output is correct |
17 |
Correct |
26 ms |
14840 KB |
Output is correct |
18 |
Correct |
19 ms |
11520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2331 ms |
391156 KB |
Output is correct |
2 |
Correct |
2312 ms |
392080 KB |
Output is correct |
3 |
Correct |
2333 ms |
392384 KB |
Output is correct |
4 |
Correct |
949 ms |
94704 KB |
Output is correct |
5 |
Correct |
467 ms |
50788 KB |
Output is correct |
6 |
Correct |
141 ms |
17020 KB |
Output is correct |
7 |
Correct |
2304 ms |
379236 KB |
Output is correct |
8 |
Correct |
2300 ms |
379508 KB |
Output is correct |
9 |
Correct |
1739 ms |
366732 KB |
Output is correct |
10 |
Correct |
298 ms |
27876 KB |
Output is correct |
11 |
Correct |
699 ms |
78832 KB |
Output is correct |
12 |
Correct |
87 ms |
16664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2331 ms |
391156 KB |
Output is correct |
2 |
Correct |
2312 ms |
392080 KB |
Output is correct |
3 |
Correct |
2333 ms |
392384 KB |
Output is correct |
4 |
Correct |
949 ms |
94704 KB |
Output is correct |
5 |
Correct |
467 ms |
50788 KB |
Output is correct |
6 |
Correct |
141 ms |
17020 KB |
Output is correct |
7 |
Correct |
2304 ms |
379236 KB |
Output is correct |
8 |
Correct |
2300 ms |
379508 KB |
Output is correct |
9 |
Correct |
1739 ms |
366732 KB |
Output is correct |
10 |
Correct |
298 ms |
27876 KB |
Output is correct |
11 |
Correct |
699 ms |
78832 KB |
Output is correct |
12 |
Correct |
87 ms |
16664 KB |
Output is correct |
13 |
Correct |
2041 ms |
392100 KB |
Output is correct |
14 |
Correct |
2472 ms |
391968 KB |
Output is correct |
15 |
Correct |
2324 ms |
391596 KB |
Output is correct |
16 |
Correct |
788 ms |
94608 KB |
Output is correct |
17 |
Correct |
377 ms |
50656 KB |
Output is correct |
18 |
Correct |
150 ms |
17096 KB |
Output is correct |
19 |
Correct |
2051 ms |
392364 KB |
Output is correct |
20 |
Correct |
2204 ms |
392072 KB |
Output is correct |
21 |
Correct |
1689 ms |
382184 KB |
Output is correct |
22 |
Correct |
261 ms |
27988 KB |
Output is correct |
23 |
Correct |
642 ms |
78788 KB |
Output is correct |
24 |
Correct |
91 ms |
16840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
11264 KB |
Output is correct |
2 |
Correct |
18 ms |
11264 KB |
Output is correct |
3 |
Correct |
15 ms |
11264 KB |
Output is correct |
4 |
Correct |
14 ms |
11264 KB |
Output is correct |
5 |
Correct |
14 ms |
11236 KB |
Output is correct |
6 |
Correct |
16 ms |
11364 KB |
Output is correct |
7 |
Correct |
44 ms |
20344 KB |
Output is correct |
8 |
Correct |
47 ms |
20216 KB |
Output is correct |
9 |
Correct |
44 ms |
20216 KB |
Output is correct |
10 |
Correct |
27 ms |
15324 KB |
Output is correct |
11 |
Correct |
22 ms |
12928 KB |
Output is correct |
12 |
Correct |
19 ms |
11512 KB |
Output is correct |
13 |
Correct |
55 ms |
20344 KB |
Output is correct |
14 |
Correct |
45 ms |
20216 KB |
Output is correct |
15 |
Correct |
46 ms |
20344 KB |
Output is correct |
16 |
Correct |
24 ms |
12132 KB |
Output is correct |
17 |
Correct |
26 ms |
14840 KB |
Output is correct |
18 |
Correct |
19 ms |
11520 KB |
Output is correct |
19 |
Correct |
2331 ms |
391156 KB |
Output is correct |
20 |
Correct |
2312 ms |
392080 KB |
Output is correct |
21 |
Correct |
2333 ms |
392384 KB |
Output is correct |
22 |
Correct |
949 ms |
94704 KB |
Output is correct |
23 |
Correct |
467 ms |
50788 KB |
Output is correct |
24 |
Correct |
141 ms |
17020 KB |
Output is correct |
25 |
Correct |
2304 ms |
379236 KB |
Output is correct |
26 |
Correct |
2300 ms |
379508 KB |
Output is correct |
27 |
Correct |
1739 ms |
366732 KB |
Output is correct |
28 |
Correct |
298 ms |
27876 KB |
Output is correct |
29 |
Correct |
699 ms |
78832 KB |
Output is correct |
30 |
Correct |
87 ms |
16664 KB |
Output is correct |
31 |
Correct |
2041 ms |
392100 KB |
Output is correct |
32 |
Correct |
2472 ms |
391968 KB |
Output is correct |
33 |
Correct |
2324 ms |
391596 KB |
Output is correct |
34 |
Correct |
788 ms |
94608 KB |
Output is correct |
35 |
Correct |
377 ms |
50656 KB |
Output is correct |
36 |
Correct |
150 ms |
17096 KB |
Output is correct |
37 |
Correct |
2051 ms |
392364 KB |
Output is correct |
38 |
Correct |
2204 ms |
392072 KB |
Output is correct |
39 |
Correct |
1689 ms |
382184 KB |
Output is correct |
40 |
Correct |
261 ms |
27988 KB |
Output is correct |
41 |
Correct |
642 ms |
78788 KB |
Output is correct |
42 |
Correct |
91 ms |
16840 KB |
Output is correct |
43 |
Correct |
2395 ms |
489076 KB |
Output is correct |
44 |
Correct |
2187 ms |
489416 KB |
Output is correct |
45 |
Correct |
2577 ms |
489476 KB |
Output is correct |
46 |
Correct |
935 ms |
147160 KB |
Output is correct |
47 |
Correct |
530 ms |
66940 KB |
Output is correct |
48 |
Correct |
122 ms |
16612 KB |
Output is correct |
49 |
Correct |
2326 ms |
475860 KB |
Output is correct |
50 |
Correct |
2015 ms |
468040 KB |
Output is correct |
51 |
Correct |
1984 ms |
452752 KB |
Output is correct |
52 |
Correct |
361 ms |
39076 KB |
Output is correct |
53 |
Correct |
897 ms |
131544 KB |
Output is correct |