답안 #920835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920835 2024-02-03T05:00:02 Z oblantis Xylophone (JOI18_xylophone) C++17
0 / 100
0 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;
	}
}
//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;
//}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 448 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 448 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 448 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -