Submission #1116564

# Submission time Handle Problem Language Result Execution time Memory
1116564 2024-11-21T20:08:55 Z mmk Xylophone (JOI18_xylophone) C++17
47 / 100
196 ms 1748 KB
#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;

int a[5010];

map<pair<int,int>,int> marc;

int q(int ini, int fim)
{
	if(marc[{ini,fim}] != 0)
		return marc[{ini,fim}];
	else
		return marc[{ini,fim}] = query(ini,fim);
}

//resolve o intervalo [ini,menor]
//0 -> fim == menor
//1 -> fim == maior
void solveL(int ini, int fim, int type)
{
	if(ini == fim) return;
	int dif = q(ini,fim);

	if(fim - ini == 1)
	{
		if(type == 0)
			a[ini] = a[fim] + dif;
		else
			a[ini] = a[fim] - dif;
		return;
	}

	int l = ini, r = fim;

	while(l < r)
	{
		int m = (l + r + 1)/2;

		if(q(m,fim) == dif) l = m;
		else r = m-1;
	}

	if(type == 0)
	{
		int maior = l;
		a[maior] = a[fim] + dif;

		solveL(ini,maior,1);
		solveL(maior + 1,fim,0);
	}
	else
	{
		int menor = l;
		a[menor] = a[fim] - dif;

		solveL(ini,menor,0);
		solveL(menor + 1,fim,1);
	}
}

void solveR(int ini, int fim, int type)
{
	if(ini == fim) return;
	int dif = q(ini,fim);

	if(fim - ini == 1)
	{
		if(type == 0)
			a[fim] = a[ini] + dif;
		else
			a[fim] = a[ini] - dif;
		return;
	}

	int l = ini, r = fim;

	while(l < r)
	{
		int m = (l + r - 1)/2;

		if(q(ini,m) == dif) r = m;
		else l = m+1;
		// cerr << l << " " << r << " " << m << "||\n";
	}

	if(type == 0)
	{
		int maior = r;
		a[maior] = a[ini] + dif;

		solveR(ini,maior - 1,0);
		solveR(maior,fim,1);
	}
	else
	{
		int menor = r;
		a[menor] = a[ini] - dif;

		solveR(ini,menor - 1,1);
		solveR(menor,fim,0);
	}
}



void solve(int N)
{
	int l = 1, r = N;

	while(l < r)
	{
		int m = (l + r - 1)/2;

		if(q(1,m) == N - 1) r = m;
		else l = m + 1;
	}

	int maior = r;

	l = 1, r = maior;

	while(l < r)
	{
		int m = (l + r + 1)/2;

		if(q(m,N) == N - 1) l = m;
		else r = m - 1;
	}

	int menor = l;

	a[menor] = 1;
	a[maior] = N;

	// cerr << "penis\n";
	solveL(1,menor,0);
	solveR(menor,maior-1,0);
	solveR(maior,N,1);


	for(int i = 1; i <= N; i++)
	{
		// cerr << i << " " << a[i] << "||\n";
		answer(i,a[i]);
	}


}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 4 ms 336 KB Output is correct
5 Correct 11 ms 336 KB Output is correct
6 Correct 4 ms 336 KB Output is correct
7 Correct 4 ms 508 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 8 ms 336 KB Output is correct
11 Correct 5 ms 592 KB Output is correct
12 Correct 6 ms 448 KB Output is correct
13 Correct 4 ms 336 KB Output is correct
14 Correct 4 ms 336 KB Output is correct
15 Correct 4 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 4 ms 336 KB Output is correct
5 Correct 11 ms 336 KB Output is correct
6 Correct 4 ms 336 KB Output is correct
7 Correct 4 ms 508 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 8 ms 336 KB Output is correct
11 Correct 5 ms 592 KB Output is correct
12 Correct 6 ms 448 KB Output is correct
13 Correct 4 ms 336 KB Output is correct
14 Correct 4 ms 336 KB Output is correct
15 Correct 4 ms 336 KB Output is correct
16 Correct 8 ms 336 KB Output is correct
17 Correct 23 ms 712 KB Output is correct
18 Correct 31 ms 1012 KB Output is correct
19 Correct 29 ms 712 KB Output is correct
20 Correct 36 ms 840 KB Output is correct
21 Correct 31 ms 592 KB Output is correct
22 Correct 35 ms 336 KB Output is correct
23 Correct 19 ms 336 KB Output is correct
24 Correct 196 ms 1748 KB Output is correct
25 Correct 179 ms 1208 KB Output is correct
26 Correct 50 ms 592 KB Output is correct
27 Correct 46 ms 592 KB Output is correct
28 Correct 40 ms 892 KB Output is correct
29 Correct 28 ms 448 KB Output is correct
30 Correct 30 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 4 ms 336 KB Output is correct
5 Correct 11 ms 336 KB Output is correct
6 Correct 4 ms 336 KB Output is correct
7 Correct 4 ms 508 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 8 ms 336 KB Output is correct
11 Correct 5 ms 592 KB Output is correct
12 Correct 6 ms 448 KB Output is correct
13 Correct 4 ms 336 KB Output is correct
14 Correct 4 ms 336 KB Output is correct
15 Correct 4 ms 336 KB Output is correct
16 Correct 8 ms 336 KB Output is correct
17 Correct 23 ms 712 KB Output is correct
18 Correct 31 ms 1012 KB Output is correct
19 Correct 29 ms 712 KB Output is correct
20 Correct 36 ms 840 KB Output is correct
21 Correct 31 ms 592 KB Output is correct
22 Correct 35 ms 336 KB Output is correct
23 Correct 19 ms 336 KB Output is correct
24 Correct 196 ms 1748 KB Output is correct
25 Correct 179 ms 1208 KB Output is correct
26 Correct 50 ms 592 KB Output is correct
27 Correct 46 ms 592 KB Output is correct
28 Correct 40 ms 892 KB Output is correct
29 Correct 28 ms 448 KB Output is correct
30 Correct 30 ms 508 KB Output is correct
31 Correct 87 ms 1296 KB Output is correct
32 Correct 130 ms 1296 KB Output is correct
33 Incorrect 194 ms 1104 KB Wrong Answer [2]
34 Halted 0 ms 0 KB -