#include "xylophone.h"
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
static int A[5000];
#define maxn 5005
int a[maxn];
map<pii,int> mp;
int get(int l,int r){
if(mp.count({l,r})) return mp[{l,r}];
return mp[{l,r}] = query(l,r);
}
bool vis[maxn];
void solve(int N) {
int n = N;
a[1] = 0;
a[2] = get(1,2);
for(int i = 3;i<=n;i++){
int x = get(i-1,i);
int y = get(i-2,i-1);
int z = get(i-2,i);
if(x+y==z){
if(a[i-1]>=a[i-2]) a[i] = a[i-2] + z;
else a[i] = a[i-2] - z;
}else if(z==x){
if(a[i-1]>=a[i-2]) a[i] = a[i-1] - x;
else a[i] = a[i-1] + x;
}else{
if(a[i-1]>=a[i-2]) a[i] = a[i-1] - x;
else a[i] = a[i-1] + x;
}
}
int mini = llinf;
for(int i = 1;i<=n;i++){
mini = min(mini,a[i]);
}
int idx1,idxn;
for(int i = 1;i<=n;i++){
a[i]-=mini-1;
if(a[i]==1) idx1 = i;
if(a[i]==n) idxn = i;
}
if(idx1>idxn) for(int i = 1;i<=n;i++) a[i] = n-a[i]+1;
if(n<=10) ceri(a,1,n);
for(int i = 1;i<=n;i++) answer(i,a[i]);
}
/*
5
2 1 5 3 4
*/
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:7:15: warning: overflow in conversion from 'long long int' to 'int' changes value from '100000000000000000' to '1569325056' [-Woverflow]
7 | #define llinf 100000000000000000LL // 10^17
| ^~~~~~~~~~~~~~~~~~~~
xylophone.cpp:50:16: note: in expansion of macro 'llinf'
50 | int mini = llinf;
| ^~~~~
xylophone.cpp: At global scope:
xylophone.cpp:21:12: warning: 'A' defined but not used [-Wunused-variable]
21 | static int A[5000];
| ^
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:60:5: warning: 'idxn' may be used uninitialized in this function [-Wmaybe-uninitialized]
60 | if(idx1>idxn) for(int i = 1;i<=n;i++) a[i] = n-a[i]+1;
| ^~
xylophone.cpp:60:5: warning: 'idx1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
3 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
320 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
2 ms |
208 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 |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
3 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
320 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
2 ms |
208 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 |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
320 KB |
Output is correct |
16 |
Correct |
6 ms |
208 KB |
Output is correct |
17 |
Correct |
5 ms |
308 KB |
Output is correct |
18 |
Correct |
15 ms |
388 KB |
Output is correct |
19 |
Correct |
14 ms |
328 KB |
Output is correct |
20 |
Correct |
9 ms |
408 KB |
Output is correct |
21 |
Correct |
14 ms |
356 KB |
Output is correct |
22 |
Correct |
20 ms |
348 KB |
Output is correct |
23 |
Correct |
17 ms |
336 KB |
Output is correct |
24 |
Correct |
22 ms |
336 KB |
Output is correct |
25 |
Correct |
17 ms |
416 KB |
Output is correct |
26 |
Correct |
16 ms |
364 KB |
Output is correct |
27 |
Correct |
15 ms |
376 KB |
Output is correct |
28 |
Correct |
21 ms |
380 KB |
Output is correct |
29 |
Correct |
9 ms |
420 KB |
Output is correct |
30 |
Correct |
16 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
3 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
320 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
2 ms |
208 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 |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
320 KB |
Output is correct |
16 |
Correct |
6 ms |
208 KB |
Output is correct |
17 |
Correct |
5 ms |
308 KB |
Output is correct |
18 |
Correct |
15 ms |
388 KB |
Output is correct |
19 |
Correct |
14 ms |
328 KB |
Output is correct |
20 |
Correct |
9 ms |
408 KB |
Output is correct |
21 |
Correct |
14 ms |
356 KB |
Output is correct |
22 |
Correct |
20 ms |
348 KB |
Output is correct |
23 |
Correct |
17 ms |
336 KB |
Output is correct |
24 |
Correct |
22 ms |
336 KB |
Output is correct |
25 |
Correct |
17 ms |
416 KB |
Output is correct |
26 |
Correct |
16 ms |
364 KB |
Output is correct |
27 |
Correct |
15 ms |
376 KB |
Output is correct |
28 |
Correct |
21 ms |
380 KB |
Output is correct |
29 |
Correct |
9 ms |
420 KB |
Output is correct |
30 |
Correct |
16 ms |
352 KB |
Output is correct |
31 |
Correct |
36 ms |
568 KB |
Output is correct |
32 |
Correct |
55 ms |
804 KB |
Output is correct |
33 |
Correct |
72 ms |
840 KB |
Output is correct |
34 |
Correct |
82 ms |
896 KB |
Output is correct |
35 |
Correct |
82 ms |
1124 KB |
Output is correct |
36 |
Correct |
87 ms |
948 KB |
Output is correct |
37 |
Correct |
74 ms |
864 KB |
Output is correct |
38 |
Correct |
82 ms |
840 KB |
Output is correct |
39 |
Correct |
80 ms |
1124 KB |
Output is correct |
40 |
Correct |
83 ms |
860 KB |
Output is correct |
41 |
Correct |
82 ms |
868 KB |
Output is correct |
42 |
Correct |
88 ms |
864 KB |
Output is correct |
43 |
Correct |
68 ms |
976 KB |
Output is correct |
44 |
Correct |
80 ms |
896 KB |
Output is correct |
45 |
Correct |
83 ms |
940 KB |
Output is correct |
46 |
Correct |
78 ms |
1108 KB |
Output is correct |
47 |
Correct |
98 ms |
956 KB |
Output is correct |
48 |
Correct |
88 ms |
924 KB |
Output is correct |
49 |
Correct |
86 ms |
912 KB |
Output is correct |
50 |
Correct |
80 ms |
940 KB |
Output is correct |
51 |
Correct |
88 ms |
948 KB |
Output is correct |
52 |
Correct |
87 ms |
872 KB |
Output is correct |
53 |
Correct |
61 ms |
980 KB |
Output is correct |
54 |
Correct |
48 ms |
960 KB |
Output is correct |
55 |
Correct |
91 ms |
844 KB |
Output is correct |
56 |
Correct |
84 ms |
916 KB |
Output is correct |
57 |
Correct |
90 ms |
896 KB |
Output is correct |
58 |
Correct |
92 ms |
932 KB |
Output is correct |
59 |
Correct |
83 ms |
848 KB |
Output is correct |
60 |
Correct |
78 ms |
932 KB |
Output is correct |