#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_updat
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define int ll
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,
tree_order_statistics_node_update> ost;
#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()
class LazyTree{
//Here ↓
int N; vector<ost> st;
int gpt;
//Here ↓
void upd(int v, int l, int r, int L, int R, int d){
if(r < L or R < l) return;
// add d into sorted array
st[v].insert({d, gpt});
if(l == r) return;
int m = (l+r)/2, v1 = 2*v, v2 = v1+1;
upd(v1, l, m, L, R, d);
upd(v2, m+1, r, L, R, d);
return;
}
//↓ Here
int qry(int v, int l, int r, int L, int R, int d){
if(r < L or R < l) return 0;
if(L <= l and r <= R){
int cfvs = st[v].size() - st[v].order_of_key({d, 0});
return cfvs;
}
int m = (l+r)/2, v1 = 2*v, v2 = v1+1;
//Here ↓
return qry(v1, l, m, L, R, d)+qry(v2, m+1, r, L, R, d);
}
public:
LazyTree(int N){st.resize(4*N);this->N = N; gpt = 0;}
//Here ↓
void upd(int L, int R, int d){gpt++; return upd(1, 0, N, L, R, d);}
//↓ Here
int qry(int L, int R, int d){return qry(1, 0, N, L, R, d);}
};
struct node1{
int s, t;
};
struct node2{
int a, b, c, idx;
};
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, q; cin >> n >> q;
vector<node1> a(n);
for(auto &i : a) cin >> i.s >> i.t;
sort(all(a), [](auto a, auto b){return a.s+a.t>b.s+b.t;});
vector<node2> cpq(q);
for(int x = 0; x < q; x++){
cin >> cpq[x].a >> cpq[x].b >> cpq[x].c;
cpq[x].idx = x;
}
sort(all(cpq), [](auto z1, auto z2){return z1.c>z2.c;});
ost ccrow; int jvc = 1;
for(int x = 0; x < n; x++){
ccrow.insert({a[x].s, jvc++});
}
int jp = ccrow.size()+20;
LazyTree ST(jp);
vi sol(q); int stp = 0;
for(auto qq : cpq){
while(stp < n && a[stp].s+a[stp].t >= qq.c){
// insert into merge segtree
int xv = ccrow.order_of_key({a[stp].s, 0});
ST.upd(xv, xv, a[stp].t);
stp++;
}
int xv = ccrow.order_of_key({qq.a, 0});
sol[qq.idx] = ST.qry(xv, jp, qq.b);
}
for(auto i : sol) cout << i << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
23 ms |
4352 KB |
Output is correct |
8 |
Correct |
23 ms |
4352 KB |
Output is correct |
9 |
Correct |
22 ms |
4352 KB |
Output is correct |
10 |
Correct |
22 ms |
4352 KB |
Output is correct |
11 |
Correct |
25 ms |
4352 KB |
Output is correct |
12 |
Correct |
21 ms |
4224 KB |
Output is correct |
13 |
Correct |
22 ms |
4352 KB |
Output is correct |
14 |
Correct |
23 ms |
4472 KB |
Output is correct |
15 |
Correct |
23 ms |
4352 KB |
Output is correct |
16 |
Correct |
25 ms |
4352 KB |
Output is correct |
17 |
Correct |
21 ms |
4352 KB |
Output is correct |
18 |
Correct |
27 ms |
4344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2578 ms |
161176 KB |
Output is correct |
2 |
Correct |
2775 ms |
161024 KB |
Output is correct |
3 |
Correct |
2618 ms |
161016 KB |
Output is correct |
4 |
Correct |
1883 ms |
161176 KB |
Output is correct |
5 |
Correct |
1502 ms |
163152 KB |
Output is correct |
6 |
Correct |
1384 ms |
160248 KB |
Output is correct |
7 |
Correct |
2470 ms |
161272 KB |
Output is correct |
8 |
Correct |
2447 ms |
161144 KB |
Output is correct |
9 |
Correct |
2165 ms |
161276 KB |
Output is correct |
10 |
Correct |
1190 ms |
163064 KB |
Output is correct |
11 |
Correct |
1416 ms |
161012 KB |
Output is correct |
12 |
Correct |
1754 ms |
162836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2578 ms |
161176 KB |
Output is correct |
2 |
Correct |
2775 ms |
161024 KB |
Output is correct |
3 |
Correct |
2618 ms |
161016 KB |
Output is correct |
4 |
Correct |
1883 ms |
161176 KB |
Output is correct |
5 |
Correct |
1502 ms |
163152 KB |
Output is correct |
6 |
Correct |
1384 ms |
160248 KB |
Output is correct |
7 |
Correct |
2470 ms |
161272 KB |
Output is correct |
8 |
Correct |
2447 ms |
161144 KB |
Output is correct |
9 |
Correct |
2165 ms |
161276 KB |
Output is correct |
10 |
Correct |
1190 ms |
163064 KB |
Output is correct |
11 |
Correct |
1416 ms |
161012 KB |
Output is correct |
12 |
Correct |
1754 ms |
162836 KB |
Output is correct |
13 |
Correct |
2358 ms |
160984 KB |
Output is correct |
14 |
Correct |
2662 ms |
161112 KB |
Output is correct |
15 |
Correct |
2656 ms |
161148 KB |
Output is correct |
16 |
Correct |
1558 ms |
161004 KB |
Output is correct |
17 |
Correct |
1494 ms |
161352 KB |
Output is correct |
18 |
Correct |
1330 ms |
159112 KB |
Output is correct |
19 |
Correct |
2458 ms |
160948 KB |
Output is correct |
20 |
Correct |
2709 ms |
161400 KB |
Output is correct |
21 |
Correct |
2217 ms |
160988 KB |
Output is correct |
22 |
Correct |
1188 ms |
162856 KB |
Output is correct |
23 |
Correct |
1461 ms |
160832 KB |
Output is correct |
24 |
Correct |
1787 ms |
162680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
23 ms |
4352 KB |
Output is correct |
8 |
Correct |
23 ms |
4352 KB |
Output is correct |
9 |
Correct |
22 ms |
4352 KB |
Output is correct |
10 |
Correct |
22 ms |
4352 KB |
Output is correct |
11 |
Correct |
25 ms |
4352 KB |
Output is correct |
12 |
Correct |
21 ms |
4224 KB |
Output is correct |
13 |
Correct |
22 ms |
4352 KB |
Output is correct |
14 |
Correct |
23 ms |
4472 KB |
Output is correct |
15 |
Correct |
23 ms |
4352 KB |
Output is correct |
16 |
Correct |
25 ms |
4352 KB |
Output is correct |
17 |
Correct |
21 ms |
4352 KB |
Output is correct |
18 |
Correct |
27 ms |
4344 KB |
Output is correct |
19 |
Correct |
2578 ms |
161176 KB |
Output is correct |
20 |
Correct |
2775 ms |
161024 KB |
Output is correct |
21 |
Correct |
2618 ms |
161016 KB |
Output is correct |
22 |
Correct |
1883 ms |
161176 KB |
Output is correct |
23 |
Correct |
1502 ms |
163152 KB |
Output is correct |
24 |
Correct |
1384 ms |
160248 KB |
Output is correct |
25 |
Correct |
2470 ms |
161272 KB |
Output is correct |
26 |
Correct |
2447 ms |
161144 KB |
Output is correct |
27 |
Correct |
2165 ms |
161276 KB |
Output is correct |
28 |
Correct |
1190 ms |
163064 KB |
Output is correct |
29 |
Correct |
1416 ms |
161012 KB |
Output is correct |
30 |
Correct |
1754 ms |
162836 KB |
Output is correct |
31 |
Correct |
2358 ms |
160984 KB |
Output is correct |
32 |
Correct |
2662 ms |
161112 KB |
Output is correct |
33 |
Correct |
2656 ms |
161148 KB |
Output is correct |
34 |
Correct |
1558 ms |
161004 KB |
Output is correct |
35 |
Correct |
1494 ms |
161352 KB |
Output is correct |
36 |
Correct |
1330 ms |
159112 KB |
Output is correct |
37 |
Correct |
2458 ms |
160948 KB |
Output is correct |
38 |
Correct |
2709 ms |
161400 KB |
Output is correct |
39 |
Correct |
2217 ms |
160988 KB |
Output is correct |
40 |
Correct |
1188 ms |
162856 KB |
Output is correct |
41 |
Correct |
1461 ms |
160832 KB |
Output is correct |
42 |
Correct |
1787 ms |
162680 KB |
Output is correct |
43 |
Correct |
2545 ms |
166148 KB |
Output is correct |
44 |
Correct |
2356 ms |
165920 KB |
Output is correct |
45 |
Correct |
2584 ms |
165864 KB |
Output is correct |
46 |
Correct |
1638 ms |
164600 KB |
Output is correct |
47 |
Correct |
1495 ms |
165328 KB |
Output is correct |
48 |
Correct |
1267 ms |
162956 KB |
Output is correct |
49 |
Correct |
2492 ms |
166048 KB |
Output is correct |
50 |
Correct |
2236 ms |
165772 KB |
Output is correct |
51 |
Correct |
2128 ms |
165772 KB |
Output is correct |
52 |
Correct |
1852 ms |
166104 KB |
Output is correct |
53 |
Correct |
1473 ms |
163412 KB |
Output is correct |