Submission #764568

#TimeUsernameProblemLanguageResultExecution timeMemory
764568vjudge1Xylophone (JOI18_xylophone)C++17
Compilation error
0 ms0 KiB
#include "xylophone.h" using namespace std; #define taskname "template" #define ll long long #define ld double #define fi first #define se second #define vi vector<int> #define pii pair<int,int> #define vii vector<pii> #define vvi vector<vi> #define pb push_back #define eb emplace_back mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rd(ll min1,ll max1){ assert(min1<=max1); ll res=rng()*1LL*rng()%(max1-min1+1); if(res<=0) res+=max1; return res; } const int MN=5e3+5; int arr[MN]; bool check2[MN]; int limit; void solve(int N){ int n=N; if(n==1){ answer(1,1); return; } for(int i=1;i<=n;++i){ check2[i]=false; } limit=10000; int l=1,r=n; while(l<r){ int mid=l+r>>1; int res=query(mid,n); --limit; // cout<<"Case "<<mid<<' '<<n<<": "<<res<<'\n'; if(res==n-1) l=mid+1; else r=mid; } int idx=l-1,num=n; // cout<<idx<<'\n'; answer(idx,1); check2[1]=true; l=idx-2; r=idx+2; if(idx>1){ int res=query(idx-1,idx); --limit; answer(idx-1,res+1); check2[res+1]=true; } int res=query(idx,idx+1); --limit; answer(idx+1,res+1); check2[res+1]=true; for(int i=l;i>=1;--i){ int res=query(i,i+1); --limit; if(arr[i+1]+res>=n||arr[i+1]+res<=1||check2[arr[i+1]+res]){ answer(i,arr[i+1]-res); check2[arr[i+1]-res]=true; continue; } if(arr[i+1]-res>=n||arr[i+1]-res<=1||check2[arr[i+1]-res]){ answer(i,arr[i+1]+res); check2[arr[i+1]+res]=true; continue; } if(limit==i-1){ if(!check2[arr[i+1]+res]&&arr[i+1]+res<n){ answer(i,arr[i+1]+res); check2[arr[i+1]+res]=true; } else{ answer(i,arr[i+1]-res); check2[arr[i+1]-res]=true; } } else{ int res2=query(i,i+2); --limit; // cout<<"Case "<<i<<": "<<res<<' '<<res2<<endl; if(res==res2){ if(arr[i+2]<arr[i+1]) arr[i]=arr[i+1]-res; else arr[i]=arr[i+1]+res; } else{ if(arr[i+1]>arr[i+2]){ if(res2==arr[i+1]-arr[i+2]) arr[i]=arr[i+1]-res; else arr[i]=arr[i+1]+res; } else{ if(res2==arr[i+2]-arr[i+1]) arr[i]=arr[i+1]+res; else arr[i]=arr[i+1]-res; } } answer(i,arr[i]); check2[arr[i]]=true; } } for(int i=r;i<=n;++i){ int res=query(i-1,i); --limit; if(arr[i-1]+res>n||arr[i-1]+res<=1||check2[arr[i-1]+res]){ // cout<<"mmb"<<'\n'; answer(i,arr[i-1]-res); check2[arr[i-1]-res]=true; continue; } if(arr[i-1]-res>n||arr[i-1]-res<=1||check2[arr[i-1]-res]){ // cout<<"mmg"<<'\n'; answer(i,arr[i-1]+res); check2[arr[i-1]+res]=true; continue; } if(limit==n-i){ if(!check2[arr[i-1]+res]&&arr[i-1]+res<=n){ answer(i,arr[i-1]+res); check2[arr[i-1]+res]=true; } else{ answer(i,arr[i-1]-res); check2[arr[i-1]-res]=true; } } else{ int res2=query(i-2,i); --limit; // cout<<"Case "<<i<<": "<<res<<' '<<res2<<'\n'; if(res==res2){ if(arr[i-2]<arr[i-1]) arr[i]=arr[i-1]-res; else arr[i]=arr[i-1]+res; } else{ if(arr[i-2]<arr[i-1]){ if(res2==arr[i-1]-arr[i-2]) arr[i]=arr[i-1]-res; else arr[i]=arr[i-1]+res; } else{ if(res2==arr[i-2]-arr[i-1]) arr[i]=arr[i-1]+res; else arr[i]=arr[i-1]-res; } } answer(i,arr[i]); check2[arr[i]]=true; } } }

Compilation message (stderr)

xylophone.cpp:16:1: error: 'mt19937' does not name a type
   16 | mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
      | ^~~~~~~
xylophone.cpp: In function 'long long int rd(long long int, long long int)':
xylophone.cpp:19:2: error: 'assert' was not declared in this scope
   19 |  assert(min1<=max1);
      |  ^~~~~~
xylophone.cpp:2:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
    1 | #include "xylophone.h"
  +++ |+#include <cassert>
    2 | using namespace std;
xylophone.cpp:20:9: error: 'rng' was not declared in this scope
   20 |  ll res=rng()*1LL*rng()%(max1-min1+1);
      |         ^~~
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:42:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |   int mid=l+r>>1;
      |           ~^~
xylophone.cpp:49:14: warning: unused variable 'num' [-Wunused-variable]
   49 |  int idx=l-1,num=n;
      |              ^~~