# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
995972 | Thanhs | Xylophone (JOI18_xylophone) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <xylophone.h>
using namespace std;
#define int long long
#define pb push_back
// #define endl '\n'
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define setmin(x,y) x=min((x),(y))
#define setmax(x,y) x=max((x),(y))
#define fi first
#define se second
mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l,int r){return l+((hdp()%(r-l+1))+r-l+1)%(r-l+1);}
const int N = 1e4+5;
const int mod = 998244353;
const int SQ = 450;
const int inf = 1e9+1;
int ans[N],n;
bool b[N];
bool check(int x)
{
if(x<0||x>n) return 0;
return !b[x];
}
void solve(int _n)
{
n=_n;
int l=1,r=n-1;
while(l<r-1)
{
int m=l+r>>1;
if(query(1,m)!=n-1) r=m;
else l=m;
}
ans[l]=1; b[1]=1;
if(l-1)
{
ans[l-1]=ans[l]+query(l-1,l);
b[ans[l-1]]=1;
}
if(l+1<=n)
{
ans[l+1]=ans[l]+query(l,l+1);
b[ans[l+1]]=1;
}
for(int i=l-2;i>=1;i--)
{
int t=query(i,i+1);
if(!check(ans[i+1]+t)) ans[i]=ans[i+1]-t;
else if(!check(ans[i+1]-t)) ans[i]=ans[i+1]+t;
if(!ans[i])
{
int tt=query(i,i+2);
if(tt==abs(ans[i+2]-ans[i+1]))
{
if(ans[i+2]>ans[i+1]) ans[i]=ans[i+1]+t;
else ans[i]=ans[i+1]-t;
}
else if(tt==t)
{
if(ans[i+2]>ans[i+1]) ans[i]=ans[i+1]+t;
else ans[i]=ans[i+1]-t;
}
else
{
if(ans[i+2]>ans[i+1]) ans[i]=ans[i+1]-t;
else ans[i]=ans[i+1]+t;
}
}
b[ans[i]]=1;
}
for(int i=1;i<=n;i++) answer(i,ans[i]);
}