#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()
#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, 0, z)
#define trav(x, y) for(auto&x:y)
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const char nl = '\n';
const int mxN = 1e5 + 10;
const int MOD = 1e9 + 7;
const long long infLL = 1e18;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
using node = ordered_set;
int n, ptr = 0, q, gl, ctr, ans[mxN]; ar<int, 3> v[mxN], w[mxN]; ar<int, 4> quer[mxN];
ordered_set st[mxN*4];
int qry(int l, int r, int lx = 0, int rx = n-1, int node = 0){
if(l <= lx && r >= rx){
// cout << gl << "{";
// trav(x, st[node]) cout << x.f << " ";
// cout << "}\n";
return siz(st[node]) - st[node].order_of_key({gl,-1});
}
if(lx > r || rx < l){
return 0;
}
int m = (lx + rx)/2;
return qry(l, r, lx, m, node*2+1) + qry(l, r, m+1, rx, node*2+2);
}
void update(int pos, int nxt, int lx = 0, int rx = n-1, int x = 0){
st[x].insert({nxt, ctr});
if(lx == rx) return;
int m = (lx + rx)/2;
if(pos <= m){
update(pos, nxt, lx, m, x*2+1);
}
else{
update(pos, nxt, m+1, rx, x*2+2);
}
}
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> q;
F0R(i, n){
cin >> v[i][0] >> v[i][1];
v[i][2] = v[i][0] + v[i][1];
w[i] = v[i];
}
sort(v, v+n);
sort(w, w+n, [](ar<int, 3> e1, ar<int, 3> e2){
return e1[1] > e2[1];
});
F0R(i, q){
cin >> quer[i][0] >> quer[i][1] >> quer[i][2];
quer[i][3] = i;
}
sort(quer, quer+q, [](ar<int, 4> e1, ar<int, 4> e2){
return e1[1] > e2[1];
});
F0R(i, q){
while(ptr < n && w[ptr][1] >= quer[i][1]){
int x = lower_bound(v, v+n,(ar<int,3>) {w[ptr][0], -1, -1}) - v;
// cout << w[ptr][2] << nl;
update(x, w[ptr][2]);
ctr++; ptr++;
}
gl = quer[i][2];
ans[quer[i][3]] = qry(lower_bound(v, v+n, (ar<int, 3>){quer[i][0], -1, -1}) - v, n-1);
// cout << ptr << " " << quer[i][2] << " " << quer[i][3] << " " << ans[quer[i][3]] << " " << lower_bound(v, v+n, (ar<int, 3>){quer[i][0], -1, -1}) - v << nl;
}
F0R(i, q){
cout << ans[i] << nl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
37884 KB |
Output is correct |
2 |
Correct |
38 ms |
37916 KB |
Output is correct |
3 |
Correct |
39 ms |
37880 KB |
Output is correct |
4 |
Correct |
38 ms |
37888 KB |
Output is correct |
5 |
Correct |
39 ms |
37888 KB |
Output is correct |
6 |
Correct |
44 ms |
38008 KB |
Output is correct |
7 |
Correct |
55 ms |
40440 KB |
Output is correct |
8 |
Correct |
55 ms |
40440 KB |
Output is correct |
9 |
Correct |
55 ms |
40568 KB |
Output is correct |
10 |
Correct |
54 ms |
40440 KB |
Output is correct |
11 |
Correct |
58 ms |
40440 KB |
Output is correct |
12 |
Correct |
53 ms |
40440 KB |
Output is correct |
13 |
Correct |
55 ms |
40440 KB |
Output is correct |
14 |
Correct |
56 ms |
40440 KB |
Output is correct |
15 |
Correct |
54 ms |
40440 KB |
Output is correct |
16 |
Correct |
57 ms |
40568 KB |
Output is correct |
17 |
Correct |
53 ms |
40440 KB |
Output is correct |
18 |
Correct |
56 ms |
40568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2267 ms |
153720 KB |
Output is correct |
2 |
Correct |
2246 ms |
156320 KB |
Output is correct |
3 |
Correct |
2242 ms |
156296 KB |
Output is correct |
4 |
Correct |
1625 ms |
155512 KB |
Output is correct |
5 |
Correct |
1264 ms |
155768 KB |
Output is correct |
6 |
Correct |
1196 ms |
155512 KB |
Output is correct |
7 |
Correct |
2213 ms |
156192 KB |
Output is correct |
8 |
Correct |
2354 ms |
156408 KB |
Output is correct |
9 |
Correct |
2157 ms |
156152 KB |
Output is correct |
10 |
Correct |
1146 ms |
157176 KB |
Output is correct |
11 |
Correct |
1513 ms |
155164 KB |
Output is correct |
12 |
Correct |
1839 ms |
156396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2267 ms |
153720 KB |
Output is correct |
2 |
Correct |
2246 ms |
156320 KB |
Output is correct |
3 |
Correct |
2242 ms |
156296 KB |
Output is correct |
4 |
Correct |
1625 ms |
155512 KB |
Output is correct |
5 |
Correct |
1264 ms |
155768 KB |
Output is correct |
6 |
Correct |
1196 ms |
155512 KB |
Output is correct |
7 |
Correct |
2213 ms |
156192 KB |
Output is correct |
8 |
Correct |
2354 ms |
156408 KB |
Output is correct |
9 |
Correct |
2157 ms |
156152 KB |
Output is correct |
10 |
Correct |
1146 ms |
157176 KB |
Output is correct |
11 |
Correct |
1513 ms |
155164 KB |
Output is correct |
12 |
Correct |
1839 ms |
156396 KB |
Output is correct |
13 |
Correct |
2397 ms |
156792 KB |
Output is correct |
14 |
Correct |
2353 ms |
156664 KB |
Output is correct |
15 |
Correct |
2283 ms |
156412 KB |
Output is correct |
16 |
Correct |
1685 ms |
155768 KB |
Output is correct |
17 |
Correct |
1439 ms |
155512 KB |
Output is correct |
18 |
Correct |
1216 ms |
154364 KB |
Output is correct |
19 |
Correct |
2417 ms |
156664 KB |
Output is correct |
20 |
Correct |
2388 ms |
156920 KB |
Output is correct |
21 |
Correct |
2512 ms |
156920 KB |
Output is correct |
22 |
Correct |
1139 ms |
157048 KB |
Output is correct |
23 |
Correct |
1490 ms |
155256 KB |
Output is correct |
24 |
Correct |
1845 ms |
156408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
37884 KB |
Output is correct |
2 |
Correct |
38 ms |
37916 KB |
Output is correct |
3 |
Correct |
39 ms |
37880 KB |
Output is correct |
4 |
Correct |
38 ms |
37888 KB |
Output is correct |
5 |
Correct |
39 ms |
37888 KB |
Output is correct |
6 |
Correct |
44 ms |
38008 KB |
Output is correct |
7 |
Correct |
55 ms |
40440 KB |
Output is correct |
8 |
Correct |
55 ms |
40440 KB |
Output is correct |
9 |
Correct |
55 ms |
40568 KB |
Output is correct |
10 |
Correct |
54 ms |
40440 KB |
Output is correct |
11 |
Correct |
58 ms |
40440 KB |
Output is correct |
12 |
Correct |
53 ms |
40440 KB |
Output is correct |
13 |
Correct |
55 ms |
40440 KB |
Output is correct |
14 |
Correct |
56 ms |
40440 KB |
Output is correct |
15 |
Correct |
54 ms |
40440 KB |
Output is correct |
16 |
Correct |
57 ms |
40568 KB |
Output is correct |
17 |
Correct |
53 ms |
40440 KB |
Output is correct |
18 |
Correct |
56 ms |
40568 KB |
Output is correct |
19 |
Correct |
2267 ms |
153720 KB |
Output is correct |
20 |
Correct |
2246 ms |
156320 KB |
Output is correct |
21 |
Correct |
2242 ms |
156296 KB |
Output is correct |
22 |
Correct |
1625 ms |
155512 KB |
Output is correct |
23 |
Correct |
1264 ms |
155768 KB |
Output is correct |
24 |
Correct |
1196 ms |
155512 KB |
Output is correct |
25 |
Correct |
2213 ms |
156192 KB |
Output is correct |
26 |
Correct |
2354 ms |
156408 KB |
Output is correct |
27 |
Correct |
2157 ms |
156152 KB |
Output is correct |
28 |
Correct |
1146 ms |
157176 KB |
Output is correct |
29 |
Correct |
1513 ms |
155164 KB |
Output is correct |
30 |
Correct |
1839 ms |
156396 KB |
Output is correct |
31 |
Correct |
2397 ms |
156792 KB |
Output is correct |
32 |
Correct |
2353 ms |
156664 KB |
Output is correct |
33 |
Correct |
2283 ms |
156412 KB |
Output is correct |
34 |
Correct |
1685 ms |
155768 KB |
Output is correct |
35 |
Correct |
1439 ms |
155512 KB |
Output is correct |
36 |
Correct |
1216 ms |
154364 KB |
Output is correct |
37 |
Correct |
2417 ms |
156664 KB |
Output is correct |
38 |
Correct |
2388 ms |
156920 KB |
Output is correct |
39 |
Correct |
2512 ms |
156920 KB |
Output is correct |
40 |
Correct |
1139 ms |
157048 KB |
Output is correct |
41 |
Correct |
1490 ms |
155256 KB |
Output is correct |
42 |
Correct |
1845 ms |
156408 KB |
Output is correct |
43 |
Correct |
2423 ms |
158668 KB |
Output is correct |
44 |
Correct |
2416 ms |
158712 KB |
Output is correct |
45 |
Correct |
2338 ms |
158628 KB |
Output is correct |
46 |
Correct |
1677 ms |
157176 KB |
Output is correct |
47 |
Correct |
1451 ms |
157304 KB |
Output is correct |
48 |
Correct |
1238 ms |
154872 KB |
Output is correct |
49 |
Correct |
2378 ms |
158296 KB |
Output is correct |
50 |
Correct |
2724 ms |
158424 KB |
Output is correct |
51 |
Correct |
2635 ms |
158396 KB |
Output is correct |
52 |
Correct |
1817 ms |
158712 KB |
Output is correct |
53 |
Correct |
1511 ms |
156024 KB |
Output is correct |