#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(a,b) for(int a = 0; a < (b); ++a)
#define all(t) t.begin(), t.end()
#define pb push_back
const int NN = 1e6+54321, INF = 2e9+54321;
const ll INF_L = (ll)2e18+54321;
int A[NN], uz[NN];
void solve(int N)
{
int poczatek = -1, koniec = N;
while(koniec - poczatek > 1)
{
int srodek = (poczatek + koniec) / 2;
if(query(srodek+1,N) == N-1) poczatek = srodek;
else koniec = srodek;
}
//cout << "POCZATEK: " << poczatek << endl;
int idx = poczatek;
A[idx] = 1, uz[1] = 1;
if(idx-1 >= 0) A[idx-1] = 1+query(idx-1+1,idx+1), uz[A[idx-1]] = 1;
if(idx+1 < N) A[idx+1] = 1+query(idx+1,idx+2), uz[A[idx+1]] = 1;
for(int i = idx+2; i < N; ++i)
{
int val = query(i-1+1,i+1), lew = A[i-1]-val, praw = A[i-1]+val;
//cout << "I: " << i << " VAL: " << val << " LEW: " << lew << " PRAW: " << praw << endl;
if(lew < 1 or uz[lew]) A[i] = praw, uz[praw] = 1;
else if(praw > N or uz[praw]) A[i] = lew, uz[lew] = 1;
else
{
//cout << "III: " << i << endl;
int que = query(i-2+1,i+1);
if(A[i-2] < lew)
{
//cout << "III: " << i << " QUE: " << que << " ROZ: " << lew-A[i-2] << endl;
if(A[i-2]+que <= A[i-1]) A[i] = lew, uz[lew] = 1;
else A[i] = praw, uz[praw] = 1;
}
else if(A[i-2] > praw)
{
if(A[i-2]-que >= A[i-1]) A[i] = praw, uz[praw] = 1;
else A[i] = lew, uz[lew] = 1;
}
else if(A[i-2] > lew and A[i-2] < A[i-1])
{
if(que > val) A[i] = praw, uz[praw] = 1;
else A[i] = lew, uz[lew] = 1;
}
else
{
if(que > val) A[i] = lew, uz[lew] = 1;
else A[i] = praw, uz[praw] = 1;
}
}
}
//cout << "T" << endl;
//rep(i,N) cout << A[i] << endl;
//cout << endl;
for(int i = idx-2; i >= 0; --i)
{
int val = query(i+1,i+1+1), lew = A[i+1]-val, praw = A[i+1]+val;
//cout << "I: " << i << " VAL: " << val << " LEW: " << lew << " PRAW: " << praw << endl;
if(lew < 1 or uz[lew]) A[i] = praw, uz[praw] = 1;
else if(praw > N or uz[praw]) A[i] = lew, uz[lew] = 1;
else
{
//cout << "III: " << i << endl;
int que = query(i+1,i+2+1);
if(A[i+2] < lew)
{
//cout << "III: " << i << " QUE: " << que << " ROZ: " << lew-A[i-2] << endl;
if(A[i+2]+que <= A[i+1]) A[i] = lew, uz[lew] = 1;
else A[i] = praw, uz[praw] = 1;
}
else if(A[i+2] > praw)
{
if(A[i+2]-que >= A[i+1]) A[i] = praw, uz[praw] = 1;
else A[i] = lew, uz[lew] = 1;
}
else if(A[i+2] > lew and A[i+2] < A[i+1])
{
if(que > val) A[i] = praw, uz[praw] = 1;
else A[i] = lew, uz[lew] = 1;
}
else
{
if(que > val) A[i] = lew, uz[lew] = 1;
else A[i] = praw, uz[praw] = 1;
}
}
}
//cout << "T" << '\n';
//cout << endl;
//rep(i,N) cout << A[i] << endl;
//cout << endl;
rep(i,N) answer(i+1,A[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2388 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2388 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
2 ms |
2392 KB |
Output is correct |
17 |
Correct |
3 ms |
2392 KB |
Output is correct |
18 |
Correct |
6 ms |
2392 KB |
Output is correct |
19 |
Correct |
8 ms |
2644 KB |
Output is correct |
20 |
Correct |
6 ms |
2392 KB |
Output is correct |
21 |
Correct |
6 ms |
2392 KB |
Output is correct |
22 |
Correct |
6 ms |
2500 KB |
Output is correct |
23 |
Correct |
6 ms |
2648 KB |
Output is correct |
24 |
Correct |
5 ms |
2504 KB |
Output is correct |
25 |
Correct |
5 ms |
2392 KB |
Output is correct |
26 |
Correct |
6 ms |
2392 KB |
Output is correct |
27 |
Correct |
6 ms |
2504 KB |
Output is correct |
28 |
Correct |
6 ms |
2392 KB |
Output is correct |
29 |
Correct |
6 ms |
2492 KB |
Output is correct |
30 |
Correct |
6 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2388 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
2 ms |
2392 KB |
Output is correct |
17 |
Correct |
3 ms |
2392 KB |
Output is correct |
18 |
Correct |
6 ms |
2392 KB |
Output is correct |
19 |
Correct |
8 ms |
2644 KB |
Output is correct |
20 |
Correct |
6 ms |
2392 KB |
Output is correct |
21 |
Correct |
6 ms |
2392 KB |
Output is correct |
22 |
Correct |
6 ms |
2500 KB |
Output is correct |
23 |
Correct |
6 ms |
2648 KB |
Output is correct |
24 |
Correct |
5 ms |
2504 KB |
Output is correct |
25 |
Correct |
5 ms |
2392 KB |
Output is correct |
26 |
Correct |
6 ms |
2392 KB |
Output is correct |
27 |
Correct |
6 ms |
2504 KB |
Output is correct |
28 |
Correct |
6 ms |
2392 KB |
Output is correct |
29 |
Correct |
6 ms |
2492 KB |
Output is correct |
30 |
Correct |
6 ms |
2392 KB |
Output is correct |
31 |
Correct |
9 ms |
2392 KB |
Output is correct |
32 |
Correct |
23 ms |
2480 KB |
Output is correct |
33 |
Correct |
27 ms |
2484 KB |
Output is correct |
34 |
Correct |
32 ms |
2640 KB |
Output is correct |
35 |
Correct |
31 ms |
2644 KB |
Output is correct |
36 |
Correct |
20 ms |
2488 KB |
Output is correct |
37 |
Correct |
24 ms |
2392 KB |
Output is correct |
38 |
Correct |
34 ms |
2392 KB |
Output is correct |
39 |
Correct |
34 ms |
2488 KB |
Output is correct |
40 |
Correct |
31 ms |
2392 KB |
Output is correct |
41 |
Correct |
30 ms |
2512 KB |
Output is correct |
42 |
Correct |
32 ms |
2904 KB |
Output is correct |
43 |
Correct |
26 ms |
2752 KB |
Output is correct |
44 |
Correct |
17 ms |
2488 KB |
Output is correct |
45 |
Correct |
39 ms |
2492 KB |
Output is correct |
46 |
Correct |
21 ms |
2388 KB |
Output is correct |
47 |
Correct |
33 ms |
2488 KB |
Output is correct |
48 |
Correct |
33 ms |
2640 KB |
Output is correct |
49 |
Correct |
37 ms |
2488 KB |
Output is correct |
50 |
Correct |
26 ms |
2488 KB |
Output is correct |
51 |
Correct |
23 ms |
2504 KB |
Output is correct |
52 |
Correct |
24 ms |
2508 KB |
Output is correct |
53 |
Correct |
23 ms |
2488 KB |
Output is correct |
54 |
Correct |
44 ms |
2496 KB |
Output is correct |
55 |
Correct |
39 ms |
2644 KB |
Output is correct |
56 |
Correct |
26 ms |
2392 KB |
Output is correct |
57 |
Correct |
27 ms |
2392 KB |
Output is correct |
58 |
Correct |
35 ms |
2492 KB |
Output is correct |
59 |
Correct |
25 ms |
2392 KB |
Output is correct |
60 |
Correct |
45 ms |
2500 KB |
Output is correct |