#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,e) for (int i = s; i <= e; ++i)
#define rrep(i,s,e) for (int i = s; i >= e; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define aint(a) a.begin(), a.end()
#define len(a) (int)a.size()
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<int> vint;
unordered_map<int,int> seg_tree[2] = {};
unordered_map<int,int> lazy[2] = {};
void upd (int tp, int val, int l, int r, int bl, int br, int id) {
seg_tree[tp][id] += val;
if (l==bl && r==br) {
lazy[tp][id] += val;
return;
}
int mid = (bl+br)/2;
if (r<=mid) upd (tp, val, l, r, bl, mid, 2*id);
else if (l>mid) upd (tp, val, l, r, mid+1, br, 2*id+1);
else {
upd (tp, val, l, mid, bl, mid, 2*id);
upd (tp, val, mid+1, r, mid+1, br, 2*id+1);
}
}
int query (int tp, int l, int r, int bl, int br, int id) {
if (l==bl && r==br) return seg_tree[tp][id];
if (bl!=br) {
lazy[tp][2*id] += lazy[tp][id];
lazy[tp][2*id+1] += lazy[tp][id];
seg_tree[tp][2*id] += lazy[tp][id];
seg_tree[tp][2*id+1] += lazy[tp][id];
lazy[tp][id] = 0;
}
int mid = (bl+br)/2;
if (r<=mid) return query (tp, l, r, bl, mid, 2*id);
if (l>mid) return query (tp, l, r, mid+1, br, 2*id+1);
return query (tp, l, mid, bl, mid, 2*id) + query (tp, mid+1, r, mid+1, br, 2*id+1);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, q, x = 0; cin >> n >> q;
vector<pair<int,ii>> peep;
vector<pair<ii,ii>> ques;
int ans[q+1];
rep (i,1,n) {
int a, b; cin >> a >> b;
peep.pb({a+b,{a,b}});
}
rep (i,1,q) {
int a, b, c; cin >> a >> b >> c;
ques.pb({{max(a+b,c),i},{a,b}});
}
sort(aint(ques));
reverse(aint(ques));
sort(aint(peep));
reverse(aint(peep));
rep (i,0,q-1) {
int c = ques[i].fi.fi, a = ques[i].se.fi, b = ques[i].se.se, u = ques[i].fi.se;
while (x < n && peep[x].fi>=c) {
upd (0, 1, peep[x].se.fi, peep[x].se.fi, 0, 1e9, 1);
upd (1, 1, peep[x].se.se, peep[x].se.se, 0, 1e9, 1);
x++;
}
ans[u] = query(0,a,1e9,0,1e9,1) + query(1,b,1e9,0,1e9,1) - x;
}
rep (i,1,q) cout << ans[i] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
170 ms |
22348 KB |
Output is correct |
8 |
Correct |
169 ms |
22380 KB |
Output is correct |
9 |
Correct |
147 ms |
22252 KB |
Output is correct |
10 |
Correct |
80 ms |
11312 KB |
Output is correct |
11 |
Correct |
100 ms |
11316 KB |
Output is correct |
12 |
Correct |
47 ms |
480 KB |
Output is correct |
13 |
Correct |
145 ms |
22280 KB |
Output is correct |
14 |
Correct |
148 ms |
22416 KB |
Output is correct |
15 |
Correct |
151 ms |
22244 KB |
Output is correct |
16 |
Correct |
83 ms |
11408 KB |
Output is correct |
17 |
Correct |
86 ms |
11340 KB |
Output is correct |
18 |
Correct |
32 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1834 ms |
38260 KB |
Output is correct |
2 |
Correct |
1763 ms |
38116 KB |
Output is correct |
3 |
Correct |
1822 ms |
38288 KB |
Output is correct |
4 |
Correct |
1196 ms |
21360 KB |
Output is correct |
5 |
Correct |
1204 ms |
21268 KB |
Output is correct |
6 |
Correct |
1389 ms |
4980 KB |
Output is correct |
7 |
Correct |
1596 ms |
30828 KB |
Output is correct |
8 |
Correct |
1769 ms |
30992 KB |
Output is correct |
9 |
Correct |
1551 ms |
22996 KB |
Output is correct |
10 |
Correct |
919 ms |
21112 KB |
Output is correct |
11 |
Correct |
975 ms |
21144 KB |
Output is correct |
12 |
Correct |
1157 ms |
4936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1834 ms |
38260 KB |
Output is correct |
2 |
Correct |
1763 ms |
38116 KB |
Output is correct |
3 |
Correct |
1822 ms |
38288 KB |
Output is correct |
4 |
Correct |
1196 ms |
21360 KB |
Output is correct |
5 |
Correct |
1204 ms |
21268 KB |
Output is correct |
6 |
Correct |
1389 ms |
4980 KB |
Output is correct |
7 |
Correct |
1596 ms |
30828 KB |
Output is correct |
8 |
Correct |
1769 ms |
30992 KB |
Output is correct |
9 |
Correct |
1551 ms |
22996 KB |
Output is correct |
10 |
Correct |
919 ms |
21112 KB |
Output is correct |
11 |
Correct |
975 ms |
21144 KB |
Output is correct |
12 |
Correct |
1157 ms |
4936 KB |
Output is correct |
13 |
Correct |
1779 ms |
38904 KB |
Output is correct |
14 |
Correct |
1958 ms |
38184 KB |
Output is correct |
15 |
Correct |
1874 ms |
38236 KB |
Output is correct |
16 |
Correct |
1377 ms |
21164 KB |
Output is correct |
17 |
Correct |
1315 ms |
21096 KB |
Output is correct |
18 |
Correct |
1413 ms |
4984 KB |
Output is correct |
19 |
Correct |
1769 ms |
38292 KB |
Output is correct |
20 |
Correct |
1824 ms |
38324 KB |
Output is correct |
21 |
Correct |
1926 ms |
31800 KB |
Output is correct |
22 |
Correct |
869 ms |
21252 KB |
Output is correct |
23 |
Correct |
864 ms |
21208 KB |
Output is correct |
24 |
Correct |
1106 ms |
4964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
170 ms |
22348 KB |
Output is correct |
8 |
Correct |
169 ms |
22380 KB |
Output is correct |
9 |
Correct |
147 ms |
22252 KB |
Output is correct |
10 |
Correct |
80 ms |
11312 KB |
Output is correct |
11 |
Correct |
100 ms |
11316 KB |
Output is correct |
12 |
Correct |
47 ms |
480 KB |
Output is correct |
13 |
Correct |
145 ms |
22280 KB |
Output is correct |
14 |
Correct |
148 ms |
22416 KB |
Output is correct |
15 |
Correct |
151 ms |
22244 KB |
Output is correct |
16 |
Correct |
83 ms |
11408 KB |
Output is correct |
17 |
Correct |
86 ms |
11340 KB |
Output is correct |
18 |
Correct |
32 ms |
500 KB |
Output is correct |
19 |
Correct |
1834 ms |
38260 KB |
Output is correct |
20 |
Correct |
1763 ms |
38116 KB |
Output is correct |
21 |
Correct |
1822 ms |
38288 KB |
Output is correct |
22 |
Correct |
1196 ms |
21360 KB |
Output is correct |
23 |
Correct |
1204 ms |
21268 KB |
Output is correct |
24 |
Correct |
1389 ms |
4980 KB |
Output is correct |
25 |
Correct |
1596 ms |
30828 KB |
Output is correct |
26 |
Correct |
1769 ms |
30992 KB |
Output is correct |
27 |
Correct |
1551 ms |
22996 KB |
Output is correct |
28 |
Correct |
919 ms |
21112 KB |
Output is correct |
29 |
Correct |
975 ms |
21144 KB |
Output is correct |
30 |
Correct |
1157 ms |
4936 KB |
Output is correct |
31 |
Correct |
1779 ms |
38904 KB |
Output is correct |
32 |
Correct |
1958 ms |
38184 KB |
Output is correct |
33 |
Correct |
1874 ms |
38236 KB |
Output is correct |
34 |
Correct |
1377 ms |
21164 KB |
Output is correct |
35 |
Correct |
1315 ms |
21096 KB |
Output is correct |
36 |
Correct |
1413 ms |
4984 KB |
Output is correct |
37 |
Correct |
1769 ms |
38292 KB |
Output is correct |
38 |
Correct |
1824 ms |
38324 KB |
Output is correct |
39 |
Correct |
1926 ms |
31800 KB |
Output is correct |
40 |
Correct |
869 ms |
21252 KB |
Output is correct |
41 |
Correct |
864 ms |
21208 KB |
Output is correct |
42 |
Correct |
1106 ms |
4964 KB |
Output is correct |
43 |
Execution timed out |
3081 ms |
307172 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |