Submission #846082

# Submission time Handle Problem Language Result Execution time Memory
846082 2023-09-07T09:27:37 Z AlphaMale06 Xylophone (JOI18_xylophone) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
include "xylophone.h"
using namespace std;
void solve(int n){
    bool have[n+1]={0};
    int ans[n]={0};
    int mnind=n;
    int l=1; int r=n;
    while(l<=r){
        if(l==r){
            mnind=l;
            have[1]=1;
            ans[l]=1;
            break;
        }
        if(r-l==1){
            int q1=query(l, n);
            int q2=query(r, n);
            if(q1>q2){
                mnind=l;
                have[1]=1;
                ans[l]=1;
            }
            else{
                mnind=r;
                have[1]=1;
                ans[r]=1;
            }
            break;
        }
        int s=(l+r)/2;
        int q1=query(s+1, n);
        if(q1!=n-1){
            r=s;
        }
        else{
            l=s+1;
        }
    }
    if(mnind!=n){
        int q=query(mnind, mnind+1);
        have[q+1]=1;
        ans[mnind+1]=q+1;
    }
    if(mnind!=1){
        int q=query(mnind-1, mnind);
        have[q+1]=1;
        ans[mnind-1]=q+1;
    }
    for(int i=mnind+2; i<=n; i++){
        int q1=query(i-1, i);
        if(q1+ans[i-1]>n || have[q1+ans[i-1]]){
            have[ans[i-1]-q1]=1;
            ans[i]=ans[i-1]-q1;
        }
        else if(ans[i-1]-q1<1 || have[ans[i-1]-q1]){
            have[ans[i-1]+q1]=1;
            ans[i]=ans[i-1]+q1;
        }
        else{
            int q2=query(i-2, i);
            if(q2==abs(ans[i-1]-ans[i-2])){
                if(ans[i-2]>ans[i-1])ans[i]=ans[i-1]+q1;
                else ans[i]=ans[i-1]-q1;
                have[ans[i]]=1;
            }
            else{
                if(ans[i-1]>ans[i-2]){
                    if(q1==q2){
                        ans[i]=ans[i-1]-q1;
                        have[ans[i]]=1;
                    }
                    else{
                        ans[i]=q1+ans[i-1];
                        have[ans[i]]=1;
                    }
                }
                else{
                    if(q1==q2){
                        ans[i]=q1+ans[i-1];
                        have[ans[i]]=1;
                    }
                    else{
                        ans[i]=ans[i-1]-q1;
                        have[ans[i]]=1;
                    }
                }
            }
        }
    }
    for(int i=mnind-2; i>=1; i--){
        int q1=query(i, i+1);
        if(q1+ans[i+1]>n || have[ans[i+1]+q1]){
            have[ans[i+1]-q1]=1;
            ans[i]=ans[i-1]+q1;
        }
        else if(ans[i+1]-q1 < 1 || have[ans[i+1]-q1]){
            have[ans[i+1]+q1]=1;
            ans[i]=ans[i+1]+q1;
        }
        else{
            int q2=query(i, i+2);
            if(q2==abs(ans[i+2]-ans[i-1])){
                if(ans[i+2]>ans[i+1])ans[i]=ans[i+1]+q1;
                else ans[i]=ans[i+1]-q1;
                have[ans[i]]=1;
            }
            else{
                if(ans[i+1]>ans[i+2]){
                    if(q1==q2){
                        ans[i]=ans[i+1]-q1;
                        have[ans[i]]=1;
                    }
                    else{
                        ans[i]=ans[i+1]+q1;
                        have[ans[i]]=1;
                    }
                }
                else{
                    if(q1==q2){
                        ans[i]=q1+ans[i+1];
                        have[ans[i]]=1;
                    }
                    else{
                        ans[i]=ans[i+1]-q1;
                        have[ans[i]]=1;
                    }
                }
            }
        }
    }
    for(int i=1; i<=n; i++){
        answer(i, ans[i]);
    }
}

Compilation message

xylophone.cpp:2:1: error: 'include' does not name a type
    2 | include "xylophone.h"
      | ^~~~~~~
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:17:20: error: 'query' was not declared in this scope
   17 |             int q1=query(l, n);
      |                    ^~~~~
xylophone.cpp:32:16: error: 'query' was not declared in this scope
   32 |         int q1=query(s+1, n);
      |                ^~~~~
xylophone.cpp:41:15: error: 'query' was not declared in this scope
   41 |         int q=query(mnind, mnind+1);
      |               ^~~~~
xylophone.cpp:46:15: error: 'query' was not declared in this scope
   46 |         int q=query(mnind-1, mnind);
      |               ^~~~~
xylophone.cpp:51:16: error: 'query' was not declared in this scope
   51 |         int q1=query(i-1, i);
      |                ^~~~~
xylophone.cpp:92:16: error: 'query' was not declared in this scope
   92 |         int q1=query(i, i+1);
      |                ^~~~~
xylophone.cpp:133:9: error: 'answer' was not declared in this scope
  133 |         answer(i, ans[i]);
      |         ^~~~~~