제출 #128294

#제출 시각아이디문제언어결과실행 시간메모리
128294miguelXylophone (JOI18_xylophone)C++14
47 / 100
97 ms516 KiB
#include<bits/stdc++.h>
#include <xylophone.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <int, pi>
#define vi vector <int>
const ll mod = 1e9 + 7;

void solve(int n){
    int t[5001], q[5003];
    for(int i=1; i<n; i++) q[i]=query(i, i+1);
    int l=1, r=n;
    while(r-l>1){
        int mid=(l+r)/2;
        if(query(1, mid)!=n-1) l=mid;
        else r=mid;
    }
    int mx=r;
    l=1, r=mx;
    while(r-l>1){
        int mid=(l+r)/2;
        if(query(mid, mx)!=n-1) r=mid;
        else l=mid;
    }
    int mn=l;
    t[mn]=1, t[mx]=n;
    if(mn>1) t[mn-1]=q[mn-1]+1;
    t[mn+1]=q[mn]+1;
    if(mx<n) t[mx+1]=n-q[mx];
    t[mx-1]=n-q[mx-1];
    for(int i=mn-1; i>=2; i--){
        int q1=query(i-1, i+1), q2=q[i-1], q3=q[i];
        if(q1==q2+q3){
            if(t[i+1]>t[i]) t[i-1]=t[i]-q2;
            else t[i-1]=t[i]+q2;
        }
        else{
            if(t[i+1]>t[i]) t[i-1]=t[i]+q2;
            else t[i-1]=t[i]-q2;
        }
    }
    for(int i=mn+1; i<=mx-2; i++){
        int q1=query(i-1, i+1), q2=q[i-1], q3=q[i];
        if(q1==q2+q3){//cout<<i<<"mamamia"<<endl;
            if(t[i-1]>t[i]) t[i+1]=t[i]-q3;
            else t[i+1]=t[i]+q3;
        }
        else{
            if(t[i-1]>t[i]) t[i+1]=t[i]+q3;
            else t[i+1]=t[i]-q3;
        }
    }
    for(int i=mx+1; i<=n-1; i++){
        int q1=query(i-1, i+1), q2=q[i-1], q3=q[i];
        if(q1==q2+q3){
            if(t[i-1]>t[i]) t[i+1]=t[i]-q3;
            else t[i+1]=t[i]+q3;
        }
        else{
            if(t[i-1]>t[i]) t[i+1]=t[i]+q3;
            else t[i+1]=t[i]-q3;
        }
    }
    //for(int i=1; i<=n; i++) cout<<t[i]<<"x ";
    for(int i=1; i<=n; i++) answer(i, t[i]);
    //cout<<mn<<" "<<mx<<endl;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...