Submission #1070489

#TimeUsernameProblemLanguageResultExecution timeMemory
1070489_8_8_Xylophone (JOI18_xylophone)C++17
47 / 100
58 ms596 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; int p[5002],a[5002]; void solve(int n) { memset(p,0,sizeof(p)); memset(a,0,sizeof(a)); int nd = n - 1; int l = 1,r = n; while(r - l > 1) { int mid = (l + r) >> 1; if(query(1,mid) == nd) { r = mid; } else { l = mid; } } p[n] = r; l = 1,r = p[n]; while(r - l > 1) { int mid = (l + r) >> 1; if(query(mid,p[n]) == nd) { l = mid; } else { r = mid; } } p[1] = l; a[p[1]] = 1; a[p[n]] = n; int mx = 1; for(int i = p[1] - 1;i >= 1;i--) { int val, T; T = query(i,p[1]); if(T != mx - 1) { val = mx = 1 + T; } else { int t2, t1; t2 = query(i,i + 2); t1 = query(i + 1,i + 2); int t = query(i,i + 1); if(a[i + 2] > a[i + 1]) { if(t2 == a[i + 2] - (a[i + 1] - t)) { val = a[i + 1] - t; } else { val = a[i + 1] + t; } } else { if(t2 == a[i + 1] + t - a[i + 2]) { val = a[i + 1] + t; } else { val = a[i + 1] - t; } } } // cout << i << ' ' << val << ' ' << (a[i + 2] > a[i + 1]) << '\n'; p[val] = i; a[i] = val; } mx = 1; for(int i = p[1] + 1;i < p[n];i++) { int val, T; T = query(p[1],i); if(T != mx - 1) { val = mx = 1 + T; } else { int t2, t1; t2 = query(i - 2,i); t1 = query(i - 2,i - 1); int t = query(i - 1,i); if(a[i - 2] > a[i - 1]) { if(t2 == a[i - 2] - (a[i - 1] - t)) { val = a[i - 1] - t; } else { val = a[i - 1] + t; } } else { if(t2 == a[i - 1] + t - a[i - 2]) { val = a[i - 1] + t; } else { val = a[i - 1] - t; } } } // cout << i << ' ' << val << '\n'; p[val] = i; a[i] = val; } int mn = n; for(int i = p[n] + 1;i <= n;i++) { int val, T = query(p[n],i); if(T != n - mn) { mn = val = n - T; } else { int t2, t1; t2 = query(i - 2,i); t1 = query(i - 2,i - 1); int t = query(i - 1,i); if(a[i - 2] > a[i - 1]) { if(t2 == a[i - 2] - (a[i - 1] - t)) { val = a[i - 1] - t; } else { val = a[i - 1] + t; } } else { if(t2 == a[i - 1] + t - a[i - 2]) { val = a[i - 1] + t; } else { val = a[i - 1] - t; } } } p[val] = i; a[i] = val; } for(int i = 1;i <= n;i++) { answer(p[i],i); } }

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:38:12: warning: variable 't1' set but not used [-Wunused-but-set-variable]
   38 |    int t2, t1;
      |            ^~
xylophone.cpp:67:12: warning: variable 't1' set but not used [-Wunused-but-set-variable]
   67 |    int t2, t1;
      |            ^~
xylophone.cpp:95:12: warning: variable 't1' set but not used [-Wunused-but-set-variable]
   95 |    int t2, t1;
      |            ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...