#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace __gnu_pbds;
using namespace std;
#define ordered_set tree< pair <int,int> , null_type, less_equal< pair <int,int> >, rb_tree_tag, tree_order_statistics_node_update>
const int N=2e5+5;
ordered_set t[N*4];
void update(int v,int tl,int tr,int ind,int val,int pos){
if(ind<tl or tr<ind)return;
if(tl==tr){
t[v].insert({val,pos});
}
else{
t[v].insert({val,pos});
int tm=(tl+tr)/2;
update(v*2,tl,tm,ind,val,pos);
update(v*2+1,tm+1,tr,ind,val,pos);
}
}
int get(int v,int tl,int tr,int l,int r,int val){
if(r<tl or tr<l)return 0;
if(l<=tl && tr<=r){
return t[v].size()-t[v].order_of_key({val,0});
}
int tm=(tl+tr)/2;
return get(v*2,tl,tm,l,r,val)+get(v*2+1,tm+1,tr,l,r,val);
}
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,q;
cin>>n>>q;
vector <pair <int,int> >v(n);
vector <int> uni;
for(int i=0;i<n;i++){
cin>>v[i].ff>>v[i].ss;
uni.pb(v[i].ss);
}
vector <vector <int> > qu;
for(int i=0;i<q;i++){
int x,y,z;
cin>>x>>y>>z;
qu.pb({x,y,z,i});
uni.pb(y);
}
sort(all(qu));reverse(all(qu));
sort(all(v));reverse(all(v));
sort(all(uni));
int cnt=0,p=-1;
map <int,int> val_ind;
for(int i=0;i<uni.size();i++){
if(uni[i]!=p){
cnt++;
val_ind[uni[i]]=cnt;
}
p=uni[i];
}
vector <int> ans(q);
int pos=0;
for(int i=0;i<q;i++){
while(pos<n && v[pos].ff>=qu[i][0]){
update(1,1,cnt,val_ind[v[pos].ss],v[pos].ff+v[pos].ss,pos);
pos++;
}
ans[qu[i][3]]=get(1,1,cnt,val_ind[qu[i][1]],cnt,qu[i][2]);
}
for(auto x : ans)cout<<x<<"\n";
}
/*
5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100
*/
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:57:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i=0;i<uni.size();i++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
75356 KB |
Output is correct |
2 |
Correct |
42 ms |
75344 KB |
Output is correct |
3 |
Correct |
42 ms |
75344 KB |
Output is correct |
4 |
Correct |
43 ms |
75344 KB |
Output is correct |
5 |
Correct |
43 ms |
75344 KB |
Output is correct |
6 |
Correct |
42 ms |
75344 KB |
Output is correct |
7 |
Correct |
58 ms |
78928 KB |
Output is correct |
8 |
Correct |
64 ms |
78936 KB |
Output is correct |
9 |
Correct |
59 ms |
78932 KB |
Output is correct |
10 |
Correct |
50 ms |
76668 KB |
Output is correct |
11 |
Correct |
56 ms |
78952 KB |
Output is correct |
12 |
Correct |
48 ms |
77044 KB |
Output is correct |
13 |
Correct |
60 ms |
78760 KB |
Output is correct |
14 |
Correct |
58 ms |
78732 KB |
Output is correct |
15 |
Correct |
58 ms |
78928 KB |
Output is correct |
16 |
Correct |
53 ms |
78812 KB |
Output is correct |
17 |
Correct |
50 ms |
76368 KB |
Output is correct |
18 |
Correct |
47 ms |
76348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1738 ms |
205132 KB |
Output is correct |
2 |
Correct |
1727 ms |
204848 KB |
Output is correct |
3 |
Correct |
1763 ms |
204560 KB |
Output is correct |
4 |
Correct |
352 ms |
117188 KB |
Output is correct |
5 |
Correct |
942 ms |
203652 KB |
Output is correct |
6 |
Correct |
294 ms |
116444 KB |
Output is correct |
7 |
Correct |
1789 ms |
204400 KB |
Output is correct |
8 |
Correct |
1640 ms |
200388 KB |
Output is correct |
9 |
Correct |
1565 ms |
200452 KB |
Output is correct |
10 |
Correct |
722 ms |
204152 KB |
Output is correct |
11 |
Correct |
205 ms |
101312 KB |
Output is correct |
12 |
Correct |
307 ms |
107052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1738 ms |
205132 KB |
Output is correct |
2 |
Correct |
1727 ms |
204848 KB |
Output is correct |
3 |
Correct |
1763 ms |
204560 KB |
Output is correct |
4 |
Correct |
352 ms |
117188 KB |
Output is correct |
5 |
Correct |
942 ms |
203652 KB |
Output is correct |
6 |
Correct |
294 ms |
116444 KB |
Output is correct |
7 |
Correct |
1789 ms |
204400 KB |
Output is correct |
8 |
Correct |
1640 ms |
200388 KB |
Output is correct |
9 |
Correct |
1565 ms |
200452 KB |
Output is correct |
10 |
Correct |
722 ms |
204152 KB |
Output is correct |
11 |
Correct |
205 ms |
101312 KB |
Output is correct |
12 |
Correct |
307 ms |
107052 KB |
Output is correct |
13 |
Correct |
1865 ms |
205340 KB |
Output is correct |
14 |
Correct |
1838 ms |
205492 KB |
Output is correct |
15 |
Correct |
1707 ms |
204372 KB |
Output is correct |
16 |
Correct |
400 ms |
117952 KB |
Output is correct |
17 |
Correct |
976 ms |
204652 KB |
Output is correct |
18 |
Correct |
288 ms |
116648 KB |
Output is correct |
19 |
Correct |
1916 ms |
204756 KB |
Output is correct |
20 |
Correct |
1864 ms |
205372 KB |
Output is correct |
21 |
Correct |
1949 ms |
203432 KB |
Output is correct |
22 |
Correct |
706 ms |
203712 KB |
Output is correct |
23 |
Correct |
211 ms |
101548 KB |
Output is correct |
24 |
Correct |
299 ms |
106428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
75356 KB |
Output is correct |
2 |
Correct |
42 ms |
75344 KB |
Output is correct |
3 |
Correct |
42 ms |
75344 KB |
Output is correct |
4 |
Correct |
43 ms |
75344 KB |
Output is correct |
5 |
Correct |
43 ms |
75344 KB |
Output is correct |
6 |
Correct |
42 ms |
75344 KB |
Output is correct |
7 |
Correct |
58 ms |
78928 KB |
Output is correct |
8 |
Correct |
64 ms |
78936 KB |
Output is correct |
9 |
Correct |
59 ms |
78932 KB |
Output is correct |
10 |
Correct |
50 ms |
76668 KB |
Output is correct |
11 |
Correct |
56 ms |
78952 KB |
Output is correct |
12 |
Correct |
48 ms |
77044 KB |
Output is correct |
13 |
Correct |
60 ms |
78760 KB |
Output is correct |
14 |
Correct |
58 ms |
78732 KB |
Output is correct |
15 |
Correct |
58 ms |
78928 KB |
Output is correct |
16 |
Correct |
53 ms |
78812 KB |
Output is correct |
17 |
Correct |
50 ms |
76368 KB |
Output is correct |
18 |
Correct |
47 ms |
76348 KB |
Output is correct |
19 |
Correct |
1738 ms |
205132 KB |
Output is correct |
20 |
Correct |
1727 ms |
204848 KB |
Output is correct |
21 |
Correct |
1763 ms |
204560 KB |
Output is correct |
22 |
Correct |
352 ms |
117188 KB |
Output is correct |
23 |
Correct |
942 ms |
203652 KB |
Output is correct |
24 |
Correct |
294 ms |
116444 KB |
Output is correct |
25 |
Correct |
1789 ms |
204400 KB |
Output is correct |
26 |
Correct |
1640 ms |
200388 KB |
Output is correct |
27 |
Correct |
1565 ms |
200452 KB |
Output is correct |
28 |
Correct |
722 ms |
204152 KB |
Output is correct |
29 |
Correct |
205 ms |
101312 KB |
Output is correct |
30 |
Correct |
307 ms |
107052 KB |
Output is correct |
31 |
Correct |
1865 ms |
205340 KB |
Output is correct |
32 |
Correct |
1838 ms |
205492 KB |
Output is correct |
33 |
Correct |
1707 ms |
204372 KB |
Output is correct |
34 |
Correct |
400 ms |
117952 KB |
Output is correct |
35 |
Correct |
976 ms |
204652 KB |
Output is correct |
36 |
Correct |
288 ms |
116648 KB |
Output is correct |
37 |
Correct |
1916 ms |
204756 KB |
Output is correct |
38 |
Correct |
1864 ms |
205372 KB |
Output is correct |
39 |
Correct |
1949 ms |
203432 KB |
Output is correct |
40 |
Correct |
706 ms |
203712 KB |
Output is correct |
41 |
Correct |
211 ms |
101548 KB |
Output is correct |
42 |
Correct |
299 ms |
106428 KB |
Output is correct |
43 |
Correct |
2033 ms |
221828 KB |
Output is correct |
44 |
Correct |
2059 ms |
221780 KB |
Output is correct |
45 |
Correct |
1996 ms |
221828 KB |
Output is correct |
46 |
Correct |
437 ms |
118936 KB |
Output is correct |
47 |
Correct |
1140 ms |
220144 KB |
Output is correct |
48 |
Correct |
317 ms |
116664 KB |
Output is correct |
49 |
Correct |
2419 ms |
221752 KB |
Output is correct |
50 |
Correct |
2225 ms |
221224 KB |
Output is correct |
51 |
Correct |
2271 ms |
221220 KB |
Output is correct |
52 |
Correct |
891 ms |
219844 KB |
Output is correct |
53 |
Correct |
308 ms |
102040 KB |
Output is correct |