Submission #920836

# Submission time Handle Problem Language Result Execution time Memory
920836 2024-02-03T05:00:53 Z oblantis Xylophone (JOI18_xylophone) C++17
0 / 100
1 ms 448 KB
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int inf = 1e9;
const int mod = 1e9+7;
const int maxn = 1e6 + 1;
#include "xylophone.h"

int a[5001], b[5001], x;
int q1[5001], q2[5001];
void solve(int n) {
	int l = 1, r = n;
	while(l + 1 < r){
		int mid = l + (r - l) / 2;
		x = query(mid, n);
		if(x == n - 1)l = mid;
		else r = mid;
	}
	a[l] = 1;
	b[1] = l;
	for(int i = l + 1; i <= n; i++){
		q1[i] = query(i - 1, i);
		if(a[i - 1] + q1[i] > n || b[a[i - 1] + q1[i]]){
			a[i] = a[i - 1] - q1[i];
		}
		else if(a[i - 1] - q1[i] < 1 || b[a[i - 1] - q1[i]]){
			a[i] = a[i - 1] + q1[i];
		}
		else {
			q2[i] = query(i - 2, i);
			if(q1[i - 1] == q2[i]){
				if(a[i - 1] < a[i - 2])a[i] = a[i - 1] + q1[i];
				else a[i] = a[i - 1] - q1[i];
			}
			else {
				if(q1[i] == q2[i]){
					if(a[i - 1] < a[i - 2])a[i] = a[i - 1] + q1[i];
					else a[i] = a[i - 1] - q1[i];
				}
				else {
					if(a[i - 1] < a[i - 2])a[i] = a[i - 1] - q1[i];
					else a[i] = a[i - 1] + q1[i];
				}
			}
		}
		b[a[i]] = i;
	}
	for(int i = l - 1; i >= 1; i--){
		q1[i] = query(i, i + 1);
		if(a[i + 1] + q1[i] > n || b[a[i + 1] + q1[i]]){
			a[i] = a[i + 1] - q1[i];
		}
		else if(a[i + 1] - q1[i] < 1 || b[a[i + 1] - q1[i]]){
			a[i] = a[i + 1] + q1[i];
		}
		else {
			q2[i] = query(i + 2, i);
			if(q1[i + 1] == q2[i]){
				if(a[i + 1] < a[i + 2])a[i] = a[i + 1] + q1[i];
				else a[i] = a[i + 1] - q1[i];
			}
			else {
				if(q1[i] == q2[i]){
					if(a[i + 1] < a[i + 2])a[i] = a[i + 1] + q1[i];
					else a[i] = a[i + 1] - q1[i];
				}
				else {
					if(a[i + 1] < a[i + 2])a[i] = a[i + 1] - q1[i];
					else a[i] = a[i + 1] + q1[i];
				}
			}
		}
		b[a[i]] = i;
	}
	for(int i = 1; i <= n; i++){
		answer(i, a[i]);
	}
}
//void solve() {
	
//}

//int main() {
	//ios_base::sync_with_stdio(0);
	//cin.tie(0);
	//int times = 1;
	////cin >> times;
	//for(int i = 1; i <= times; i++) {
		//solve();
	//}
	//return 0;
//}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 1 ms 444 KB Output is correct
3 Correct 1 ms 448 KB Output is correct
4 Incorrect 1 ms 448 KB Wrong Answer [1]
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 1 ms 444 KB Output is correct
3 Correct 1 ms 448 KB Output is correct
4 Incorrect 1 ms 448 KB Wrong Answer [1]
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 1 ms 444 KB Output is correct
3 Correct 1 ms 448 KB Output is correct
4 Incorrect 1 ms 448 KB Wrong Answer [1]
5 Halted 0 ms 0 KB -