#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll int
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define maxn 400005
struct tupl{
ll x,y,sum,id;
} v[maxn];
ll n,q;
pll a[maxn];
ordered_set t[4*maxn];
ll ls[4*maxn],rs[4*maxn],root,tsz;
void upd(ll v,ll tl,ll tr,ll i,ll x,bool f){
if(f) t[v].insert(x);
if(tl==tr) return;
ll mid = (tl+tr)/2;
if(i<=mid) upd(ls[v],tl,mid,i,x,f);
else upd(rs[v],mid+1,tr,i,x,f);
}
ll get(ll v,ll tl,ll tr,ll l,ll r,ll x){
if(r<tl||l>tr||tl>tr) return 0;
if(l<=tl&&tr<=r){
ll cnt = t[v].order_of_key(x);
return sz(t[v]) - cnt;
}
ll mid = (tl+tr)/2;
return get(ls[v],tl,mid,l,r,x) + get(rs[v],mid+1,tr,l,r,x);
}
void init(ll &v,ll tl,ll tr){
v = ++tsz;
if(tl==tr) return;
ll mid = (tl+tr)/2;
init(ls[v],tl,mid);
init(rs[v],mid+1,tr);
}
bool cmp(pll x,pll y){return x.fi+x.sc<y.fi+y.sc;}
bool cmp2(tupl x,tupl y){return x.sum<y.sum;}
map<ll,ll> mp;
set<ll> s;
ll it = 0;
ll ans[maxn];
void tc(){
cin >> n >> q;
for(ll i = 1;i<=n;i++) cin >> a[i].fi >> a[i].sc;
for(ll i = 1;i<=q;i++) cin >> v[i].x >> v[i].y >> v[i].sum;
for(ll i = 1;i<=q;i++) v[i].id = i;
sort(a+1,a+1+n,cmp);
sort(v+1,v+1+q,cmp2);
for(ll i = 1;i<=n;i++) s.insert(a[i].fi),s.insert(a[i].sc);
for(ll i = 1;i<=q;i++) s.insert(v[i].x),s.insert(v[i].y);
for(ll x : s) mp[x] = ++it;
init(root,1,it);
ll k = n;
for(ll j = q;j>=1;j--){
while(k>=1&&a[k].fi+a[k].sc>=v[j].sum){
upd(root,1,it,mp[a[k].fi],mp[a[k].sc],1);
k--;
}
ans[v[j].id] = get(root,1,it,mp[v[j].x],it,mp[v[j].y]);
}
for(ll i = 1;i<=q;i++) cout<<ans[i]<<endl;
}
int main(){
daj_mi_malo_vremena
int t; t = 1;
while(t--){
tc();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
125484 KB |
Output is correct |
2 |
Correct |
92 ms |
125544 KB |
Output is correct |
3 |
Correct |
93 ms |
125492 KB |
Output is correct |
4 |
Correct |
96 ms |
125668 KB |
Output is correct |
5 |
Correct |
94 ms |
125588 KB |
Output is correct |
6 |
Correct |
94 ms |
125516 KB |
Output is correct |
7 |
Correct |
111 ms |
128972 KB |
Output is correct |
8 |
Correct |
112 ms |
129032 KB |
Output is correct |
9 |
Correct |
120 ms |
129004 KB |
Output is correct |
10 |
Correct |
110 ms |
128260 KB |
Output is correct |
11 |
Correct |
114 ms |
128280 KB |
Output is correct |
12 |
Correct |
100 ms |
126280 KB |
Output is correct |
13 |
Correct |
110 ms |
128968 KB |
Output is correct |
14 |
Correct |
110 ms |
129016 KB |
Output is correct |
15 |
Correct |
111 ms |
129064 KB |
Output is correct |
16 |
Correct |
107 ms |
128212 KB |
Output is correct |
17 |
Correct |
105 ms |
128168 KB |
Output is correct |
18 |
Correct |
95 ms |
126028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1932 ms |
222644 KB |
Output is correct |
2 |
Correct |
1942 ms |
222756 KB |
Output is correct |
3 |
Correct |
1921 ms |
222588 KB |
Output is correct |
4 |
Correct |
1211 ms |
220488 KB |
Output is correct |
5 |
Correct |
1039 ms |
220644 KB |
Output is correct |
6 |
Correct |
355 ms |
150320 KB |
Output is correct |
7 |
Correct |
1850 ms |
222172 KB |
Output is correct |
8 |
Correct |
1845 ms |
222424 KB |
Output is correct |
9 |
Correct |
1432 ms |
220740 KB |
Output is correct |
10 |
Correct |
878 ms |
222768 KB |
Output is correct |
11 |
Correct |
965 ms |
220328 KB |
Output is correct |
12 |
Correct |
275 ms |
142760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1932 ms |
222644 KB |
Output is correct |
2 |
Correct |
1942 ms |
222756 KB |
Output is correct |
3 |
Correct |
1921 ms |
222588 KB |
Output is correct |
4 |
Correct |
1211 ms |
220488 KB |
Output is correct |
5 |
Correct |
1039 ms |
220644 KB |
Output is correct |
6 |
Correct |
355 ms |
150320 KB |
Output is correct |
7 |
Correct |
1850 ms |
222172 KB |
Output is correct |
8 |
Correct |
1845 ms |
222424 KB |
Output is correct |
9 |
Correct |
1432 ms |
220740 KB |
Output is correct |
10 |
Correct |
878 ms |
222768 KB |
Output is correct |
11 |
Correct |
965 ms |
220328 KB |
Output is correct |
12 |
Correct |
275 ms |
142760 KB |
Output is correct |
13 |
Correct |
1795 ms |
222640 KB |
Output is correct |
14 |
Correct |
1960 ms |
222800 KB |
Output is correct |
15 |
Correct |
1932 ms |
222500 KB |
Output is correct |
16 |
Correct |
1060 ms |
220428 KB |
Output is correct |
17 |
Correct |
1038 ms |
220712 KB |
Output is correct |
18 |
Correct |
378 ms |
150312 KB |
Output is correct |
19 |
Correct |
1789 ms |
222708 KB |
Output is correct |
20 |
Correct |
1874 ms |
222572 KB |
Output is correct |
21 |
Correct |
1571 ms |
221804 KB |
Output is correct |
22 |
Correct |
894 ms |
222684 KB |
Output is correct |
23 |
Correct |
961 ms |
220348 KB |
Output is correct |
24 |
Correct |
283 ms |
142628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
125484 KB |
Output is correct |
2 |
Correct |
92 ms |
125544 KB |
Output is correct |
3 |
Correct |
93 ms |
125492 KB |
Output is correct |
4 |
Correct |
96 ms |
125668 KB |
Output is correct |
5 |
Correct |
94 ms |
125588 KB |
Output is correct |
6 |
Correct |
94 ms |
125516 KB |
Output is correct |
7 |
Correct |
111 ms |
128972 KB |
Output is correct |
8 |
Correct |
112 ms |
129032 KB |
Output is correct |
9 |
Correct |
120 ms |
129004 KB |
Output is correct |
10 |
Correct |
110 ms |
128260 KB |
Output is correct |
11 |
Correct |
114 ms |
128280 KB |
Output is correct |
12 |
Correct |
100 ms |
126280 KB |
Output is correct |
13 |
Correct |
110 ms |
128968 KB |
Output is correct |
14 |
Correct |
110 ms |
129016 KB |
Output is correct |
15 |
Correct |
111 ms |
129064 KB |
Output is correct |
16 |
Correct |
107 ms |
128212 KB |
Output is correct |
17 |
Correct |
105 ms |
128168 KB |
Output is correct |
18 |
Correct |
95 ms |
126028 KB |
Output is correct |
19 |
Correct |
1932 ms |
222644 KB |
Output is correct |
20 |
Correct |
1942 ms |
222756 KB |
Output is correct |
21 |
Correct |
1921 ms |
222588 KB |
Output is correct |
22 |
Correct |
1211 ms |
220488 KB |
Output is correct |
23 |
Correct |
1039 ms |
220644 KB |
Output is correct |
24 |
Correct |
355 ms |
150320 KB |
Output is correct |
25 |
Correct |
1850 ms |
222172 KB |
Output is correct |
26 |
Correct |
1845 ms |
222424 KB |
Output is correct |
27 |
Correct |
1432 ms |
220740 KB |
Output is correct |
28 |
Correct |
878 ms |
222768 KB |
Output is correct |
29 |
Correct |
965 ms |
220328 KB |
Output is correct |
30 |
Correct |
275 ms |
142760 KB |
Output is correct |
31 |
Correct |
1795 ms |
222640 KB |
Output is correct |
32 |
Correct |
1960 ms |
222800 KB |
Output is correct |
33 |
Correct |
1932 ms |
222500 KB |
Output is correct |
34 |
Correct |
1060 ms |
220428 KB |
Output is correct |
35 |
Correct |
1038 ms |
220712 KB |
Output is correct |
36 |
Correct |
378 ms |
150312 KB |
Output is correct |
37 |
Correct |
1789 ms |
222708 KB |
Output is correct |
38 |
Correct |
1874 ms |
222572 KB |
Output is correct |
39 |
Correct |
1571 ms |
221804 KB |
Output is correct |
40 |
Correct |
894 ms |
222684 KB |
Output is correct |
41 |
Correct |
961 ms |
220348 KB |
Output is correct |
42 |
Correct |
283 ms |
142628 KB |
Output is correct |
43 |
Correct |
2279 ms |
265136 KB |
Output is correct |
44 |
Correct |
2368 ms |
270176 KB |
Output is correct |
45 |
Correct |
2530 ms |
269936 KB |
Output is correct |
46 |
Correct |
1176 ms |
241808 KB |
Output is correct |
47 |
Correct |
1178 ms |
242568 KB |
Output is correct |
48 |
Correct |
335 ms |
151136 KB |
Output is correct |
49 |
Correct |
2209 ms |
270160 KB |
Output is correct |
50 |
Correct |
2239 ms |
270120 KB |
Output is correct |
51 |
Correct |
2063 ms |
269924 KB |
Output is correct |
52 |
Correct |
1438 ms |
243084 KB |
Output is correct |
53 |
Correct |
1099 ms |
241112 KB |
Output is correct |