Submission #1070496

#TimeUsernameProblemLanguageResultExecution timeMemory
1070496_8_8_Xylophone (JOI18_xylophone)C++17
47 / 100
95 ms98392 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; int p[5002],a[5002],mem[5002][5002]; int QQ(int l,int r) { if(mem[l][r] != -1) { return mem[l][r]; } return mem[l][r] = query(l,r); } void solve(int n) { memset(mem,-1,sizeof(mem)); 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(QQ(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(QQ(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 = QQ(i,p[1]); if(T != mx - 1) { val = mx = 1 + T; } else { int t2, t1; t2 = QQ(i,i + 2); t1 = QQ(i + 1,i + 2); int t = QQ(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 = QQ(p[1],i); if(T != mx - 1) { val = mx = 1 + T; } else { int t2, t1; t2 = QQ(i - 2,i); t1 = QQ(i - 2,i - 1); int t = QQ(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 = QQ(p[n],i); if(T != n - mn) { mn = val = n - T; } else { int t2, t1; t2 = QQ(i - 2,i); t1 = QQ(i - 2,i - 1); int t = QQ(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:45:12: warning: variable 't1' set but not used [-Wunused-but-set-variable]
   45 |    int t2, t1;
      |            ^~
xylophone.cpp:74:12: warning: variable 't1' set but not used [-Wunused-but-set-variable]
   74 |    int t2, t1;
      |            ^~
xylophone.cpp:102:12: warning: variable 't1' set but not used [-Wunused-but-set-variable]
  102 |    int t2, t1;
      |            ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...