Submission #604295

#TimeUsernameProblemLanguageResultExecution timeMemory
604295krit3379Art Collections (BOI22_art)C++17
100 / 100
1588 ms648 KiB
#include<bits/stdc++.h> #include "art.h" using namespace std; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define N 10005 int pos[N],fen[N],mi=1e9; vector<int> v; void upd(int x,int k){ while(x<N){ fen[x]+=k; x+=x&-x; } } int sol(int x){ int ans=0; while(x){ ans+=fen[x]; x-=x&-x; } return ans; } int lower(int x){ int l=1,r=N-1,mid,pos; while(l<=r){ mid=(l+r)/2; if(sol(mid)>=x)pos=mid,r=mid-1; else l=mid+1; } return pos; } void solve(int n){ int i,m=5000,pre,now; for(i=1;i<=n;i++)v.push_back(i); for(i=1;i<N;i++)fen[i]=i&-i; pre=publish(v); pos[1]=m; upd(pos[1],-1); for(i=n-1;i>0;i--){ swap(v[0],v[i]); now=publish(v); int val=(now-pre)/2+(now-pre)/abs(now-pre); if(val<0)val++; pos[v[0]]=lower(sol(pos[v[i]])+val); upd(pos[v[0]],-1); pre=now; } for(i=1;i<=n;i++)mi=min(mi,pos[i]); for(i=1;i<=n;i++)pos[i]-=mi; for(i=1;i<=n;i++)v[pos[i]]=i; answer(v); return ; }

Compilation message (stderr)

art.cpp: In function 'int lower(int)':
art.cpp:34:12: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   34 |     return pos;
      |            ^~~
art.cpp: In function 'void solve(int)':
art.cpp:49:18: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |         pos[v[0]]=lower(sol(pos[v[i]])+val);
      |         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
interface.cpp: In function 'int publish(std::vector<int>)':
interface.cpp:20:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |     if(v.size() != N) {
      |        ~~~~~~~~~^~~~
interface.cpp: In function 'void answer(std::vector<int>)':
interface.cpp:36:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |     if(v.size() != 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...