#include<bits/stdc++.h>
#include "xylophone.h"
#define ll int
using namespace std;
ll a[100005];
bool seen[100005];
ll calc(ll a, ll b, ll dis1, ll dis2)
{
if (a<b)
{
if (dis1==dis2 || dis2==b-a)
return a+dis1;
return a-dis1;
}
if (dis1==dis2 || dis2==a-b)
return a-dis1;
return a+dis1;
}
void solve(ll n)
{
// freopen("output.txt", "w", stdout);
ll L=1, R=n;
ll lo=L, hi=R, val=query(lo, hi);
while (hi-lo>1)
{
ll mid=(hi+lo)/2;
if (query(L, mid)!=val)
lo=mid;
else hi=mid;
}
if (query(L, lo)!=val)
R=hi;
else R=lo;
lo=L, hi=R;
while (hi-lo>1)
{
ll mid=(hi+lo)/2;
if (query(mid, R)!=val)
hi=mid;
else lo=mid;
}
if (query(hi, R)!=val)
L=lo;
else R=hi;
a[L]=1; a[R]=n;
// cout << L << " " << R << "\n";
if (L>1) a[L-1]=a[L]+query(L-1, L);
a[L+1]=a[L]+query(L, L+1);
if (R<n) a[R+1]=a[R]-query(R, R+1);
for (ll i=L-2; i>=1; i--)
{
ll val=query(i, i+1);
if (a[i+1]-val<0 || seen[a[i+1]-val])
a[i]=a[i+1]+val;
else if (a[i+1]+val>n || seen[a[i+1]+val])
a[i]=a[i+1]-val;
else
a[i]=calc(a[i+1], a[i+2], val, query(i, i+2));
seen[a[i]]=1;
}
for (ll i=L+2; i<R; i++)
{
ll val=query(i-1, i);
if (a[i-1]-val<0 || seen[a[i-1]-val])
a[i]=a[i-1]+val;
else if (a[i-1]+val>n || seen[a[i-1]+val])
a[i]=a[i-1]-val;
else
a[i]=calc(a[i-1], a[i-2], val, query(i-2, i));
seen[a[i]]=1;
}
for (ll i=R+2; i<=n; i++)
{
ll val=query(i-1, i);
if (a[i-1]-val<0 || seen[a[i-1]-val])
a[i]=a[i-1]+val;
else if (a[i-1]+val>n || seen[a[i-1]+val])
a[i]=a[i-1]-val;
else
a[i]=calc(a[i-1], a[i-2], val, query(i-2, i));
seen[a[i]]=1;
}
// for (ll i=1; i<=n; i++)
// cout << a[i] << " ";
// cout << "\n";
for (ll i=1; i<=n; i++)
answer(i, a[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
312 KB |
Output is correct |
14 |
Correct |
2 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
312 KB |
Output is correct |
14 |
Correct |
2 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
7 ms |
308 KB |
Output is correct |
18 |
Correct |
10 ms |
208 KB |
Output is correct |
19 |
Correct |
13 ms |
296 KB |
Output is correct |
20 |
Correct |
12 ms |
292 KB |
Output is correct |
21 |
Correct |
14 ms |
208 KB |
Output is correct |
22 |
Correct |
11 ms |
308 KB |
Output is correct |
23 |
Correct |
10 ms |
320 KB |
Output is correct |
24 |
Correct |
15 ms |
292 KB |
Output is correct |
25 |
Correct |
11 ms |
308 KB |
Output is correct |
26 |
Correct |
11 ms |
312 KB |
Output is correct |
27 |
Correct |
12 ms |
316 KB |
Output is correct |
28 |
Correct |
12 ms |
300 KB |
Output is correct |
29 |
Correct |
13 ms |
208 KB |
Output is correct |
30 |
Correct |
12 ms |
292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
312 KB |
Output is correct |
14 |
Correct |
2 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
7 ms |
308 KB |
Output is correct |
18 |
Correct |
10 ms |
208 KB |
Output is correct |
19 |
Correct |
13 ms |
296 KB |
Output is correct |
20 |
Correct |
12 ms |
292 KB |
Output is correct |
21 |
Correct |
14 ms |
208 KB |
Output is correct |
22 |
Correct |
11 ms |
308 KB |
Output is correct |
23 |
Correct |
10 ms |
320 KB |
Output is correct |
24 |
Correct |
15 ms |
292 KB |
Output is correct |
25 |
Correct |
11 ms |
308 KB |
Output is correct |
26 |
Correct |
11 ms |
312 KB |
Output is correct |
27 |
Correct |
12 ms |
316 KB |
Output is correct |
28 |
Correct |
12 ms |
300 KB |
Output is correct |
29 |
Correct |
13 ms |
208 KB |
Output is correct |
30 |
Correct |
12 ms |
292 KB |
Output is correct |
31 |
Correct |
22 ms |
208 KB |
Output is correct |
32 |
Correct |
37 ms |
312 KB |
Output is correct |
33 |
Correct |
41 ms |
312 KB |
Output is correct |
34 |
Correct |
35 ms |
328 KB |
Output is correct |
35 |
Correct |
47 ms |
312 KB |
Output is correct |
36 |
Correct |
51 ms |
316 KB |
Output is correct |
37 |
Correct |
33 ms |
308 KB |
Output is correct |
38 |
Correct |
47 ms |
304 KB |
Output is correct |
39 |
Correct |
63 ms |
312 KB |
Output is correct |
40 |
Correct |
42 ms |
312 KB |
Output is correct |
41 |
Correct |
51 ms |
328 KB |
Output is correct |
42 |
Correct |
49 ms |
316 KB |
Output is correct |
43 |
Correct |
50 ms |
324 KB |
Output is correct |
44 |
Correct |
25 ms |
320 KB |
Output is correct |
45 |
Correct |
40 ms |
312 KB |
Output is correct |
46 |
Correct |
57 ms |
320 KB |
Output is correct |
47 |
Correct |
62 ms |
308 KB |
Output is correct |
48 |
Correct |
55 ms |
320 KB |
Output is correct |
49 |
Correct |
54 ms |
328 KB |
Output is correct |
50 |
Correct |
55 ms |
308 KB |
Output is correct |
51 |
Correct |
51 ms |
436 KB |
Output is correct |
52 |
Correct |
55 ms |
428 KB |
Output is correct |
53 |
Correct |
63 ms |
316 KB |
Output is correct |
54 |
Correct |
48 ms |
316 KB |
Output is correct |
55 |
Correct |
54 ms |
328 KB |
Output is correct |
56 |
Correct |
58 ms |
312 KB |
Output is correct |
57 |
Correct |
55 ms |
320 KB |
Output is correct |
58 |
Correct |
53 ms |
316 KB |
Output is correct |
59 |
Correct |
52 ms |
312 KB |
Output is correct |
60 |
Correct |
39 ms |
328 KB |
Output is correct |