Submission #419670

#TimeUsernameProblemLanguageResultExecution timeMemory
419670Emin2004Xylophone (JOI18_xylophone)C++14
0 / 100
1 ms308 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pii pair<int, ll>
#define F first
#define S second

const int N = 100005;
const int mod = 1e9;

static int a[5005];
int found[N];

void solve(int n) {
    int l = 1;
    int pos = -1;
    while(l < n){
        pos = l;
        int x = query(l + 1, n);
        if(x + 1 != n){
            break;
        }
        l++;
    }
    a[pos] = 1;
    found[1] = 1;
    int r = query(pos, pos + 1) + 1;
    int lastquery = r - 1;
    a[pos + 1] = r;
    found[r] = 1;
    for(int i = pos + 2; i <= n; i++){
        int x = query(i - 1, i);
        int c1 = a[i - 1] - x;
        int c2 = a[i - 1] + x;
        if(c1 <= 0 || found[c1] == 1){
            a[i] = c2;
            found[c2] = 1;
        }
        else if(c2 > n || found[c2] == 1){
            a[i] = c1;
            found[c1] = 1;
        }
        else{
            int y = query(i - 2, i);
            if(a[i - 2] < a[i - 1]){
                if(y > lastquery){
                    a[i] = c2;
                    found[c2] = 1;
                }
                else{
                    a[i] = c1;
                    found[c1] = 1;
                }
            }
            else{
                if(y > lastquery){
                    a[i] = c1;
                    found[c1] = 1;
                }
                else{
                    a[i] = c2;
                    found[c2] = 1;
                }
            }
        }
        lastquery = x;
    }
    lastquery = r - 1;
    for(int i = pos - 1; i > 0; i--){
        int x = query(i, i + 1);
        int c1 = a[i + 1] - x;
        int c2 = a[i + 1] + x;
        if(c1 <= 0 || found[c1] == 1){
            a[i] = c2;
            found[c2] = 1;
        }
        else if(c2 > n || found[c2] == 1){
            a[i] = c1;
            found[c1] = 1;
        }
        else{
            int y = query(i, i + 2);
            if(a[i + 2] < a[i + 1]){
                if(y > lastquery){
                    a[i] = c2;
                    found[c2] = 1;
                }
                else{
                    a[i] = c1;
                    found[c1] = 1;
                }
            }
            else{
                if(y > lastquery){
                    a[i] = c1;
                    found[c1] = 1;
                }
                else{
                    a[i] = c2;
                    found[c2] = 1;
                }
            }
        }
        lastquery = x;
    }
	for(int i = 1; i <= n; i++) {
		answer(i, a[i]);
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...