Submission #676421

#TimeUsernameProblemLanguageResultExecution timeMemory
676421uroskExamination (JOI19_examination)C++14
100 / 100
358 ms13260 KiB
#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_multiset; #define maxn 400005 struct tupl{ ll x,y,sum,id; } v[maxn]; ll n,q; pll a[maxn]; bool ok[maxn]; 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;} bool cmp3(tupl x,tupl y){ if(x.x!=y.x) return x.x<y.x; return x.y<y.y; } 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); ll k = n; ordered_multiset sx,sy; for(ll j = q;j>=1;j--){ if(v[j].x+v[j].y>=v[j].sum){ ok[v[j].id] = 1; continue; } while(k>=1&&a[k].fi+a[k].sc>=v[j].sum){ sx.insert(a[k].fi); sy.insert(a[k].sc); k--; } ans[v[j].id] = sz(sx) - sx.order_of_key(v[j].x) - sy.order_of_key(v[j].y); } sort(v+1,v+1+q,cmp3); sort(a+1,a+1+n); sy.clear(); k = n; for(ll i = q;i>=1;i--){ if(!ok[v[i].id]) continue; while(k>=1&&a[k].fi>=v[i].x){ sy.insert(a[k].sc); k--; } ans[v[i].id] = sz(sy) - sy.order_of_key(v[i].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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...