Submission #784336

#TimeUsernameProblemLanguageResultExecution timeMemory
7843361075508020060209tcNew Home (APIO18_new_home)C++14
10 / 100
4316 ms67892 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define X first #define Y second int n; int K;int Q; int xar[500005]; int typ[500005]; int ta[500005]; int tb[500005]; int qpl[500005]; int qt[500005]; int ansl[500005];int ansr[500005]; int anok[500005]; int kcnt; int freq[500005]; struct mo{ int l;int r;int id; }; bool cmp(mo i,mo j){ int va=i.l/500;int vb=j.l/500; if(va<vb){return 1;} if(va>vb){return 0;} if(((va&1)==0)){ return i.r<j.r; } return i.r>j.r; } void add(int v){ freq[v]++; if(freq[v]==1){ kcnt++; } } void del(int v){ freq[v]--; if(freq[v]==0){ kcnt--; } } signed main() { cin.tie(0); ios_base::sync_with_stdio(0); cin>>n>>K>>Q; for(int i=1;i<=n;i++){ cin>>xar[i]>>typ[i]>>ta[i]>>tb[i]; } for(int i=1;i<=Q;i++){ cin>>qpl[i]>>qt[i]; ansl[i]=0;ansr[i]=1e9; } vector<pair<int,int>>event; vector<int>eventp; for(int i=1;i<=n;i++){ event.push_back({xar[i],typ[i]}); eventp.push_back(xar[i]); } sort(eventp.begin(),eventp.end()); sort(event.begin(),event.end()); for(int ttt=0;ttt<=29;ttt++){ vector<mo>qry; for(int i=1;i<=Q;i++){ int mi=ansl[i]+(ansr[i]-ansl[i])/2; anok[i]=0; if(ansl[i]==ansr[i]){anok[i]=1;continue;} mo hi; hi.id=i; hi.l=lower_bound(eventp.begin(),eventp.end(),qpl[i]-mi)-eventp.begin(); hi.r=upper_bound(eventp.begin(),eventp.end(),qpl[i]+mi)-eventp.begin(); hi.r--; if(hi.l>hi.r){continue;} qry.push_back(hi); } sort(qry.begin(),qry.end(),cmp); for(int i=1;i<=K;i++){ freq[i]=0; } kcnt=0; int lit=0;int rit=0; add(event[0].second); for(int i=0;i<qry.size();i++){ while(lit<qry[i].l){del(event[lit++].second);} while(rit>qry[i].r){del(event[rit--].second);} while(lit>qry[i].l){add(event[--lit].second);} while(rit<qry[i].r){add(event[++rit].second);} if(kcnt==K){ anok[qry[i].id]=1; } } for(int i=1;i<=Q;i++){ int mi=ansl[i]+(ansr[i]-ansl[i])/2; if(anok[i]){ ansr[i]=mi; }else{ ansl[i]=mi+1; } // cout<<anok[i]<<" "<<mi<<endl; } } for(int i=1;i<=Q;i++){ if(ansl[i]>1e8){ cout<<-1<<endl; }else{ cout<<ansl[i]<<endl; } } }

Compilation message (stderr)

new_home.cpp: In function 'int main()':
new_home.cpp:87:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<mo>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         for(int i=0;i<qry.size();i++){
      |                     ~^~~~~~~~~~~
#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...