이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int mod=1e9+7;
void solve(int n){
int id1=0,l=1,r=n;
while(l<=r){
int mid=(l+r)/2;
int x=query(mid,n);
if (x==n-1) {
id1=mid;
l=mid+1;
}else{
r=mid-1;
}
}
int idn=0;
l=id1+1;
r=n;
while(l<=r){
int mid=(l+r)/2;
int x=query(id1,mid);
if (x==n-1) {
idn=mid;
r=mid-1;
}else{
l=mid+1;
}
}
vector<int> vis(n+1,0),ans(n+1,0);
vis[1]=1;
vis[n]=1;
ans[id1]=1;
ans[idn]=n;
for(int i=id1-1;i>=1;i--){
int q=query(i,i+1);
int a=ans[i+1]+q;
int b=ans[i+1]-q;
if(b<=0 || vis[b]==1){
ans[i]=a;
vis[a]=1;
}else if(a>n || vis[a]==1){
ans[i]=b;
vis[b]=1;
}else{
int x=query(i,i+2);
int mx=max(a,max(ans[i+1],ans[i+2]));
int mn=min(a,min(ans[i+1],ans[i+2]));
if(x==mx-mn){
ans[i]=a;
vis[a]=1;
}else{
ans[i]=b;
vis[b]=1;
}
}
}
for(int i=idn-1;i>id1;i--){
int q=query(i,i+1);
int a=ans[i+1]+q;
int b=ans[i+1]-q;
if(b<=0 || vis[b]==1){
ans[i]=a;
vis[a]=1;
}else if(a>n || vis[a]==1){
ans[i]=b;
vis[b]=1;
}else{
int x=query(i,i+2);
int mx=max(a,max(ans[i+1],ans[i+2]));
int mn=min(a,min(ans[i+1],ans[i+2]));
if(x==mx-mn){
ans[i]=a;
vis[a]=1;
}else{
ans[i]=b;
vis[b]=1;
}
}
}
for(int i=idn+1;i<=n;i++){
int q=query(i,i-1);
int a=ans[i-1]+q;
int b=ans[i-1]-q;
if(b<=0 || vis[b]==1){
ans[i]=a;
vis[a]=1;
}else if(a>n || vis[a]==1){
ans[i]=b;
vis[b]=1;
}else{
int x=query(i-2,i);
int mx=max(a,max(ans[i-1],ans[i-2]));
int mn=min(a,min(ans[i-1],ans[i-2]));
if(x==mx-mn){
ans[i]=a;
vis[a]=1;
}else{
ans[i]=b;
vis[b]=1;
}
}
}
for(int i=1;i<=n;i++) answer(i,ans[i]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |