# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
995879 | 2024-06-10T03:21:06 Z | khanhphucscratch | Xylophone (JOI18_xylophone) | C++14 | 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); }*/