Submission #738510

#TimeUsernameProblemLanguageResultExecution timeMemory
738510089487New Home (APIO18_new_home)C++14
5 / 100
5066 ms1048576 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include<bits/stdc++.h> #define int long long #define quick ios::sync_with_stdio(0);cin.tie(0); #define rep(x,a,b) for(int x=a;x<=b;x++) #define repd(x,a,b) for(int x=a;x>=b;x--) #define lowbit(x) (x&-x) #define sz(x) (int)(x.size()) #define F first #define S second #define all(x) x.begin(),x.end() #define mp make_pair #define eb emplace_back using namespace std; typedef pair<int,int> pii; void debug(){ cout<<"\n"; } template <class T,class ... U > void debug(T a, U ... b){ cout<<a<<" ",debug(b...); } const int N=8e6+7; const int INF=1e18; set<int> st[N]; int L[N]; int R[N]; int root[N]; int cnt=0; void Update(int &now,int val,int l,int r,int lx=0,int rx=1e8+7){ if(!now) now=++cnt; if(l<=lx&&rx<=r){ st[now].insert(val); return ; } if(l>=rx||lx>=r) return ; int mid=(lx+rx)>>1; Update(L[now],val,l,r,lx,mid); Update(R[now],val,l,r,mid,rx); } int qry(int now,int pos,int val,int lx=0,int rx=1e8+7){ if(!now) return INF; int ret=INF; auto it=st[now].lower_bound(val); if(it!=st[now].end()) ret=min(ret,*it-val); if(it!=st[now].begin()) ret=min(ret,val-*prev(it)); if(lx==rx-1) return ret; int mid=(lx+rx)>>1; if(pos<mid) return min(ret,qry(L[now],pos,val,lx,mid)); return min(ret,qry(R[now],pos,val,mid,rx)); } int x[N]; int t[N]; int a[N]; int b[N]; signed main(){ quick int n,k,q; cin>>n>>k>>q; rep(i,1,n){ cin>>x[i]>>t[i]>>a[i]>>b[i]; Update(root[t[i]],x[i],a[i],b[i]+1); } while(q--){ int l,y; cin>>l>>y; int ret=-1; rep(type,1,k){ ret=max(ret,qry(root[type],y,l)); } cout<<(ret>=INF ? -1 : ret)<<"\n"; } 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...