#include "xylophone.h"
#include <vector>
#include <iostream>
using namespace std;
/*
5
2 1 5 3 4
10
7 6 3 9 2 8 5 1 10 4
*/
void solve(int N) {
int K = query(1,N);
int minIndex;{
int m, k;
int left, right;
left = 1;
right = N-1;
while(left != right){
m = (left+right)/2+1;
k = query(m, N);
if(k == K) left = m;
else right = m-1;
}
minIndex = left;
}
vector<bool> UsedNumbers(N+1, false);
vector<int> kVtr(N+1);
for(int i = 2; i <= N; ++i)
kVtr[i] = query(i-1,i);
vector<int> Solution(N+1);
Solution[minIndex] = 1;
UsedNumbers[Solution[minIndex]] = true;
Solution[minIndex+1] = Solution[minIndex] + kVtr[minIndex+1];
UsedNumbers[Solution[minIndex+1]] = true;
if(minIndex != 1){
Solution[minIndex-1] = Solution[minIndex] + kVtr[minIndex];
UsedNumbers[Solution[minIndex+1]] = true;
}
int k, kM, km, k_;
///After minIndex
for(int i = minIndex+2; i <= N; ++i){
k = kVtr[i];
kM = Solution[i-1] + k;
km = Solution[i-1] - k;
if((km < 1) || (UsedNumbers[km])){Solution[i] = kM; continue;}
if((kM > N) || (UsedNumbers[kM])){Solution[i] = km; continue;}
k_ = query(i-2,i);
Solution[i] = Solution[i-1];
if(Solution[i-2] < Solution[i-1]){ ///^
if(kVtr[i-1]+kVtr[i] == k_) Solution[i] += k; ///^^
else Solution[i] -= k; ///^v
}else{ ///v
if(kVtr[i-1]+kVtr[i] == k_) Solution[i] -= k; ///vv
else Solution[i] += k; ///v^
}
UsedNumbers[Solution[i]] = true;
}
///Before minIndex
for(int i = minIndex-2; i >= 1; --i){
k = kVtr[i+1];
kM = Solution[i+1] + k;
km = Solution[i+1] - k;
if((km < 1) || (UsedNumbers[km])){Solution[i] = kM; continue;}
if((kM > N) || (UsedNumbers[kM])){Solution[i] = km; continue;}
k_ = query(i,i+2);
Solution[i] = Solution[i+1];
if(Solution[i+1] < Solution[i+2]){ ///v
if(kVtr[i+1]+kVtr[i+2] == k_)
Solution[i] -= k; ///vv
else
Solution[i] += k; ///v^
}else{ ///^
if(kVtr[i+1]+kVtr[i+2] == k_)
Solution[i] += k; ///^^
else
Solution[i] -= k; ///^v
}
}
// cout << "minindex=" << minIndex << " maxindex=" << maxIndex << endl;
// cout << "Solution:" << endl;
// for(int i = 1; i <= N; ++i)
// cout << Solution[i] << " ";
// cout << endl;
for(int i = 1; i <= N; i++)
answer(i, Solution[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
436 KB |
Output is correct |
3 |
Correct |
3 ms |
516 KB |
Output is correct |
4 |
Correct |
4 ms |
516 KB |
Output is correct |
5 |
Correct |
5 ms |
596 KB |
Output is correct |
6 |
Correct |
4 ms |
596 KB |
Output is correct |
7 |
Correct |
4 ms |
596 KB |
Output is correct |
8 |
Correct |
4 ms |
596 KB |
Output is correct |
9 |
Correct |
4 ms |
596 KB |
Output is correct |
10 |
Correct |
5 ms |
596 KB |
Output is correct |
11 |
Correct |
4 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
596 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
436 KB |
Output is correct |
3 |
Correct |
3 ms |
516 KB |
Output is correct |
4 |
Correct |
4 ms |
516 KB |
Output is correct |
5 |
Correct |
5 ms |
596 KB |
Output is correct |
6 |
Correct |
4 ms |
596 KB |
Output is correct |
7 |
Correct |
4 ms |
596 KB |
Output is correct |
8 |
Correct |
4 ms |
596 KB |
Output is correct |
9 |
Correct |
4 ms |
596 KB |
Output is correct |
10 |
Correct |
5 ms |
596 KB |
Output is correct |
11 |
Correct |
4 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
596 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
596 KB |
Output is correct |
16 |
Correct |
6 ms |
596 KB |
Output is correct |
17 |
Correct |
10 ms |
596 KB |
Output is correct |
18 |
Correct |
12 ms |
596 KB |
Output is correct |
19 |
Correct |
17 ms |
596 KB |
Output is correct |
20 |
Correct |
21 ms |
596 KB |
Output is correct |
21 |
Correct |
8 ms |
596 KB |
Output is correct |
22 |
Correct |
15 ms |
596 KB |
Output is correct |
23 |
Correct |
20 ms |
596 KB |
Output is correct |
24 |
Correct |
19 ms |
596 KB |
Output is correct |
25 |
Correct |
15 ms |
596 KB |
Output is correct |
26 |
Correct |
18 ms |
596 KB |
Output is correct |
27 |
Correct |
13 ms |
596 KB |
Output is correct |
28 |
Correct |
21 ms |
596 KB |
Output is correct |
29 |
Correct |
23 ms |
596 KB |
Output is correct |
30 |
Correct |
14 ms |
700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
436 KB |
Output is correct |
3 |
Correct |
3 ms |
516 KB |
Output is correct |
4 |
Correct |
4 ms |
516 KB |
Output is correct |
5 |
Correct |
5 ms |
596 KB |
Output is correct |
6 |
Correct |
4 ms |
596 KB |
Output is correct |
7 |
Correct |
4 ms |
596 KB |
Output is correct |
8 |
Correct |
4 ms |
596 KB |
Output is correct |
9 |
Correct |
4 ms |
596 KB |
Output is correct |
10 |
Correct |
5 ms |
596 KB |
Output is correct |
11 |
Correct |
4 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
596 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
596 KB |
Output is correct |
16 |
Correct |
6 ms |
596 KB |
Output is correct |
17 |
Correct |
10 ms |
596 KB |
Output is correct |
18 |
Correct |
12 ms |
596 KB |
Output is correct |
19 |
Correct |
17 ms |
596 KB |
Output is correct |
20 |
Correct |
21 ms |
596 KB |
Output is correct |
21 |
Correct |
8 ms |
596 KB |
Output is correct |
22 |
Correct |
15 ms |
596 KB |
Output is correct |
23 |
Correct |
20 ms |
596 KB |
Output is correct |
24 |
Correct |
19 ms |
596 KB |
Output is correct |
25 |
Correct |
15 ms |
596 KB |
Output is correct |
26 |
Correct |
18 ms |
596 KB |
Output is correct |
27 |
Correct |
13 ms |
596 KB |
Output is correct |
28 |
Correct |
21 ms |
596 KB |
Output is correct |
29 |
Correct |
23 ms |
596 KB |
Output is correct |
30 |
Correct |
14 ms |
700 KB |
Output is correct |
31 |
Correct |
15 ms |
700 KB |
Output is correct |
32 |
Correct |
23 ms |
700 KB |
Output is correct |
33 |
Correct |
61 ms |
700 KB |
Output is correct |
34 |
Correct |
64 ms |
700 KB |
Output is correct |
35 |
Correct |
81 ms |
700 KB |
Output is correct |
36 |
Correct |
75 ms |
700 KB |
Output is correct |
37 |
Correct |
74 ms |
700 KB |
Output is correct |
38 |
Correct |
80 ms |
700 KB |
Output is correct |
39 |
Correct |
36 ms |
700 KB |
Output is correct |
40 |
Correct |
34 ms |
700 KB |
Output is correct |
41 |
Correct |
39 ms |
700 KB |
Output is correct |
42 |
Correct |
89 ms |
700 KB |
Output is correct |
43 |
Correct |
73 ms |
700 KB |
Output is correct |
44 |
Correct |
99 ms |
700 KB |
Output is correct |
45 |
Correct |
80 ms |
700 KB |
Output is correct |
46 |
Correct |
96 ms |
700 KB |
Output is correct |
47 |
Correct |
102 ms |
700 KB |
Output is correct |
48 |
Correct |
61 ms |
720 KB |
Output is correct |
49 |
Correct |
99 ms |
720 KB |
Output is correct |
50 |
Correct |
92 ms |
720 KB |
Output is correct |
51 |
Correct |
85 ms |
720 KB |
Output is correct |
52 |
Correct |
67 ms |
720 KB |
Output is correct |
53 |
Correct |
66 ms |
720 KB |
Output is correct |
54 |
Correct |
59 ms |
720 KB |
Output is correct |
55 |
Correct |
55 ms |
720 KB |
Output is correct |
56 |
Correct |
31 ms |
720 KB |
Output is correct |
57 |
Correct |
65 ms |
720 KB |
Output is correct |
58 |
Correct |
78 ms |
720 KB |
Output is correct |
59 |
Correct |
31 ms |
720 KB |
Output is correct |
60 |
Correct |
83 ms |
720 KB |
Output is correct |