Submission #995879

# Submission time Handle Problem Language Result Execution time Memory
995879 2024-06-10T03:21:06 Z khanhphucscratch Xylophone (JOI18_xylophone) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
/*int query(int l, int r)
{
    cout<<"? "<<l<<" "<<r<<endl;
    int x; cin>>x;
    return x;
}
void answer(int p, int v)
{
    cout<<"! "<<p<<" "<<v<<endl;
}*/
void solve(int n)
{
    vector<int> a(n+1), s(n+1);
    a[2] = query(1, 2), s[2] = 0;
    int last = a[2];
    for(int i = 3; i <= n; i++){
        int cur = query(i-1, i), sum = query(i-2, i);
        a[i] = cur;
        if(last + cur == sum) s[i] = s[i-1];
        else s[i] = (s[i-1] ^ 1);
        last = cur;
    }
    vector<int> cd(n+1);
    for(int i = 1; i <= n; i++) cd[i] = cd[i-1] + a[i] * (-s[i] * 2 + 1);
    int maxplace = 1, minplace = 1;
    for(int i = 1; i <= n; i++){
        if(cd[maxplace] < cd[i]) maxplace = i;
        if(cd[minplace] > cd[i]) minplace = i;
    }
    if(maxplace < minplace){
        for(int i = 1; i <= n; i++) s[i] ^= 1;
        for(int i = 1; i <= n; i++) cd[i] = cd[i-1] + a[i] * (-s[i] * 2 + 1);
    }
    int minval = 1e18;
    for(int i = 1; i <= n; i++) minval = min(minval, cd[i]);
    for(int i = 1; i <= n; i++) cd[i] += -minval + 1;
    for(int i = 1; i <= n; i++) answer(i, cd[i]);
}
/*signed main()
{
    solve(5);
}*/

Compilation message

xylophone.cpp: In function 'void solve(long long int)':
xylophone.cpp:17:12: error: 'query' was not declared in this scope
   17 |     a[2] = query(1, 2), s[2] = 0;
      |            ^~~~~
xylophone.cpp:22:26: error: 'sum' was not declared in this scope
   22 |         if(last + cur == sum) s[i] = s[i-1];
      |                          ^~~
xylophone.cpp:40:33: error: 'answer' was not declared in this scope
   40 |     for(int i = 1; i <= n; i++) answer(i, cd[i]);
      |                                 ^~~~~~