#include<bits/stdc++.h>
#include "xylophone.h"
#define ll int
//#define int long long
#define ld long double
#define cd complex<ld>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pld pair<ld,ld>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std ;
ll n ;
ll A[100005] ;
bool check[100005] ;
ll find_one()
{
ll lo = 1 , hi = n-1 , mid ;
while(hi-lo>1)
{
mid = ((hi+lo)>>1) ;
if(query(mid , n)==n-1)
{
lo = mid ;
}
else
{
hi = mid ;
}
}
if(query(hi , n)==n-1) return hi ;
else return lo ;
}
void solve(int m)
{
n = m ;
ll val = find_one() ;
A[val] = 1 ;
check[1] = 1 ;
for(int i = val+1 ; i<= n ; i++)
{
if(i==val+1)
{
A[i] = A[i-1]+query(i-1 , i) ;
}
else
{
ll k = query(i-1 , i) ;
if(k+A[i-1]>n)
{
A[i] = A[i-1]-k ;
}
else if(A[i-1]-k<=0)
{
A[i] = A[i-1]+k ;
}
else if(check[A[i-1]-k])
{
A[i] = A[i-1]+k ;
}
else if(check[A[i-1]+k])
{
A[i] = A[i-1]-k ;
}
else
{
ll q = query(i-2 , i) ;
if(A[i-2]<A[i-1])
{
if(A[i-1]-A[i-2]!=q)
{
if(k+A[i-1]-A[i-2]==q)
{
A[i] = A[i-1]+k ;
}
else
{
A[i] = A[i-1]-k ;
}
}
else
{
A[i] = A[i-1]-k ;
}
}
else
{
if(A[i-2]-A[i-1]!=q)
{
if(k+A[i-2]-A[i-1]==q)
{
A[i] = A[i-1]-k ;
}
else
{
A[i] = A[i-1]+k ;
}
}
else
{
A[i] = A[i-1]+k ;
}
}
}
}
check[A[i]] = 1 ;
}
for(int i = val-1 ; i>= 1 ; i--)
{
if(i==val-1)
{
A[i] = A[i+1] + query(i , i+1) ;
}
else
{
ll k = query(i , i+1) ;
if(k+A[i+1]>n)
{
A[i] = A[i+1]-k ;
}
else if(A[i+1]-k<=0)
{
A[i] = A[i+1]+k;
}
else if(check[A[i+1]-k])
{
A[i] = A[i+1]+k ;
}
else if(check[A[i+1]+k])
{
A[i] = A[i+1]-k ;
}
else
{
ll q = query(i , i+2) ;
if(A[i+2]<A[i+1])
{
if(A[i+1]-A[i+2]!=q)
{
if(k+A[i+1]-A[i+2]==q)
{
A[i] = A[i+1]+k ;
}
else
{
A[i] = A[i+1]-k ;
}
}
else
{
A[i] = A[i+1]-k ;
}
}
else
{
if(A[i+2]-A[i+1]!=q)
{
if(k+A[i+2]-A[i+1]==q)
{
A[i] = A[i+1]-k ;
}
else
{
A[i] = A[i+1]+k ;
}
}
else
{
A[i] = A[i+1]+k ;
}
}
}
}
check[A[i]] = 1;
}
for(int i = 1; i<= n ; i++) answer(i , A[i]) ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
216 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
2 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
216 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
2 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
7 ms |
308 KB |
Output is correct |
18 |
Correct |
8 ms |
312 KB |
Output is correct |
19 |
Correct |
11 ms |
208 KB |
Output is correct |
20 |
Correct |
14 ms |
288 KB |
Output is correct |
21 |
Correct |
11 ms |
208 KB |
Output is correct |
22 |
Correct |
9 ms |
312 KB |
Output is correct |
23 |
Correct |
11 ms |
208 KB |
Output is correct |
24 |
Correct |
9 ms |
208 KB |
Output is correct |
25 |
Correct |
8 ms |
312 KB |
Output is correct |
26 |
Correct |
10 ms |
208 KB |
Output is correct |
27 |
Correct |
10 ms |
304 KB |
Output is correct |
28 |
Correct |
10 ms |
208 KB |
Output is correct |
29 |
Correct |
8 ms |
208 KB |
Output is correct |
30 |
Correct |
11 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
216 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
2 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
7 ms |
308 KB |
Output is correct |
18 |
Correct |
8 ms |
312 KB |
Output is correct |
19 |
Correct |
11 ms |
208 KB |
Output is correct |
20 |
Correct |
14 ms |
288 KB |
Output is correct |
21 |
Correct |
11 ms |
208 KB |
Output is correct |
22 |
Correct |
9 ms |
312 KB |
Output is correct |
23 |
Correct |
11 ms |
208 KB |
Output is correct |
24 |
Correct |
9 ms |
208 KB |
Output is correct |
25 |
Correct |
8 ms |
312 KB |
Output is correct |
26 |
Correct |
10 ms |
208 KB |
Output is correct |
27 |
Correct |
10 ms |
304 KB |
Output is correct |
28 |
Correct |
10 ms |
208 KB |
Output is correct |
29 |
Correct |
8 ms |
208 KB |
Output is correct |
30 |
Correct |
11 ms |
300 KB |
Output is correct |
31 |
Correct |
36 ms |
336 KB |
Output is correct |
32 |
Correct |
32 ms |
304 KB |
Output is correct |
33 |
Correct |
42 ms |
328 KB |
Output is correct |
34 |
Correct |
59 ms |
428 KB |
Output is correct |
35 |
Correct |
53 ms |
312 KB |
Output is correct |
36 |
Correct |
38 ms |
304 KB |
Output is correct |
37 |
Correct |
38 ms |
328 KB |
Output is correct |
38 |
Correct |
33 ms |
316 KB |
Output is correct |
39 |
Correct |
32 ms |
308 KB |
Output is correct |
40 |
Correct |
56 ms |
328 KB |
Output is correct |
41 |
Correct |
61 ms |
328 KB |
Output is correct |
42 |
Correct |
47 ms |
312 KB |
Output is correct |
43 |
Correct |
49 ms |
300 KB |
Output is correct |
44 |
Correct |
40 ms |
320 KB |
Output is correct |
45 |
Correct |
37 ms |
316 KB |
Output is correct |
46 |
Correct |
42 ms |
308 KB |
Output is correct |
47 |
Correct |
61 ms |
308 KB |
Output is correct |
48 |
Correct |
61 ms |
420 KB |
Output is correct |
49 |
Correct |
34 ms |
300 KB |
Output is correct |
50 |
Correct |
56 ms |
428 KB |
Output is correct |
51 |
Correct |
65 ms |
308 KB |
Output is correct |
52 |
Correct |
50 ms |
312 KB |
Output is correct |
53 |
Correct |
56 ms |
308 KB |
Output is correct |
54 |
Correct |
63 ms |
296 KB |
Output is correct |
55 |
Correct |
54 ms |
296 KB |
Output is correct |
56 |
Correct |
64 ms |
316 KB |
Output is correct |
57 |
Correct |
60 ms |
304 KB |
Output is correct |
58 |
Correct |
46 ms |
328 KB |
Output is correct |
59 |
Correct |
58 ms |
316 KB |
Output is correct |
60 |
Correct |
62 ms |
316 KB |
Output is correct |