Submission #1253531

#TimeUsernameProblemLanguageResultExecution timeMemory
1253531ardaXylophone (JOI18_xylophone)C++20
Compilation error
0 ms0 KiB
int l = 1, r = n; while(l != r){ int m = (l + r) / 2; int res = query(1, m); if(res == n-1) r = m; else l = m+1; } int ans[n+1], ans2[n+1]; for(int i = 0; i <= n; i++) ans2[i] = -1; ans[l] = 1; ans2[1] = l; if(l != n) ans[l+1] = query(l, l+1) + 1, ans2[ans[l+1]] = l+1; // cout << ans[l] << " " << ans[l+1]<<endl; for(int i = l+2; i <= n; i++){ int hmmm = query(i-1,i); if(ans[i-1] + hmmm > n){ ans[i] = ans[i-1] - hmmm; ans2[ans[i-1]-hmmm] = i; continue; } if(ans[i-1] - hmmm < 2){ ans[i] = ans[i-1] + hmmm; ans2[ans[i-1]+hmmm] = i; continue; } if(ans2[ans[i-1] + hmmm] != -1){ ans[i] = ans[i-1] - hmmm; ans2[ans[i-1]-hmmm] = i; continue; } if(ans2[ans[i-1] - hmmm] != -1){ ans[i] = ans[i-1] + hmmm; ans2[ans[i-1]+hmmm] = i; continue; } int of = query(i-2, i); if(ans[i-2]<ans[i-1]){ if(of == (ans[i-1]-ans[i-2] + hmmm)) ans[i] = ans[i-1] + hmmm, ans2[ans[i-1] + hmmm] = i; else ans[i] = ans[i-1] - hmmm, ans2[ans[i-1] - hmmm] = i; } else{ if(of == (ans[i-2]-ans[i-1] + hmmm)) ans[i] = ans[i-1] - hmmm, ans2[ans[i-1] - hmmm] = i; else ans[i] = ans[i-1] + hmmm, ans2[ans[i-1] + hmmm] = i; } } if(l != 1) ans[l-1] = query(l-1, l) + 1, ans2[ans[l-1]] = l-1; for(int i = l-2; i; i--){ int hmmm = query(i,i+1); if(ans[i+1] + hmmm > n){ ans[i] = ans[i+1] - hmmm; ans2[ans[i+1]-hmmm] = i; continue; } if(ans[i+1] - hmmm < 2){ ans[i] = ans[i+1] + hmmm; ans2[ans[i+1]+hmmm] = i; continue; } if(ans2[ans[i+1] + hmmm] != -1){ ans[i] = ans[i+1] - hmmm; ans2[ans[i+1]-hmmm] = i; continue; } if(ans2[ans[i+1] - hmmm] != -1){ ans[i] = ans[i+1] + hmmm; ans2[ans[i+1]+hmmm] = i; continue; } int of = query(i, i+2); if(ans[i+2]<ans[i+1]){ if(of == (ans[i+1]-ans[i+2] + hmmm)) ans[i] = ans[i+1] + hmmm, ans2[ans[i+1] + hmmm] = i; else ans[i] = ans[i+1] - hmmm, ans2[ans[i+1] - hmmm] = i; } else{ if(of == (ans[i+2]-ans[i+1] + hmmm)) ans[i] = ans[i+1] - hmmm, ans2[ans[i+1] - hmmm] = i; else ans[i] = ans[i+1] + hmmm, ans2[ans[i+1] + hmmm] = i; } } for(int i = 1; i <= n; i++) answer(i, ans[i]);

Compilation message (stderr)

xylophone.cpp:1:16: error: 'n' was not declared in this scope
    1 | int l = 1, r = n;
      |                ^
xylophone.cpp:2:5: error: expected unqualified-id before 'while'
    2 |     while(l != r){
      |     ^~~~~
xylophone.cpp:8:13: error: 'n' was not declared in this scope
    8 |     int ans[n+1], ans2[n+1];
      |             ^
xylophone.cpp:8:24: error: 'n' was not declared in this scope
    8 |     int ans[n+1], ans2[n+1];
      |                        ^
xylophone.cpp:9:5: error: expected unqualified-id before 'for'
    9 |     for(int i = 0; i <= n; i++) ans2[i] = -1;
      |     ^~~
xylophone.cpp:9:20: error: 'i' does not name a type
    9 |     for(int i = 0; i <= n; i++) ans2[i] = -1;
      |                    ^
xylophone.cpp:9:28: error: 'i' does not name a type
    9 |     for(int i = 0; i <= n; i++) ans2[i] = -1;
      |                            ^
xylophone.cpp:10:5: error: 'ans' does not name a type
   10 |     ans[l] = 1;
      |     ^~~
xylophone.cpp:11:5: error: 'ans2' does not name a type
   11 |     ans2[1] = l;
      |     ^~~~
xylophone.cpp:12:5: error: expected unqualified-id before 'if'
   12 |     if(l != n) ans[l+1] = query(l, l+1) + 1, ans2[ans[l+1]] = l+1;
      |     ^~
xylophone.cpp:14:5: error: expected unqualified-id before 'for'
   14 |     for(int i = l+2; i <= n; i++){
      |     ^~~
xylophone.cpp:14:22: error: 'i' does not name a type
   14 |     for(int i = l+2; i <= n; i++){
      |                      ^
xylophone.cpp:14:30: error: 'i' does not name a type
   14 |     for(int i = l+2; i <= n; i++){
      |                              ^
xylophone.cpp:46:5: error: expected unqualified-id before 'if'
   46 |     if(l != 1) ans[l-1] = query(l-1, l) + 1, ans2[ans[l-1]] = l-1;
      |     ^~
xylophone.cpp:47:5: error: expected unqualified-id before 'for'
   47 |     for(int i = l-2; i; i--){
      |     ^~~
xylophone.cpp:47:22: error: 'i' does not name a type
   47 |     for(int i = l-2; i; i--){
      |                      ^
xylophone.cpp:47:25: error: 'i' does not name a type
   47 |     for(int i = l-2; i; i--){
      |                         ^
xylophone.cpp:79:5: error: expected unqualified-id before 'for'
   79 |     for(int i = 1; i <= n; i++) answer(i, ans[i]);
      |     ^~~
xylophone.cpp:79:20: error: 'i' does not name a type
   79 |     for(int i = 1; i <= n; i++) answer(i, ans[i]);
      |                    ^
xylophone.cpp:79:28: error: 'i' does not name a type
   79 |     for(int i = 1; i <= n; i++) answer(i, ans[i]);
      |                            ^