Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
RUPC 2016 day3 D: Complex Oracle
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
typedef long long ll;
ll query(int l, int r) {
printf("? %d %d\n", l, r); fflush(stdout);
ll c;
scanf("%lld", &c);
return c;
}
int main() {
int n;
cin >> n;
vector<ll> front(n + 2);
vector<ll> back(n + 2);
for (int i = 1; i <= n; i++) front[i] = query(1, i);
for (int i = 1; i <= n; i++) back[i] = query(i, n);
vector<ll> ans(n + 1);
for (int i = 1; i <= n; i++) {
ans[i] += back[i] - back[i + 1];
ans[i] += i - 1 - (front[i] - front[i - 1]);
}
cout << "!";
for (int i = 1; i <= n; i++) {
printf(" %d", ans[i] + 1);
}
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment