답안 #995989

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995989 2024-06-10T06:40:27 Z Thanhs Xylophone (JOI18_xylophone) C++14
컴파일 오류
0 ms 0 KB
// #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];
}

// int query(int l,int r)
// {
//     cout<<l<<' '<<r<<endl;
//     int res; cin>>res; return res;
// }

void solve(int _n)
// signed main()
{
    n=_n;
    // cin>>n;
    int l=1,r=n;
    while(l<r-1)
    {
        int m=l+r>>1;
        if(query(m,n)!=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;
    }
    cout<<"LDSJFOLSJDF";
    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=l+2;i<=n;i++)
    {
        int t=query(i-1,i);
        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-2,i);
            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]);
    // for(int i=1;i<=n;i++) cout<<ans[i]<<' ';
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:47:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |         int m=l+r>>1;
      |               ~^~
xylophone.cpp:48:12: error: 'query' was not declared in this scope
   48 |         if(query(m,n)!=n-1) r=m;
      |            ^~~~~
xylophone.cpp:54:25: error: 'query' was not declared in this scope
   54 |         ans[l-1]=ans[l]+query(l-1,l);
      |                         ^~~~~
xylophone.cpp:59:25: error: 'query' was not declared in this scope
   59 |         ans[l+1]=ans[l]+query(l,l+1);
      |                         ^~~~~
xylophone.cpp:65:15: error: 'query' was not declared in this scope
   65 |         int t=query(i,i+1);
      |               ^~~~~
xylophone.cpp:91:15: error: 'query' was not declared in this scope
   91 |         int t=query(i-1,i);
      |               ^~~~~
xylophone.cpp:115:27: error: 'answer' was not declared in this scope
  115 |     for(int i=1;i<=n;i++) answer(i,ans[i]);
      |                           ^~~~~~