Submission #419737

#TimeUsernameProblemLanguageResultExecution timeMemory
419737Emin2004Xylophone (JOI18_xylophone)C++14
100 / 100
98 ms444 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<int, ll> #define F first #define S second const int N = 100005; const int mod = 1e9; static int a[5005]; int found[N]; void solve(int n) { int l = 1, r = n; int pos = 1; for(int i = 4096; i > 0; i /= 2){ if(pos + i >= n) continue; int x = query(pos + i, n); if(x + 1 == n) pos += i; } // answer(1, pos); a[pos] = 1; found[1] = 1; r = query(pos, pos + 1) + 1; a[pos + 1] = r; found[r] = 1; for(int i = pos + 2; i <= n; i++){ int x = query(i - 1, i); int c1 = a[i - 1] - x; int c2 = a[i - 1] + x; if(c1 <= 0 || found[c1] == 1){ a[i] = c2; found[c2] = 1; } else if(c2 > n || found[c2] == 1){ a[i] = c1; found[c1] = 1; } else{ int y = query(i - 2, i); if(max(abs(a[i - 1] - a[i - 2]), max(abs(a[i - 2] - c1), x)) == y){ a[i] = c1; found[c1] = 1; } else{ a[i] = c2; found[c2] = 1; } } } for(int i = pos - 1; i > 0; i--){ int x = query(i, i + 1); int c1 = a[i + 1] - x; int c2 = a[i + 1] + x; if(c1 <= 0 || found[c1] == 1){ a[i] = c2; found[c2] = 1; } else if(c2 > n || found[c2] == 1){ a[i] = c1; found[c1] = 1; } else{ int y = query(i, i + 2); if(max(abs(a[i + 1] - a[i + 2]), max(abs(a[i + 2] - c1), x)) == y){ a[i] = c1; found[c1] = 1; } else{ a[i] = c2; found[c2] = 1; } } } for(int i = 1; i <= n; i++) { answer(i, a[i]); } }

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:18:9: warning: unused variable 'l' [-Wunused-variable]
   18 |     int l = 1, r = n;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...