Submission #920837

# Submission time Handle Problem Language Result Execution time Memory
920837 2024-02-03T05:08:48 Z oblantis Xylophone (JOI18_xylophone) C++17
100 / 100
45 ms 1720 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, i + 2);
			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 1 ms 452 KB Output is correct
2 Correct 0 ms 444 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 444 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 1 ms 696 KB Output is correct
8 Correct 1 ms 448 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 448 KB Output is correct
12 Correct 1 ms 444 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 1 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 452 KB Output is correct
2 Correct 0 ms 444 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 444 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 1 ms 696 KB Output is correct
8 Correct 1 ms 448 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 448 KB Output is correct
12 Correct 1 ms 444 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 1 ms 444 KB Output is correct
16 Correct 2 ms 444 KB Output is correct
17 Correct 4 ms 704 KB Output is correct
18 Correct 4 ms 1208 KB Output is correct
19 Correct 6 ms 700 KB Output is correct
20 Correct 5 ms 700 KB Output is correct
21 Correct 6 ms 716 KB Output is correct
22 Correct 6 ms 960 KB Output is correct
23 Correct 5 ms 708 KB Output is correct
24 Correct 4 ms 464 KB Output is correct
25 Correct 4 ms 700 KB Output is correct
26 Correct 6 ms 964 KB Output is correct
27 Correct 5 ms 1216 KB Output is correct
28 Correct 6 ms 700 KB Output is correct
29 Correct 5 ms 440 KB Output is correct
30 Correct 5 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 452 KB Output is correct
2 Correct 0 ms 444 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 444 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 1 ms 696 KB Output is correct
8 Correct 1 ms 448 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 448 KB Output is correct
12 Correct 1 ms 444 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 1 ms 444 KB Output is correct
16 Correct 2 ms 444 KB Output is correct
17 Correct 4 ms 704 KB Output is correct
18 Correct 4 ms 1208 KB Output is correct
19 Correct 6 ms 700 KB Output is correct
20 Correct 5 ms 700 KB Output is correct
21 Correct 6 ms 716 KB Output is correct
22 Correct 6 ms 960 KB Output is correct
23 Correct 5 ms 708 KB Output is correct
24 Correct 4 ms 464 KB Output is correct
25 Correct 4 ms 700 KB Output is correct
26 Correct 6 ms 964 KB Output is correct
27 Correct 5 ms 1216 KB Output is correct
28 Correct 6 ms 700 KB Output is correct
29 Correct 5 ms 440 KB Output is correct
30 Correct 5 ms 716 KB Output is correct
31 Correct 10 ms 952 KB Output is correct
32 Correct 17 ms 1216 KB Output is correct
33 Correct 24 ms 748 KB Output is correct
34 Correct 28 ms 1208 KB Output is correct
35 Correct 26 ms 1212 KB Output is correct
36 Correct 23 ms 1468 KB Output is correct
37 Correct 20 ms 1460 KB Output is correct
38 Correct 21 ms 1212 KB Output is correct
39 Correct 30 ms 952 KB Output is correct
40 Correct 34 ms 740 KB Output is correct
41 Correct 26 ms 1228 KB Output is correct
42 Correct 19 ms 964 KB Output is correct
43 Correct 23 ms 1220 KB Output is correct
44 Correct 22 ms 1212 KB Output is correct
45 Correct 30 ms 1224 KB Output is correct
46 Correct 28 ms 1212 KB Output is correct
47 Correct 28 ms 1228 KB Output is correct
48 Correct 32 ms 1720 KB Output is correct
49 Correct 24 ms 980 KB Output is correct
50 Correct 28 ms 1000 KB Output is correct
51 Correct 29 ms 968 KB Output is correct
52 Correct 26 ms 1460 KB Output is correct
53 Correct 29 ms 960 KB Output is correct
54 Correct 26 ms 956 KB Output is correct
55 Correct 26 ms 1492 KB Output is correct
56 Correct 31 ms 984 KB Output is correct
57 Correct 45 ms 960 KB Output is correct
58 Correct 27 ms 1220 KB Output is correct
59 Correct 35 ms 1240 KB Output is correct
60 Correct 32 ms 728 KB Output is correct