Submission #1006357

#TimeUsernameProblemLanguageResultExecution timeMemory
1006357AdamGSExamination (JOI19_examination)C++17
20 / 100
136 ms24352 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=1e5+7; pair<ll,ll>T[LIM]; ll wynik[LIM]; pair<pair<ll,ll>,ll>pyt[LIM]; vector<pair<ll,pair<ll,ll>>>A; vector<ll>skal; map<ll,ll>mp; ll tr[4*LIM], N=1, akt=0; void upd(int v, ll x) { v+=N; while(v) { tr[v]+=x; v/=2; } } ll cnt(int l, int r) { if(l>r) return 0; l+=N; r+=N; ll ans=tr[l]; if(l!=r) ans+=tr[r]; while(l/2!=r/2) { if(l%2==0) ans+=tr[l+1]; if(r%2==1) ans+=tr[r-1]; l/=2; r/=2; } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; rep(i, n) { cin >> T[i].st >> T[i].nd; A.pb({-T[i].st, {-1, T[i].nd}}); } rep(i, q) { cin >> pyt[i].st.st >> pyt[i].st.nd >> pyt[i].nd; pyt[i].nd=max(pyt[i].nd, pyt[i].st.st+pyt[i].st.nd); A.pb({-max(pyt[i].st.st, pyt[i].nd-pyt[i].st.nd), {i, pyt[i].st.nd}}); } for(auto i : A) skal.pb(i.nd.nd); sort(all(skal)); for(auto i : skal) if(mp.find(i)==mp.end()) mp[i]=akt++; while(N<akt) N*=2; sort(all(A)); for(auto i : A) { if(i.nd.st==-1) upd(mp[i.nd.nd], 1); else wynik[i.nd.st]+=cnt(mp[i.nd.nd], N-1); } rep(i, q) cout << wynik[i] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...