#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
struct Score {
int s, t;
int sum() const {
return s + t;
}
bool operator<(Score o) const {
if(sum() != o.sum()) return sum() > o.sum();
if(s != o.s) return s < o.s;
return t < o.t;
}
};
struct Query {
int i, a, b, c;
bool operator<(Query q) const {
if(c != q.c) return c > q.c;
return i < q.i;
}
};
int N, Q;
Score scores[MAXN + 10];
Query queries[MAXN + 10];
int res[MAXN + 10];
vector<int> svals, tvals;
void compress() {
for(int i = 0; i < N; i++) {
svals.push_back(scores[i].s);
tvals.push_back(scores[i].t);
}
sort(svals.begin(), svals.end());
svals.erase(unique(svals.begin(), svals.end()), svals.end());
sort(tvals.begin(), tvals.end());
tvals.erase(unique(tvals.begin(), tvals.end()), tvals.end());
}
struct SegT {
int L, R, cc;
};
int tree[MAXN + 10];
SegT tree_t[int(1e7) + 10];
int create_seg_t(int l, int r, int cc) {
static int ii = 0;
tree_t[ii].L = l;
tree_t[ii].R = r;
tree_t[ii].cc = cc;
++ii;
return ii - 1;
}
int get_t(int cn, int b, int e, int l, int r) {
if(r < b || l > e || cn == -1) return 0;
if(l <= b && e <= r) return tree_t[cn].cc;
int m = (b + e) / 2;
return get_t(tree_t[cn].L, b, m, l, r) + get_t(tree_t[cn].R, m+1, e, l, r);
}
int get_t(int cn, int ti) {
return get_t(cn, 0, tvals.size() - 1, ti, tvals.size() - 1);
}
int get(int si, int ti) {
si = svals.size() - si; // 0 -> n, n - 1 -> 1
int rs = 0;
while(si > 0) {
rs += get_t(tree[si], ti);
si -= si & (-si);
}
return rs;
}
int upd_t(int cn, int b, int e, int i) {
//cerr << "upd_t(" << cn << ", [" << b << ", " << e << "], " << i << ")\n";
//cerr << "-------->\n\n";
if(cn == -1) {
cn = create_seg_t(-1, -1, 0);
}
tree_t[cn].cc++;
//cerr << "tree_t[" << cn << "].cc = " << tree_t[cn].cc << "\n";
if(b == e) {
//cerr << cn << " <---------------------\n\n";
return cn;
}
int m = (b + e) / 2;
//cerr << "cn = " << cn << "\n";
if(i <= m) {
tree_t[cn].L = upd_t(tree_t[cn].L, b, m, i);
//cerr << "to left = " << tree_t[cn].L << "\n";
} else {
tree_t[cn].R = upd_t(tree_t[cn].R, m + 1, e, i);
//cerr << "to right = " << tree_t[cn].R << "\n";
}
//cerr << cn << " --> " << tree_t[cn].L << " " << tree_t[cn].R << "\n";
//cerr << cn << " <----------------\n\n";
return cn;
}
int upd_t(int cn, int ti) {
return upd_t(cn, 0, tvals.size() - 1, ti);
}
void upd(int si, int ti) {
//cerr << si << " " << ti << "\n";
si = svals.size() - si;
while(si <= (int)svals.size()) {
tree[si] = upd_t(tree[si], ti);
si += si & (-si);
}
}
void add(Score sc) {
int si = lower_bound(svals.begin(), svals.end(), sc.s) - svals.begin();
int ti = lower_bound(tvals.begin(), tvals.end(), sc.t) - tvals.begin();
return upd(si, ti);
}
int calc(Query q) {
int si = lower_bound(svals.begin(), svals.end(), q.a) - svals.begin();
int ti = lower_bound(tvals.begin(), tvals.end(), q.b) - tvals.begin();
return get(si, ti);
}
int main() {
scanf("%d%d", &N, &Q);
for(int i = 0; i < N; i++) {
scanf("%d%d", &scores[i].s, &scores[i].t);
}
for(int i = 0; i < Q; i++) {
scanf("%d%d%d", &queries[i].a, &queries[i].b, &queries[i].c);
queries[i].i = i;
}
sort(scores, scores + N);
sort(queries, queries + Q);
compress();
memset(tree, -1, sizeof tree);
int i = 0;
for(int q = 0; q < Q; q++) {
while(i < N && scores[i].sum() >= queries[q].c) {
add(scores[i]);
i++;
}
res[queries[q].i] = calc(queries[q]);
}
for(int q = 0; q < Q; q++) {
printf("%d\n", res[q]);
}
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:138:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &Q);
~~~~~^~~~~~~~~~~~~~~~
examination.cpp:140:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &scores[i].s, &scores[i].t);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:143:12: 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 |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
3 |
Correct |
3 ms |
768 KB |
Output is correct |
4 |
Correct |
3 ms |
768 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
2 ms |
768 KB |
Output is correct |
7 |
Correct |
12 ms |
2560 KB |
Output is correct |
8 |
Correct |
12 ms |
2560 KB |
Output is correct |
9 |
Correct |
11 ms |
2560 KB |
Output is correct |
10 |
Correct |
8 ms |
1208 KB |
Output is correct |
11 |
Correct |
7 ms |
1280 KB |
Output is correct |
12 |
Correct |
6 ms |
868 KB |
Output is correct |
13 |
Correct |
16 ms |
2560 KB |
Output is correct |
14 |
Correct |
13 ms |
2560 KB |
Output is correct |
15 |
Correct |
13 ms |
2560 KB |
Output is correct |
16 |
Correct |
7 ms |
1024 KB |
Output is correct |
17 |
Correct |
7 ms |
1024 KB |
Output is correct |
18 |
Correct |
4 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1109 ms |
91280 KB |
Output is correct |
2 |
Correct |
1170 ms |
91368 KB |
Output is correct |
3 |
Correct |
1165 ms |
91348 KB |
Output is correct |
4 |
Correct |
250 ms |
13208 KB |
Output is correct |
5 |
Correct |
242 ms |
13292 KB |
Output is correct |
6 |
Correct |
82 ms |
6124 KB |
Output is correct |
7 |
Correct |
1093 ms |
91500 KB |
Output is correct |
8 |
Correct |
1008 ms |
91520 KB |
Output is correct |
9 |
Correct |
700 ms |
91360 KB |
Output is correct |
10 |
Correct |
111 ms |
7656 KB |
Output is correct |
11 |
Correct |
129 ms |
6928 KB |
Output is correct |
12 |
Correct |
60 ms |
5612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1109 ms |
91280 KB |
Output is correct |
2 |
Correct |
1170 ms |
91368 KB |
Output is correct |
3 |
Correct |
1165 ms |
91348 KB |
Output is correct |
4 |
Correct |
250 ms |
13208 KB |
Output is correct |
5 |
Correct |
242 ms |
13292 KB |
Output is correct |
6 |
Correct |
82 ms |
6124 KB |
Output is correct |
7 |
Correct |
1093 ms |
91500 KB |
Output is correct |
8 |
Correct |
1008 ms |
91520 KB |
Output is correct |
9 |
Correct |
700 ms |
91360 KB |
Output is correct |
10 |
Correct |
111 ms |
7656 KB |
Output is correct |
11 |
Correct |
129 ms |
6928 KB |
Output is correct |
12 |
Correct |
60 ms |
5612 KB |
Output is correct |
13 |
Correct |
937 ms |
91284 KB |
Output is correct |
14 |
Correct |
1050 ms |
91612 KB |
Output is correct |
15 |
Correct |
1117 ms |
91372 KB |
Output is correct |
16 |
Correct |
193 ms |
13928 KB |
Output is correct |
17 |
Correct |
199 ms |
13688 KB |
Output is correct |
18 |
Correct |
87 ms |
6024 KB |
Output is correct |
19 |
Correct |
878 ms |
91328 KB |
Output is correct |
20 |
Correct |
961 ms |
91380 KB |
Output is correct |
21 |
Correct |
738 ms |
91484 KB |
Output is correct |
22 |
Correct |
128 ms |
7660 KB |
Output is correct |
23 |
Correct |
108 ms |
6892 KB |
Output is correct |
24 |
Correct |
60 ms |
5612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
3 |
Correct |
3 ms |
768 KB |
Output is correct |
4 |
Correct |
3 ms |
768 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
2 ms |
768 KB |
Output is correct |
7 |
Correct |
12 ms |
2560 KB |
Output is correct |
8 |
Correct |
12 ms |
2560 KB |
Output is correct |
9 |
Correct |
11 ms |
2560 KB |
Output is correct |
10 |
Correct |
8 ms |
1208 KB |
Output is correct |
11 |
Correct |
7 ms |
1280 KB |
Output is correct |
12 |
Correct |
6 ms |
868 KB |
Output is correct |
13 |
Correct |
16 ms |
2560 KB |
Output is correct |
14 |
Correct |
13 ms |
2560 KB |
Output is correct |
15 |
Correct |
13 ms |
2560 KB |
Output is correct |
16 |
Correct |
7 ms |
1024 KB |
Output is correct |
17 |
Correct |
7 ms |
1024 KB |
Output is correct |
18 |
Correct |
4 ms |
896 KB |
Output is correct |
19 |
Correct |
1109 ms |
91280 KB |
Output is correct |
20 |
Correct |
1170 ms |
91368 KB |
Output is correct |
21 |
Correct |
1165 ms |
91348 KB |
Output is correct |
22 |
Correct |
250 ms |
13208 KB |
Output is correct |
23 |
Correct |
242 ms |
13292 KB |
Output is correct |
24 |
Correct |
82 ms |
6124 KB |
Output is correct |
25 |
Correct |
1093 ms |
91500 KB |
Output is correct |
26 |
Correct |
1008 ms |
91520 KB |
Output is correct |
27 |
Correct |
700 ms |
91360 KB |
Output is correct |
28 |
Correct |
111 ms |
7656 KB |
Output is correct |
29 |
Correct |
129 ms |
6928 KB |
Output is correct |
30 |
Correct |
60 ms |
5612 KB |
Output is correct |
31 |
Correct |
937 ms |
91284 KB |
Output is correct |
32 |
Correct |
1050 ms |
91612 KB |
Output is correct |
33 |
Correct |
1117 ms |
91372 KB |
Output is correct |
34 |
Correct |
193 ms |
13928 KB |
Output is correct |
35 |
Correct |
199 ms |
13688 KB |
Output is correct |
36 |
Correct |
87 ms |
6024 KB |
Output is correct |
37 |
Correct |
878 ms |
91328 KB |
Output is correct |
38 |
Correct |
961 ms |
91380 KB |
Output is correct |
39 |
Correct |
738 ms |
91484 KB |
Output is correct |
40 |
Correct |
128 ms |
7660 KB |
Output is correct |
41 |
Correct |
108 ms |
6892 KB |
Output is correct |
42 |
Correct |
60 ms |
5612 KB |
Output is correct |
43 |
Correct |
992 ms |
106588 KB |
Output is correct |
44 |
Correct |
1010 ms |
106544 KB |
Output is correct |
45 |
Correct |
1233 ms |
106560 KB |
Output is correct |
46 |
Correct |
218 ms |
15848 KB |
Output is correct |
47 |
Correct |
228 ms |
15912 KB |
Output is correct |
48 |
Correct |
80 ms |
5740 KB |
Output is correct |
49 |
Correct |
1018 ms |
106560 KB |
Output is correct |
50 |
Correct |
828 ms |
106464 KB |
Output is correct |
51 |
Correct |
810 ms |
106720 KB |
Output is correct |
52 |
Correct |
162 ms |
9200 KB |
Output is correct |
53 |
Correct |
129 ms |
8040 KB |
Output is correct |