# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1116557 |
2024-11-21T19:51:54 Z |
mmk |
Xylophone (JOI18_xylophone) |
C++17 |
|
203 ms |
1760 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);
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);
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 |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
11 ms |
592 KB |
Output is correct |
6 |
Correct |
5 ms |
352 KB |
Output is correct |
7 |
Correct |
5 ms |
448 KB |
Output is correct |
8 |
Correct |
5 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
448 KB |
Output is correct |
10 |
Correct |
10 ms |
592 KB |
Output is correct |
11 |
Correct |
6 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
336 KB |
Output is correct |
13 |
Correct |
5 ms |
448 KB |
Output is correct |
14 |
Correct |
5 ms |
336 KB |
Output is correct |
15 |
Correct |
5 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 |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
11 ms |
592 KB |
Output is correct |
6 |
Correct |
5 ms |
352 KB |
Output is correct |
7 |
Correct |
5 ms |
448 KB |
Output is correct |
8 |
Correct |
5 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
448 KB |
Output is correct |
10 |
Correct |
10 ms |
592 KB |
Output is correct |
11 |
Correct |
6 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
336 KB |
Output is correct |
13 |
Correct |
5 ms |
448 KB |
Output is correct |
14 |
Correct |
5 ms |
336 KB |
Output is correct |
15 |
Correct |
5 ms |
336 KB |
Output is correct |
16 |
Correct |
9 ms |
336 KB |
Output is correct |
17 |
Correct |
25 ms |
752 KB |
Output is correct |
18 |
Correct |
30 ms |
764 KB |
Output is correct |
19 |
Correct |
40 ms |
732 KB |
Output is correct |
20 |
Correct |
45 ms |
712 KB |
Output is correct |
21 |
Correct |
41 ms |
584 KB |
Output is correct |
22 |
Correct |
40 ms |
592 KB |
Output is correct |
23 |
Correct |
19 ms |
336 KB |
Output is correct |
24 |
Correct |
201 ms |
1356 KB |
Output is correct |
25 |
Correct |
169 ms |
1240 KB |
Output is correct |
26 |
Correct |
40 ms |
576 KB |
Output is correct |
27 |
Correct |
55 ms |
724 KB |
Output is correct |
28 |
Correct |
45 ms |
592 KB |
Output is correct |
29 |
Correct |
54 ms |
592 KB |
Output is correct |
30 |
Correct |
44 ms |
744 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 |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
11 ms |
592 KB |
Output is correct |
6 |
Correct |
5 ms |
352 KB |
Output is correct |
7 |
Correct |
5 ms |
448 KB |
Output is correct |
8 |
Correct |
5 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
448 KB |
Output is correct |
10 |
Correct |
10 ms |
592 KB |
Output is correct |
11 |
Correct |
6 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
336 KB |
Output is correct |
13 |
Correct |
5 ms |
448 KB |
Output is correct |
14 |
Correct |
5 ms |
336 KB |
Output is correct |
15 |
Correct |
5 ms |
336 KB |
Output is correct |
16 |
Correct |
9 ms |
336 KB |
Output is correct |
17 |
Correct |
25 ms |
752 KB |
Output is correct |
18 |
Correct |
30 ms |
764 KB |
Output is correct |
19 |
Correct |
40 ms |
732 KB |
Output is correct |
20 |
Correct |
45 ms |
712 KB |
Output is correct |
21 |
Correct |
41 ms |
584 KB |
Output is correct |
22 |
Correct |
40 ms |
592 KB |
Output is correct |
23 |
Correct |
19 ms |
336 KB |
Output is correct |
24 |
Correct |
201 ms |
1356 KB |
Output is correct |
25 |
Correct |
169 ms |
1240 KB |
Output is correct |
26 |
Correct |
40 ms |
576 KB |
Output is correct |
27 |
Correct |
55 ms |
724 KB |
Output is correct |
28 |
Correct |
45 ms |
592 KB |
Output is correct |
29 |
Correct |
54 ms |
592 KB |
Output is correct |
30 |
Correct |
44 ms |
744 KB |
Output is correct |
31 |
Correct |
116 ms |
996 KB |
Output is correct |
32 |
Correct |
152 ms |
1760 KB |
Output is correct |
33 |
Incorrect |
203 ms |
1192 KB |
Wrong Answer [2] |
34 |
Halted |
0 ms |
0 KB |
- |