Submission #958309

# Submission time Handle Problem Language Result Execution time Memory
958309 2024-04-05T11:19:05 Z JwFXoiz Xylophone (JOI18_xylophone) C++14
47 / 100
64 ms 98512 KB
#include <bits/stdc++.h>
#include "xylophone.h"

using namespace std;

int a[5001], qq[5001][5001];

int ask(int l, int r)
{
	if (qq[l][r] != -1) return qq[l][r];
	return qq[l][r] = query(l, r);
}

void calc(int l, int r, int f, int up)
{
	if (r - l <= 1) return;
	if (!f)
	{
		int x = ask(l + 1, r);
		int lx = l + 1, rx = r - 1;
		while (lx < rx)
		{
			int mid = (lx + rx + 1) >> 1;
			int y = ask(mid, r);
			if (x == y) lx = mid;
			else rx = mid - 1;
		}
		if (up) a[lx] = a[r] + x;
		else a[lx] = a[r] - x;
		calc(l, lx, 0, up ^ 1), calc(lx, r, 0, up);
	}
	else
	{
		int x = ask(l, r - 1);
		int lx = l + 1, rx = r - 1;
		while (lx < rx)
		{
			int mid = (lx + rx) >> 1;
			int y = ask(l, mid);
			if (x == y) rx = mid;
			else lx = mid + 1;
		}
		if (up) a[lx] = a[l] + x;
		else a[lx] = a[l] - x;
		calc(l, lx, 1, up), calc(lx, r, 1, up ^ 1);
	}
}

void solve(int N)
{
	for (int i = 0; i <= N; i++) for (int j = 0; j <= N; j++) qq[i][j] = -1;
	int l = 1, r = N;
	while (l < r)
	{
		int mid = (l + r + 1) >> 1;
		if (ask(mid, N) == N - 1) l = mid;
		else r = mid - 1;
	}
	a[l] = 1;
	calc(0, l, 0, 1), calc(l, N + 1, 1, 1);
	for (int i = 1; i <= N; i++) 
	{
		answer(i, a[i]);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 456 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 1 ms 2532 KB Output is correct
4 Correct 2 ms 2532 KB Output is correct
5 Correct 3 ms 2540 KB Output is correct
6 Correct 1 ms 2528 KB Output is correct
7 Correct 1 ms 2536 KB Output is correct
8 Correct 1 ms 2524 KB Output is correct
9 Correct 1 ms 2532 KB Output is correct
10 Correct 4 ms 2648 KB Output is correct
11 Correct 2 ms 2528 KB Output is correct
12 Correct 1 ms 2532 KB Output is correct
13 Correct 1 ms 2528 KB Output is correct
14 Correct 2 ms 2524 KB Output is correct
15 Correct 1 ms 2784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 456 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 1 ms 2532 KB Output is correct
4 Correct 2 ms 2532 KB Output is correct
5 Correct 3 ms 2540 KB Output is correct
6 Correct 1 ms 2528 KB Output is correct
7 Correct 1 ms 2536 KB Output is correct
8 Correct 1 ms 2524 KB Output is correct
9 Correct 1 ms 2532 KB Output is correct
10 Correct 4 ms 2648 KB Output is correct
11 Correct 2 ms 2528 KB Output is correct
12 Correct 1 ms 2532 KB Output is correct
13 Correct 1 ms 2528 KB Output is correct
14 Correct 2 ms 2524 KB Output is correct
15 Correct 1 ms 2784 KB Output is correct
16 Correct 3 ms 6640 KB Output is correct
17 Correct 7 ms 10748 KB Output is correct
18 Correct 9 ms 17172 KB Output is correct
19 Correct 12 ms 21084 KB Output is correct
20 Correct 15 ms 21024 KB Output is correct
21 Correct 12 ms 21036 KB Output is correct
22 Correct 12 ms 21292 KB Output is correct
23 Correct 6 ms 21544 KB Output is correct
24 Correct 49 ms 21860 KB Output is correct
25 Correct 57 ms 21028 KB Output is correct
26 Correct 14 ms 21288 KB Output is correct
27 Correct 14 ms 21284 KB Output is correct
28 Correct 13 ms 21032 KB Output is correct
29 Correct 10 ms 21292 KB Output is correct
30 Correct 12 ms 21036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 456 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 1 ms 2532 KB Output is correct
4 Correct 2 ms 2532 KB Output is correct
5 Correct 3 ms 2540 KB Output is correct
6 Correct 1 ms 2528 KB Output is correct
7 Correct 1 ms 2536 KB Output is correct
8 Correct 1 ms 2524 KB Output is correct
9 Correct 1 ms 2532 KB Output is correct
10 Correct 4 ms 2648 KB Output is correct
11 Correct 2 ms 2528 KB Output is correct
12 Correct 1 ms 2532 KB Output is correct
13 Correct 1 ms 2528 KB Output is correct
14 Correct 2 ms 2524 KB Output is correct
15 Correct 1 ms 2784 KB Output is correct
16 Correct 3 ms 6640 KB Output is correct
17 Correct 7 ms 10748 KB Output is correct
18 Correct 9 ms 17172 KB Output is correct
19 Correct 12 ms 21084 KB Output is correct
20 Correct 15 ms 21024 KB Output is correct
21 Correct 12 ms 21036 KB Output is correct
22 Correct 12 ms 21292 KB Output is correct
23 Correct 6 ms 21544 KB Output is correct
24 Correct 49 ms 21860 KB Output is correct
25 Correct 57 ms 21028 KB Output is correct
26 Correct 14 ms 21288 KB Output is correct
27 Correct 14 ms 21284 KB Output is correct
28 Correct 13 ms 21032 KB Output is correct
29 Correct 10 ms 21292 KB Output is correct
30 Correct 12 ms 21036 KB Output is correct
31 Correct 26 ms 43884 KB Output is correct
32 Correct 35 ms 62144 KB Output is correct
33 Correct 64 ms 87304 KB Output is correct
34 Incorrect 63 ms 98512 KB Wrong Answer [2]
35 Halted 0 ms 0 KB -