Submission #953704

#TimeUsernameProblemLanguageResultExecution timeMemory
953704woodXylophone (JOI18_xylophone)C++17
0 / 100
0 ms344 KiB
#include <bits/stdc++.h> #include "xylophone.h"; using namespace std; typedef long long ll; typedef pair<int,int> p32; typedef pair<ll,ll> p64; #define pb push_back #define eb emplace_back #define fi first #define se second #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define MOD %1000000007 //int query(int s, int t); void solve(int n){ int res[n]; memset(res,0,sizeof res); int l = 0, r = n; while(r-l>1){ int mid = (l+r)/2; int x = query(1,mid); if(x<n) l = mid; else r = mid; } int R = l; l = 0, r = n; while(r-l>1){ int mid = (l+r)/2; int x = query(mid,n); if(x<n-1) r = mid; else l = mid; } int L = l-1; res[l] = 1; res[R]=n;//replace w R if(l) res[l-1] = query(l-1,l)+1; res[l+1] = query(l,l+1)+1; for (int i = l - 1; i >= 0; i--) { int q = query(i,i+1); if(res[i+1]+q>n) res[i]=res[i+1]-q; else if(res[i+1]-q<1) res[i] = res[i+1] + q; else{ int q2 = query(i,i+2); if((q2>abs(res[i+2]-res[i+1])&&res[i+2]>res[i+1])||(q2<abs(res[i+2]-res[i+1])&&res[i+2]<res[i+1])) res[i]=res[i+2]-q2; else res[i]=res[i+2]+q2; } } for (size_t i = l+1; i <= n; i++) { int q = query(i,i+1); if(res[i-1]+q>n) res[i]=res[i-1]-q; else if(res[i-1]-q<1) res[i] = res[i-1] + q; else{ int q2 = query(i-1,i+1); if((q2>abs(res[i-2]-res[i-1])&&res[i-2]>res[i-1])||(q2<abs(res[i-2]-res[i-1])&&res[i-2]<res[i-1])) res[i]=res[i-2]-q2; else res[i]=res[i-2]+q2; } } for (size_t i = 0; i < n; i++) { answer(i+1,res[i]); } }

Compilation message (stderr)

xylophone.cpp:2:23: warning: extra tokens at end of #include directive
    2 | #include "xylophone.h";
      |                       ^
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:54:25: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |  for (size_t i = l+1; i <= n; i++)
      |                       ~~^~~~
xylophone.cpp:69:23: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   69 |  for (size_t i = 0; i < n; i++)
      |                     ~~^~~
xylophone.cpp:33:6: warning: unused variable 'L' [-Wunused-variable]
   33 |  int L = l-1;
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...