Submission #1083441

#TimeUsernameProblemLanguageResultExecution timeMemory
1083441tosivanmakMinerals (JOI19_minerals)C++17
90 / 100
32 ms2996 KiB
#include "minerals.h" #include<bits/stdc++.h> using namespace std; #define ll long long mt19937 rng((ll)chrono::steady_clock::now().time_since_epoch().count()); random_device rd; mt19937 g(rd()); ll rnd(ll u, ll v){ return uniform_int_distribution<ll>(u,v)(rng); } int mp[86005]; bool used[86005]; int cnt=0; int machine=0; bool inside[86005]; map<ll,ll>hv; int query_num=0; ll fp[43005],sp[43005]; bool pref[86005]; ll timer=1,timer2=1; void dc(ll l, ll r){ if(l==r)return; ll mid=(l+r-1)>>1; ll last_qry; bool noonlef=0; for(int i=l;i<=mid;i++){ last_qry=Query(fp[i]); pref[fp[i]]^=1; if(pref[fp[i]]==0)noonlef=1; } // cout<<"dc "<<l<<" "<<r<<" "<<noonlef<<'\n'; vector<ll>lef,righ; ll brkid; for(int i=l;i<=r-1;i++){ ll curq=Query(sp[i]); pref[sp[i]]^=1; bool remov=0; if(!pref[sp[i]])remov=1; if(remov){ if(curq==last_qry){ if(noonlef)righ.push_back(sp[i]); else lef.push_back(sp[i]); } else{ if(noonlef)lef.push_back(sp[i]); else righ.push_back(sp[i]); } } else{ if(curq==last_qry){ if(noonlef)righ.push_back(sp[i]); else lef.push_back(sp[i]); } else{ if(noonlef)lef.push_back(sp[i]); else righ.push_back(sp[i]); } } if(lef.size()==mid-l+1||righ.size()==r-(mid+1)+1){ brkid=i; break; } last_qry=curq; } if(lef.size()!=mid-l+1){ for(int i=brkid+1;i<=r;i++){ lef.push_back(sp[i]); } } else{ for(int i=brkid+1;i<=r;i++){ righ.push_back(sp[i]); } } shuffle(lef.begin(),lef.end(),g); shuffle(righ.begin(),righ.end(),g); for(int i=0;i<lef.size();i++){ sp[l+i]=lef[i]; } for(int i=0;i<righ.size();i++){ sp[mid+1+i]=righ[i]; } dc(l,mid); dc(mid+1,r); } void Solve(int n){ int prev=0; for(int i=1;i<=2*n;i++){ int cur=Query(i); if(cur==prev+1){ fp[timer++]=i; } else{ sp[timer2++]=i; } prev=cur; } for(int i=1;i<=2*n;i++)pref[i]=1; dc(1,n); for(int i=1;i<=n;i++){ Answer(fp[i],sp[i]); } }

Compilation message (stderr)

minerals.cpp: In function 'void dc(long long int, long long int)':
minerals.cpp:60:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   60 |         if(lef.size()==mid-l+1||righ.size()==r-(mid+1)+1){
      |            ~~~~~~~~~~^~~~~~~~~
minerals.cpp:60:44: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   60 |         if(lef.size()==mid-l+1||righ.size()==r-(mid+1)+1){
      |                                 ~~~~~~~~~~~^~~~~~~~~~~~~
minerals.cpp:65:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   65 |     if(lef.size()!=mid-l+1){
      |        ~~~~~~~~~~^~~~~~~~~
minerals.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for(int i=0;i<lef.size();i++){
      |                 ~^~~~~~~~~~~
minerals.cpp:80:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for(int i=0;i<righ.size();i++){
      |                 ~^~~~~~~~~~~~
minerals.cpp:71:24: warning: 'brkid' may be used uninitialized in this function [-Wmaybe-uninitialized]
   71 |         for(int i=brkid+1;i<=r;i++){
      |                   ~~~~~^~
minerals.cpp:41:13: warning: 'last_qry' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |             if(curq==last_qry){
      |             ^~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...