#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define em emplace
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const int MAX = 101010;
const int INF = (1 << 30) - 1;
const ll LINF = 1LL << 60;
int ans[MAX], n, q;
pii arr[MAX];
vector <int> S, T[MAX], tree[MAX];
struct Query {
int a, b, c, idx;
} query[MAX];
void update(int x, int y, int val) {
x = upper_bound(all(S), x) - S.begin();
while(x <= n) {
int temp = upper_bound(all(T[x]), y) - T[x].begin();
while(temp <= T[x].size()) {
tree[x][temp] += val;
temp += (temp & -temp);
}
x += (x & -x);
}
}
int cal(int x, int y) {
x = upper_bound(all(S), x) - S.begin();
int ret = 0;
while(x > 0) {
int temp = upper_bound(all(T[x]), y) - T[x].begin();
while(temp > 0) {
ret += tree[x][temp];
temp -= (temp & -temp);
}
x -= (x & -x);
}
return ret;
}
int main () {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> q;
for(int i = 1; i <= n; i++) {
cin >> arr[i].fi >> arr[i].se;
S.eb(arr[i].fi);
}
sort(all(S));
for(int i = 1; i <= n; i++) {
int temp = upper_bound(all(S), arr[i].fi) - S.begin();
while(temp <= n) {
T[temp].eb(arr[i].se);
temp += (temp & -temp);
}
}
for(int i = 1; i <= n; i++) {
tree[i].resize(T[i].size()+10);
sort(all(T[i]));
}
sort(arr+1, arr+n+1, [](pii a, pii b) {
return a.fi + a.se > b.fi + b.se;
});
for(int i = 1; i <= q; i++) {
cin >> query[i].a >> query[i].b >> query[i].c;
query[i].idx = i;
}
sort(query+1, query+q+1, [](Query X, Query Y) {
return X.c > Y.c;
});
int idx = 1;
for(int i = 1; i <= q; i++) {
while(idx <= n && arr[idx].fi + arr[idx].se >= query[i].c) {
update(arr[idx].fi, arr[idx].se, 1);
idx++;
}
ans[query[i].idx] = cal(1000000000, 1000000000) - cal(1000000000, query[i].b-1) - cal(query[i].a-1, 1000000000) + cal(query[i].a-1, query[i].b-1);
}
for(int i = 1; i <= q; i++) {
cout << ans[i] << '\n';
}
}
Compilation message
examination.cpp: In function 'void update(int, int, int)':
examination.cpp:28:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(temp <= T[x].size()) {
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
Output is correct |
2 |
Correct |
6 ms |
5112 KB |
Output is correct |
3 |
Correct |
6 ms |
5112 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
5112 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
16 ms |
5752 KB |
Output is correct |
8 |
Correct |
16 ms |
5752 KB |
Output is correct |
9 |
Correct |
16 ms |
5752 KB |
Output is correct |
10 |
Correct |
14 ms |
5624 KB |
Output is correct |
11 |
Correct |
14 ms |
5652 KB |
Output is correct |
12 |
Correct |
13 ms |
5500 KB |
Output is correct |
13 |
Correct |
16 ms |
5752 KB |
Output is correct |
14 |
Correct |
16 ms |
5752 KB |
Output is correct |
15 |
Correct |
17 ms |
5752 KB |
Output is correct |
16 |
Correct |
10 ms |
5496 KB |
Output is correct |
17 |
Correct |
13 ms |
5752 KB |
Output is correct |
18 |
Correct |
9 ms |
5500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
641 ms |
23360 KB |
Output is correct |
2 |
Correct |
640 ms |
25904 KB |
Output is correct |
3 |
Correct |
641 ms |
25820 KB |
Output is correct |
4 |
Correct |
544 ms |
25052 KB |
Output is correct |
5 |
Correct |
367 ms |
23152 KB |
Output is correct |
6 |
Correct |
228 ms |
22388 KB |
Output is correct |
7 |
Correct |
549 ms |
25644 KB |
Output is correct |
8 |
Correct |
594 ms |
25716 KB |
Output is correct |
9 |
Correct |
562 ms |
25476 KB |
Output is correct |
10 |
Correct |
150 ms |
15832 KB |
Output is correct |
11 |
Correct |
369 ms |
24788 KB |
Output is correct |
12 |
Correct |
108 ms |
14964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
641 ms |
23360 KB |
Output is correct |
2 |
Correct |
640 ms |
25904 KB |
Output is correct |
3 |
Correct |
641 ms |
25820 KB |
Output is correct |
4 |
Correct |
544 ms |
25052 KB |
Output is correct |
5 |
Correct |
367 ms |
23152 KB |
Output is correct |
6 |
Correct |
228 ms |
22388 KB |
Output is correct |
7 |
Correct |
549 ms |
25644 KB |
Output is correct |
8 |
Correct |
594 ms |
25716 KB |
Output is correct |
9 |
Correct |
562 ms |
25476 KB |
Output is correct |
10 |
Correct |
150 ms |
15832 KB |
Output is correct |
11 |
Correct |
369 ms |
24788 KB |
Output is correct |
12 |
Correct |
108 ms |
14964 KB |
Output is correct |
13 |
Correct |
684 ms |
26168 KB |
Output is correct |
14 |
Correct |
665 ms |
26100 KB |
Output is correct |
15 |
Correct |
653 ms |
25844 KB |
Output is correct |
16 |
Correct |
511 ms |
25388 KB |
Output is correct |
17 |
Correct |
390 ms |
22644 KB |
Output is correct |
18 |
Correct |
238 ms |
22060 KB |
Output is correct |
19 |
Correct |
727 ms |
26228 KB |
Output is correct |
20 |
Correct |
682 ms |
26100 KB |
Output is correct |
21 |
Correct |
655 ms |
26068 KB |
Output is correct |
22 |
Correct |
152 ms |
15868 KB |
Output is correct |
23 |
Correct |
368 ms |
24676 KB |
Output is correct |
24 |
Correct |
108 ms |
15100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
Output is correct |
2 |
Correct |
6 ms |
5112 KB |
Output is correct |
3 |
Correct |
6 ms |
5112 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
5112 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
16 ms |
5752 KB |
Output is correct |
8 |
Correct |
16 ms |
5752 KB |
Output is correct |
9 |
Correct |
16 ms |
5752 KB |
Output is correct |
10 |
Correct |
14 ms |
5624 KB |
Output is correct |
11 |
Correct |
14 ms |
5652 KB |
Output is correct |
12 |
Correct |
13 ms |
5500 KB |
Output is correct |
13 |
Correct |
16 ms |
5752 KB |
Output is correct |
14 |
Correct |
16 ms |
5752 KB |
Output is correct |
15 |
Correct |
17 ms |
5752 KB |
Output is correct |
16 |
Correct |
10 ms |
5496 KB |
Output is correct |
17 |
Correct |
13 ms |
5752 KB |
Output is correct |
18 |
Correct |
9 ms |
5500 KB |
Output is correct |
19 |
Correct |
641 ms |
23360 KB |
Output is correct |
20 |
Correct |
640 ms |
25904 KB |
Output is correct |
21 |
Correct |
641 ms |
25820 KB |
Output is correct |
22 |
Correct |
544 ms |
25052 KB |
Output is correct |
23 |
Correct |
367 ms |
23152 KB |
Output is correct |
24 |
Correct |
228 ms |
22388 KB |
Output is correct |
25 |
Correct |
549 ms |
25644 KB |
Output is correct |
26 |
Correct |
594 ms |
25716 KB |
Output is correct |
27 |
Correct |
562 ms |
25476 KB |
Output is correct |
28 |
Correct |
150 ms |
15832 KB |
Output is correct |
29 |
Correct |
369 ms |
24788 KB |
Output is correct |
30 |
Correct |
108 ms |
14964 KB |
Output is correct |
31 |
Correct |
684 ms |
26168 KB |
Output is correct |
32 |
Correct |
665 ms |
26100 KB |
Output is correct |
33 |
Correct |
653 ms |
25844 KB |
Output is correct |
34 |
Correct |
511 ms |
25388 KB |
Output is correct |
35 |
Correct |
390 ms |
22644 KB |
Output is correct |
36 |
Correct |
238 ms |
22060 KB |
Output is correct |
37 |
Correct |
727 ms |
26228 KB |
Output is correct |
38 |
Correct |
682 ms |
26100 KB |
Output is correct |
39 |
Correct |
655 ms |
26068 KB |
Output is correct |
40 |
Correct |
152 ms |
15868 KB |
Output is correct |
41 |
Correct |
368 ms |
24676 KB |
Output is correct |
42 |
Correct |
108 ms |
15100 KB |
Output is correct |
43 |
Correct |
676 ms |
28416 KB |
Output is correct |
44 |
Correct |
691 ms |
28580 KB |
Output is correct |
45 |
Correct |
665 ms |
28404 KB |
Output is correct |
46 |
Correct |
512 ms |
26996 KB |
Output is correct |
47 |
Correct |
395 ms |
24132 KB |
Output is correct |
48 |
Correct |
233 ms |
22048 KB |
Output is correct |
49 |
Correct |
588 ms |
28528 KB |
Output is correct |
50 |
Correct |
638 ms |
28320 KB |
Output is correct |
51 |
Correct |
538 ms |
28148 KB |
Output is correct |
52 |
Correct |
177 ms |
17460 KB |
Output is correct |
53 |
Correct |
364 ms |
26024 KB |
Output is correct |