# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1153362 | Zflop | Xylophone (JOI18_xylophone) | C++20 | 0 ms | 0 KiB |
#include <cstdio>
#include <cstdlib>
static const int N_MAX = 5000;
static const int Q_MAX = 10000;
static int N;
static int A[N_MAX];
static bool used[N_MAX];
static int query_c;
static int answer_c;
int query(int s, int t) {
if(query_c >= Q_MAX) {
printf("Wrong Answer\n");
exit(0);
}
query_c++;
if(!(1 <= s && s <= t && t <= N)) {
printf("Wrong Answer\n");
exit(0);
}
int mx = 0, mn = N + 1;
for(int i = s - 1; i < t; i++) {
if(mx < A[i]) {
mx = A[i];
}
if(mn > A[i]) {
mn = A[i];
}
}
return mx - mn;
}
void answer(int i, int a) {
answer_c++;
if(!(1 <= i && i <= N)) {
printf("Wrong Answer\n");
exit(0);
}
if(!(1 <= a && a <= N)) {
printf("Wrong Answer\n");
exit(0);
}
if(used[i - 1]) {
printf("Wrong Answer\n");
exit(0);
}
if(a != A[i - 1]) {
printf("Wrong Answer\n");
exit(0);
}
used[i - 1] = true;
}
#include <bits/stdc++.h>
using namespace std;
vector<int>a;
void DO(int l,int r) {
if (l == r - 1)
return;
cout << l << ' ' << r << '\n';
if (a[l] < a[r]) {
/// in l e minimul
int q = query(l,r - 1);
int ans = r - 1;
int L = l,R = r - 1;
while (L <= R) {
int MID = (L + R) / 2;
if (query(l,MID) == q) {
ans = MID;
R = MID - 1;
} else
L = MID + 1;
}
a[ans] = q - a[l];
cout << ans << ' ' << a[ans] << '\n';
DO(l,ans);
DO(ans,r);
} else {
int q = query(l + 1,r);
int ans = l + 1;
int L = l + 1,R = r;
while (L <= R) {
int MID = (L + R) / 2;
if (query(MID,r) == q) {
ans = MID;
L = MID + 1;
} else
R = MID - 1;
}
a[ans] = q - a[r];
cout << ans << ' ' << a[ans] << '\n';
DO(l,ans);
DO(ans,r);
}
}
void solve(int N) {
a = vector<int>(N + 1);
int l = 1,r = N;
int l1 = 0;
while (l <= r) {
int mid = (l + r) / 2;
if (query(mid,N) == N - 1) {
l = mid + 1;
l1 = mid;
} else
r = mid - 1;
}
l = 1,r = N;
int lN = 0;
while (l <= r) {
int mid = (l + r) / 2;
if (query(1,mid) == N - 1) {
lN = mid;
r = mid - 1;
} else
l = mid + 1;
}
a[l1] = 1;
a[lN] = N;
cout << l1 << ' ' << lN << '\n';
DO(l1,lN);
DO(1,l1);
DO(lN,N);
for (int i = 1; i <= N;++i)
cout << a[i] << ' ';
}
int main() {
query_c = 0;
answer_c = 0;
if(scanf("%d", &N) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
for(int i = 0; i < N; i++) {
if(scanf("%d", A + i) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
used[i] = false;
}
solve(N);
if(!(answer_c == N)) {
printf("Wrong Answer\n");
exit(0);
}
printf("Accepted : %d\n", query_c);
}