#include "xylophone.h"
#include<bits/stdc++.h>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define st first
#define nd second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long lo;
const int mod=1000000007,N=500005;
lo a,b,c,d,e,f,g=1,h[N];
pair<lo,lo>arr[N];
string s;
vector<lo>v;
// int query(int a,int b){ }
// void answer(int a,int b){ }
void solve(int n){
for(lo i=1;i<n;i++){
arr[i].st=query(i,i+1);
if(i<n-1)arr[i].nd=query(i,i+2);
}
h[1]=1;
for(lo i=1;i<=n-2;i++){
if(arr[i].st+arr[i+1].st==arr[i].nd)h[i+1]=h[i];
else h[i+1]=(h[i]^1);
}
lo sum=0;
pair<lo,lo>mx={0,1},mn={0,1};
for(lo i=1;i<n;i++){
if(h[i]==0)sum-=arr[i].st;
else sum+=arr[i].st;
if(mx.st<sum)mx={sum,i+1};
if(mn.st>sum)mn={sum,i+1};
}
if(mx.nd>mn.nd){
lo hehe=n-mx.st;
answer(1,hehe);
for(lo i=1;i<n;i++){
hehe+=arr[i].st*(h[i]==0?-1:1);
answer(i+1,hehe);
}
return;
}
h[1]=0;
sum=0;
lo mxi=0;
for(lo i=1;i<=n-2;i++){
if(arr[i].st+arr[i+1].st==arr[i].nd)h[i+1]=h[i];
else h[i+1]=(h[i]^1);
}
for(lo i=1;i<n;i++){
if(h[i]==0)sum-=arr[i].st;
else sum+=arr[i].st;
mxi=max(sum,mxi);
}
lo hehe=n-mxi;
answer(1,hehe);
for(lo i=1;i<n;i++){
hehe+=arr[i].st*(h[i]==0?-1:1);
answer(i+1,hehe);
}
}
// int main(){
// #ifdef local
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// #endif
// ios_base::sync_with_stdio(false);
// cin.tie(NULL); cout.tie(NULL);
// // cin >> g;
// // while(g--)solve();
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
10 ms |
384 KB |
Output is correct |
18 |
Correct |
12 ms |
504 KB |
Output is correct |
19 |
Correct |
21 ms |
384 KB |
Output is correct |
20 |
Correct |
17 ms |
384 KB |
Output is correct |
21 |
Correct |
22 ms |
384 KB |
Output is correct |
22 |
Correct |
17 ms |
384 KB |
Output is correct |
23 |
Correct |
22 ms |
376 KB |
Output is correct |
24 |
Correct |
15 ms |
380 KB |
Output is correct |
25 |
Correct |
22 ms |
412 KB |
Output is correct |
26 |
Correct |
16 ms |
384 KB |
Output is correct |
27 |
Correct |
13 ms |
504 KB |
Output is correct |
28 |
Correct |
16 ms |
384 KB |
Output is correct |
29 |
Correct |
17 ms |
384 KB |
Output is correct |
30 |
Correct |
17 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
10 ms |
384 KB |
Output is correct |
18 |
Correct |
12 ms |
504 KB |
Output is correct |
19 |
Correct |
21 ms |
384 KB |
Output is correct |
20 |
Correct |
17 ms |
384 KB |
Output is correct |
21 |
Correct |
22 ms |
384 KB |
Output is correct |
22 |
Correct |
17 ms |
384 KB |
Output is correct |
23 |
Correct |
22 ms |
376 KB |
Output is correct |
24 |
Correct |
15 ms |
380 KB |
Output is correct |
25 |
Correct |
22 ms |
412 KB |
Output is correct |
26 |
Correct |
16 ms |
384 KB |
Output is correct |
27 |
Correct |
13 ms |
504 KB |
Output is correct |
28 |
Correct |
16 ms |
384 KB |
Output is correct |
29 |
Correct |
17 ms |
384 KB |
Output is correct |
30 |
Correct |
17 ms |
504 KB |
Output is correct |
31 |
Correct |
43 ms |
380 KB |
Output is correct |
32 |
Correct |
57 ms |
384 KB |
Output is correct |
33 |
Correct |
65 ms |
504 KB |
Output is correct |
34 |
Correct |
86 ms |
504 KB |
Output is correct |
35 |
Correct |
105 ms |
504 KB |
Output is correct |
36 |
Correct |
91 ms |
500 KB |
Output is correct |
37 |
Correct |
91 ms |
504 KB |
Output is correct |
38 |
Correct |
98 ms |
504 KB |
Output is correct |
39 |
Correct |
94 ms |
504 KB |
Output is correct |
40 |
Correct |
99 ms |
504 KB |
Output is correct |
41 |
Correct |
97 ms |
676 KB |
Output is correct |
42 |
Correct |
95 ms |
504 KB |
Output is correct |
43 |
Correct |
92 ms |
504 KB |
Output is correct |
44 |
Correct |
91 ms |
504 KB |
Output is correct |
45 |
Correct |
93 ms |
508 KB |
Output is correct |
46 |
Correct |
102 ms |
504 KB |
Output is correct |
47 |
Correct |
77 ms |
676 KB |
Output is correct |
48 |
Correct |
100 ms |
504 KB |
Output is correct |
49 |
Correct |
103 ms |
504 KB |
Output is correct |
50 |
Correct |
92 ms |
528 KB |
Output is correct |
51 |
Correct |
99 ms |
504 KB |
Output is correct |
52 |
Correct |
95 ms |
436 KB |
Output is correct |
53 |
Correct |
88 ms |
504 KB |
Output is correct |
54 |
Correct |
89 ms |
508 KB |
Output is correct |
55 |
Correct |
99 ms |
504 KB |
Output is correct |
56 |
Correct |
94 ms |
504 KB |
Output is correct |
57 |
Correct |
63 ms |
524 KB |
Output is correct |
58 |
Correct |
93 ms |
504 KB |
Output is correct |
59 |
Correct |
88 ms |
524 KB |
Output is correct |
60 |
Correct |
98 ms |
508 KB |
Output is correct |