#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include "xylophone.h"
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e5 + 5, inf = 1e9;
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(int n){
vi ans(n + 1), d1(n + 1), d2(n + 1);
for(int i = 1; i < n; i++)d1[i] = query(i, i + 1);
for(int i = 1; i < n - 1; i++)d2[i] = query(i, i + 2);
ans[1] = 0;
ans[2] = d1[1];
int x = 1;
for(int i = 3; i <= n; i++){
if(d1[i - 2] + d1[i - 1] != d2[i - 2]){
x *= -1;
}
ans[i] = ans[i - 1] + d1[i - 1] * x;
}
int mx = -inf, mxp = -1, mn = inf, mnp = -1;
for(int i = 1; i <= n; i++){
if(ans[i] > mx){
mx = ans[i];
mxp = i;
}
if(ans[i] < mn){
mn = ans[i];
mnp = i;
}
}
if(mxp < mnp){
for(int i = 1; i <= n; i++){
ans[i] = 1 + mx - ans[i];
}
}else{
for(int i = 1; i <= n; i++){
ans[i] = 1 + ans[i] - mn;
}
}
for(int i = 1; i <= n; i++){
answer(i, ans[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
256 KB |
Output is correct |
4 |
Correct |
6 ms |
256 KB |
Output is correct |
5 |
Correct |
7 ms |
256 KB |
Output is correct |
6 |
Correct |
7 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
7 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
7 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
256 KB |
Output is correct |
12 |
Correct |
6 ms |
256 KB |
Output is correct |
13 |
Correct |
6 ms |
384 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
7 ms |
368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
256 KB |
Output is correct |
4 |
Correct |
6 ms |
256 KB |
Output is correct |
5 |
Correct |
7 ms |
256 KB |
Output is correct |
6 |
Correct |
7 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
7 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
7 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
256 KB |
Output is correct |
12 |
Correct |
6 ms |
256 KB |
Output is correct |
13 |
Correct |
6 ms |
384 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
7 ms |
368 KB |
Output is correct |
16 |
Correct |
8 ms |
256 KB |
Output is correct |
17 |
Correct |
16 ms |
416 KB |
Output is correct |
18 |
Correct |
19 ms |
384 KB |
Output is correct |
19 |
Correct |
27 ms |
384 KB |
Output is correct |
20 |
Correct |
23 ms |
256 KB |
Output is correct |
21 |
Correct |
23 ms |
384 KB |
Output is correct |
22 |
Correct |
25 ms |
384 KB |
Output is correct |
23 |
Correct |
23 ms |
384 KB |
Output is correct |
24 |
Correct |
23 ms |
384 KB |
Output is correct |
25 |
Correct |
23 ms |
384 KB |
Output is correct |
26 |
Correct |
21 ms |
384 KB |
Output is correct |
27 |
Correct |
18 ms |
384 KB |
Output is correct |
28 |
Correct |
27 ms |
384 KB |
Output is correct |
29 |
Correct |
21 ms |
384 KB |
Output is correct |
30 |
Correct |
21 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
256 KB |
Output is correct |
4 |
Correct |
6 ms |
256 KB |
Output is correct |
5 |
Correct |
7 ms |
256 KB |
Output is correct |
6 |
Correct |
7 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
7 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
7 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
256 KB |
Output is correct |
12 |
Correct |
6 ms |
256 KB |
Output is correct |
13 |
Correct |
6 ms |
384 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
7 ms |
368 KB |
Output is correct |
16 |
Correct |
8 ms |
256 KB |
Output is correct |
17 |
Correct |
16 ms |
416 KB |
Output is correct |
18 |
Correct |
19 ms |
384 KB |
Output is correct |
19 |
Correct |
27 ms |
384 KB |
Output is correct |
20 |
Correct |
23 ms |
256 KB |
Output is correct |
21 |
Correct |
23 ms |
384 KB |
Output is correct |
22 |
Correct |
25 ms |
384 KB |
Output is correct |
23 |
Correct |
23 ms |
384 KB |
Output is correct |
24 |
Correct |
23 ms |
384 KB |
Output is correct |
25 |
Correct |
23 ms |
384 KB |
Output is correct |
26 |
Correct |
21 ms |
384 KB |
Output is correct |
27 |
Correct |
18 ms |
384 KB |
Output is correct |
28 |
Correct |
27 ms |
384 KB |
Output is correct |
29 |
Correct |
21 ms |
384 KB |
Output is correct |
30 |
Correct |
21 ms |
384 KB |
Output is correct |
31 |
Correct |
45 ms |
384 KB |
Output is correct |
32 |
Correct |
62 ms |
384 KB |
Output is correct |
33 |
Correct |
85 ms |
384 KB |
Output is correct |
34 |
Correct |
76 ms |
384 KB |
Output is correct |
35 |
Correct |
90 ms |
384 KB |
Output is correct |
36 |
Correct |
93 ms |
508 KB |
Output is correct |
37 |
Correct |
84 ms |
384 KB |
Output is correct |
38 |
Correct |
92 ms |
416 KB |
Output is correct |
39 |
Correct |
96 ms |
384 KB |
Output is correct |
40 |
Correct |
92 ms |
384 KB |
Output is correct |
41 |
Correct |
90 ms |
432 KB |
Output is correct |
42 |
Correct |
93 ms |
384 KB |
Output is correct |
43 |
Correct |
92 ms |
504 KB |
Output is correct |
44 |
Correct |
93 ms |
384 KB |
Output is correct |
45 |
Correct |
92 ms |
384 KB |
Output is correct |
46 |
Correct |
80 ms |
428 KB |
Output is correct |
47 |
Correct |
58 ms |
556 KB |
Output is correct |
48 |
Correct |
80 ms |
384 KB |
Output is correct |
49 |
Correct |
99 ms |
476 KB |
Output is correct |
50 |
Correct |
95 ms |
384 KB |
Output is correct |
51 |
Correct |
101 ms |
384 KB |
Output is correct |
52 |
Correct |
86 ms |
384 KB |
Output is correct |
53 |
Correct |
88 ms |
384 KB |
Output is correct |
54 |
Correct |
94 ms |
384 KB |
Output is correct |
55 |
Correct |
89 ms |
436 KB |
Output is correct |
56 |
Correct |
90 ms |
384 KB |
Output is correct |
57 |
Correct |
96 ms |
384 KB |
Output is correct |
58 |
Correct |
88 ms |
384 KB |
Output is correct |
59 |
Correct |
86 ms |
384 KB |
Output is correct |
60 |
Correct |
89 ms |
512 KB |
Output is correct |