답안 #704238

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704238 2023-03-02T01:35:53 Z minhcool Xylophone (JOI18_xylophone) C++17
100 / 100
66 ms 568 KB
#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e5 + 5;

const int oo = 1e18 + 7, mod = 1e9 + 7;

mt19937_64 rng(7405);

int rnd(int l, int r){
	int temp = rng() % (r - l + 1);
	return abs(temp) + l;
}

int n, a[N];

bool choose[N];

bool valid(int x){
	return (x >= 1 && x <= n && !choose[x]);
}

int answerr[N];
set<int> inq;

void solve(int N){
	n = N;
	int l = 2, r = n;
	while(l < r){
		int mid = (l + r) >> 1;
		if(query(1, mid) < (n - 1)) l = mid + 1;
		else r = mid;
	}
	int le = 1, ri = l - 1;
	while(le < ri){
		int mid = (le + ri + 1) >> 1;
		if(query(mid, l) == (n - 1)) le = mid;
		else ri = mid - 1;
	}
	int temp1 = le, temp2 = l;
	//cout << temp1 << " " << temp2 << "\n";
	answerr[temp1] = 1, answerr[temp2] = n;
	if(temp1 > 1) inq.insert(temp1 - 1);
	if(temp1 < (temp2 - 1)) inq.insert(temp1 + 1);
	if(temp1 < (temp2 - 2)) inq.insert(temp2 - 1);
	if(temp2 < n) inq.insert(temp2 + 1);
	choose[1] = choose[n] = 1;
	while(inq.size()){
		int pos = rnd(1, inq.size()), temp = -1;
		for(auto it : inq){
			pos--;
			if(!pos){
				temp = it;
				break;
			}
		}
		if(answerr[temp - 1]){
			int diff = query(temp - 1, temp);
			if(!valid(answerr[temp - 1] - diff)) answerr[temp] = answerr[temp - 1] + diff;
			else if(!valid(answerr[temp - 1] + diff)) answerr[temp] = answerr[temp - 1] - diff;
			else{
				assert(temp >= 2 && answerr[temp - 2]);
				int diff2 = query(temp - 2, temp);
				if(answerr[temp - 2] < answerr[temp - 1]){
					if(diff2 == (answerr[temp - 1] - answerr[temp - 2])) answerr[temp] = answerr[temp - 1] - diff;
					else{
						if(diff2 == diff) answerr[temp] = answerr[temp - 1] - diff;
						else answerr[temp] = answerr[temp - 1] + diff;
					}
				}
				else{
					if(diff2 == (answerr[temp - 2] - answerr[temp - 1])) answerr[temp] = answerr[temp - 1] + diff;
					else{
						if(diff2 == diff) answerr[temp] = answerr[temp - 1] + diff;
						else answerr[temp] = answerr[temp - 1] - diff;
					}
				}
			}
		}
		else{
			//int diff = query(temp, temp + 1);
			int diff = query(temp, temp + 1);
			if(!valid(answerr[temp + 1] - diff)) answerr[temp] = answerr[temp + 1] + diff;
			else if(!valid(answerr[temp + 1] + diff)) answerr[temp] = answerr[temp + 1] - diff;
			else{
				assert(answerr[temp + 2]);
				int diff2 = query(temp, temp + 2);
				if(answerr[temp + 2] < answerr[temp + 1]){
					if(diff2 == (answerr[temp + 1] - answerr[temp + 2])) answerr[temp] = answerr[temp + 1] - diff;
					else{
						if(diff2 == diff) answerr[temp] = answerr[temp + 1] - diff;
						else answerr[temp] = answerr[temp + 1] + diff;
					}
				}
				else{
					if(diff2 == (answerr[temp + 2] - answerr[temp + 1])) answerr[temp] = answerr[temp + 1] + diff;
					else{
						if(diff2 == diff) answerr[temp] = answerr[temp + 1] + diff;
						else answerr[temp] = answerr[temp + 1] - diff;
					}
				}
			}
		}
		choose[answerr[temp]] = 1;
		//cout << "OK " << temp << " " << answerr[temp] << "\n";
		inq.erase(temp);
		if(temp >= 2 && !answerr[temp - 1]) inq.insert(temp - 1);
		if(temp < n && !answerr[temp + 1]) inq.insert(temp + 1);
	}
	for(int i = 1; i <= n; i++){
		//cout << i << " " << answerr[i] << "\n";
		answer(i, answerr[i]);
	}
}

Compilation message

xylophone.cpp:16:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   16 | const int oo = 1e18 + 7, mod = 1e9 + 7;
      |                ~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 2 ms 308 KB Output is correct
8 Correct 2 ms 308 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 2 ms 308 KB Output is correct
8 Correct 2 ms 308 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 6 ms 324 KB Output is correct
19 Correct 13 ms 316 KB Output is correct
20 Correct 11 ms 208 KB Output is correct
21 Correct 12 ms 208 KB Output is correct
22 Correct 13 ms 208 KB Output is correct
23 Correct 9 ms 320 KB Output is correct
24 Correct 15 ms 316 KB Output is correct
25 Correct 11 ms 320 KB Output is correct
26 Correct 8 ms 332 KB Output is correct
27 Correct 13 ms 304 KB Output is correct
28 Correct 12 ms 324 KB Output is correct
29 Correct 13 ms 208 KB Output is correct
30 Correct 10 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 2 ms 308 KB Output is correct
8 Correct 2 ms 308 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 6 ms 324 KB Output is correct
19 Correct 13 ms 316 KB Output is correct
20 Correct 11 ms 208 KB Output is correct
21 Correct 12 ms 208 KB Output is correct
22 Correct 13 ms 208 KB Output is correct
23 Correct 9 ms 320 KB Output is correct
24 Correct 15 ms 316 KB Output is correct
25 Correct 11 ms 320 KB Output is correct
26 Correct 8 ms 332 KB Output is correct
27 Correct 13 ms 304 KB Output is correct
28 Correct 12 ms 324 KB Output is correct
29 Correct 13 ms 208 KB Output is correct
30 Correct 10 ms 328 KB Output is correct
31 Correct 23 ms 208 KB Output is correct
32 Correct 42 ms 308 KB Output is correct
33 Correct 41 ms 320 KB Output is correct
34 Correct 57 ms 332 KB Output is correct
35 Correct 60 ms 336 KB Output is correct
36 Correct 41 ms 308 KB Output is correct
37 Correct 40 ms 320 KB Output is correct
38 Correct 48 ms 336 KB Output is correct
39 Correct 60 ms 440 KB Output is correct
40 Correct 56 ms 316 KB Output is correct
41 Correct 27 ms 336 KB Output is correct
42 Correct 43 ms 568 KB Output is correct
43 Correct 49 ms 328 KB Output is correct
44 Correct 47 ms 316 KB Output is correct
45 Correct 52 ms 316 KB Output is correct
46 Correct 63 ms 320 KB Output is correct
47 Correct 65 ms 440 KB Output is correct
48 Correct 58 ms 440 KB Output is correct
49 Correct 52 ms 332 KB Output is correct
50 Correct 28 ms 324 KB Output is correct
51 Correct 58 ms 308 KB Output is correct
52 Correct 30 ms 336 KB Output is correct
53 Correct 52 ms 332 KB Output is correct
54 Correct 60 ms 328 KB Output is correct
55 Correct 54 ms 308 KB Output is correct
56 Correct 62 ms 320 KB Output is correct
57 Correct 64 ms 316 KB Output is correct
58 Correct 66 ms 320 KB Output is correct
59 Correct 56 ms 304 KB Output is correct
60 Correct 53 ms 328 KB Output is correct