Submission #780896

# Submission time Handle Problem Language Result Execution time Memory
780896 2023-07-12T14:25:58 Z JoenPoenMan Xylophone (JOI18_xylophone) C++17
47 / 100
85 ms 960 KB

#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> ii;

map<ii, int> queries;

int q(int l, int h) {
	if (l == h) return 0;
	if (queries.find({l, h}) != queries.end()) {
		return queries[{l, h}];
	}
	int res = query(l, h);
	queries[{l, h}] = res;
	return res;
}

void findNext2(int N, int top, int bot, int prevPitch, bool MIN);

void findNext1(int N, int top, int bot = 1, int prevPitch = 1, bool MIN = false, bool exl = false) {
	if (top == bot) return;
	int mid;
	int low = bot, high = top;
	int diff = q(low, high);
	if (abs(top - bot) != 1) {
		while (low != high) {
			mid = (low+high)/2;
			int res = q(bot, mid);
			if (res == diff) high = mid;
			else low = mid+1;
		}
	} else low = top;
	answer(low, prevPitch+diff*(MIN?-1:1));
	findNext1(N, top, low, prevPitch+diff*(MIN?-1:1), !MIN, true);
	findNext2(N, low, bot + exl, prevPitch+diff*(MIN?-1:1), !MIN);
}

void findNext2(int N, int top, int bot, int prevPitch, bool MIN ) {
	if (top == bot) return;
	int mid;
	int low = bot, high = top;
	int diff = q(low, high);
	if (abs(top - bot) != 1) {
		while (low != high) {
			mid = (low+high+1)/2;
			int res = q(mid, top);
			if (res == diff) low = mid;
			else high = mid-1;
		}
	} else low = bot;
	answer(low, prevPitch+diff*(MIN?-1:1));
	findNext1(N, top-1, low, prevPitch+diff*(MIN?-1:1), !MIN, true);
	findNext2(N, low, bot, prevPitch+diff*(MIN?-1:1), !MIN);
}

void solve(int N) {
	findNext1(N, N);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 6 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 3 ms 304 KB Output is correct
9 Correct 6 ms 336 KB Output is correct
10 Correct 5 ms 336 KB Output is correct
11 Correct 3 ms 308 KB Output is correct
12 Correct 3 ms 308 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 6 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 3 ms 304 KB Output is correct
9 Correct 6 ms 336 KB Output is correct
10 Correct 5 ms 336 KB Output is correct
11 Correct 3 ms 308 KB Output is correct
12 Correct 3 ms 308 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 11 ms 568 KB Output is correct
18 Correct 16 ms 384 KB Output is correct
19 Correct 26 ms 348 KB Output is correct
20 Correct 18 ms 344 KB Output is correct
21 Correct 24 ms 356 KB Output is correct
22 Correct 26 ms 336 KB Output is correct
23 Correct 57 ms 960 KB Output is correct
24 Correct 63 ms 912 KB Output is correct
25 Correct 85 ms 928 KB Output is correct
26 Correct 28 ms 456 KB Output is correct
27 Correct 23 ms 360 KB Output is correct
28 Correct 25 ms 424 KB Output is correct
29 Correct 17 ms 368 KB Output is correct
30 Correct 22 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 6 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 3 ms 304 KB Output is correct
9 Correct 6 ms 336 KB Output is correct
10 Correct 5 ms 336 KB Output is correct
11 Correct 3 ms 308 KB Output is correct
12 Correct 3 ms 308 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 4 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 11 ms 568 KB Output is correct
18 Correct 16 ms 384 KB Output is correct
19 Correct 26 ms 348 KB Output is correct
20 Correct 18 ms 344 KB Output is correct
21 Correct 24 ms 356 KB Output is correct
22 Correct 26 ms 336 KB Output is correct
23 Correct 57 ms 960 KB Output is correct
24 Correct 63 ms 912 KB Output is correct
25 Correct 85 ms 928 KB Output is correct
26 Correct 28 ms 456 KB Output is correct
27 Correct 23 ms 360 KB Output is correct
28 Correct 25 ms 424 KB Output is correct
29 Correct 17 ms 368 KB Output is correct
30 Correct 22 ms 336 KB Output is correct
31 Correct 32 ms 584 KB Output is correct
32 Correct 80 ms 732 KB Output is correct
33 Incorrect 56 ms 876 KB Wrong Answer [2]
34 Halted 0 ms 0 KB -