// author: erray
#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std;
template<typename T, typename F> string to_string(pair<T, F> p);
string to_string(string s) {
return '"' + s + '"';
}
string to_string(char c) {
return (string) "'" + c + "'";
}
string to_string(const char* p) {
return to_string((string) p);
}
string to_string(bool B) {
return (B ? "true" : "false");
}
string to_string(vector<bool> v) {
string res = "{";
for (int i = 0; i < (int) v.size(); ++i) {
if ((int) res.size() > 1) res += ", ";
res += to_string(v[i]);
}
res += "}";
return res;
}
template<size_t T> string to_string(bitset<T> bs) {
return bs.to_string();
}
template<typename T> string to_string(T v) {
string res = "{";
for (auto& el : v) {
if ((int) res.size() > 1) res += ", ";
res += to_string(el);
}
res += "}";
return res;
}
template<typename T, typename F> string to_string(pair<T, F> p) {
return '(' + to_string(p.first) + ", " + to_string(p.second) + ')';
}
void debug_out() {
cerr << endl;
}
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" , debug_out(__VA_ARGS__)
#else
#define debug(...) (void) 37
#endif
//int query(int s, int e);
//int answer(int ind, int v);
void solve(int n) {
vector<int> f(n);
f[1] = query(1, 2);
for (int i = 2; i < n; ++i) {
int th = query(i - 1, i + 1), tw = query(i, i + 1);
debug(th, tw);
if (th == abs(f[i - 1])) {
f[i] = -tw;
} else if (th > abs(f[i - 1])) {
if (tw >= th) {
f[i] = -tw;
} else {
f[i] = tw;
}
}
}
bool cur = false;
for (int i = 0; i < n; ++i) {
if (f[i] < 0) cur ^= 1;
f[i] = abs(f[i]) * (cur ? 1 : -1);
}
debug(f);
vector<int> pref(1, 0);
for (int i = 1; i < n; ++i) pref.push_back(pref.back() + f[i]);
int mn_ind = (int) (min_element(pref.begin(), pref.end()) - pref.begin()), mx_ind = (int) (max_element(pref.begin(), pref.end()) - pref.begin());
if (mx_ind < mn_ind) {
swap(mx_ind, mn_ind);
for (auto& el : f) el = -el;
}
vector<int> ans(n);
ans[mn_ind] = 1;
for (int i = mn_ind + 1; i < n; ++i) {
ans[i] = ans[i - 1] + f[i];
}
for (int i = mn_ind - 1; i >= 0; --i) {
ans[i] = ans[i + 1] - f[i + 1];
}
debug(ans);
for (int i = 0; i < n; ++i) {
answer(i + 1, ans[i]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
256 KB |
Output is correct |
14 |
Correct |
3 ms |
256 KB |
Output is correct |
15 |
Correct |
3 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
256 KB |
Output is correct |
14 |
Correct |
3 ms |
256 KB |
Output is correct |
15 |
Correct |
3 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
256 KB |
Output is correct |
17 |
Correct |
6 ms |
372 KB |
Output is correct |
18 |
Correct |
13 ms |
376 KB |
Output is correct |
19 |
Correct |
12 ms |
376 KB |
Output is correct |
20 |
Correct |
17 ms |
376 KB |
Output is correct |
21 |
Correct |
17 ms |
372 KB |
Output is correct |
22 |
Correct |
19 ms |
376 KB |
Output is correct |
23 |
Correct |
20 ms |
376 KB |
Output is correct |
24 |
Correct |
19 ms |
376 KB |
Output is correct |
25 |
Correct |
23 ms |
376 KB |
Output is correct |
26 |
Correct |
19 ms |
376 KB |
Output is correct |
27 |
Correct |
19 ms |
376 KB |
Output is correct |
28 |
Correct |
17 ms |
376 KB |
Output is correct |
29 |
Correct |
18 ms |
376 KB |
Output is correct |
30 |
Correct |
29 ms |
372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
256 KB |
Output is correct |
14 |
Correct |
3 ms |
256 KB |
Output is correct |
15 |
Correct |
3 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
256 KB |
Output is correct |
17 |
Correct |
6 ms |
372 KB |
Output is correct |
18 |
Correct |
13 ms |
376 KB |
Output is correct |
19 |
Correct |
12 ms |
376 KB |
Output is correct |
20 |
Correct |
17 ms |
376 KB |
Output is correct |
21 |
Correct |
17 ms |
372 KB |
Output is correct |
22 |
Correct |
19 ms |
376 KB |
Output is correct |
23 |
Correct |
20 ms |
376 KB |
Output is correct |
24 |
Correct |
19 ms |
376 KB |
Output is correct |
25 |
Correct |
23 ms |
376 KB |
Output is correct |
26 |
Correct |
19 ms |
376 KB |
Output is correct |
27 |
Correct |
19 ms |
376 KB |
Output is correct |
28 |
Correct |
17 ms |
376 KB |
Output is correct |
29 |
Correct |
18 ms |
376 KB |
Output is correct |
30 |
Correct |
29 ms |
372 KB |
Output is correct |
31 |
Correct |
40 ms |
376 KB |
Output is correct |
32 |
Correct |
54 ms |
376 KB |
Output is correct |
33 |
Correct |
73 ms |
384 KB |
Output is correct |
34 |
Correct |
98 ms |
384 KB |
Output is correct |
35 |
Correct |
106 ms |
388 KB |
Output is correct |
36 |
Correct |
130 ms |
504 KB |
Output is correct |
37 |
Correct |
85 ms |
384 KB |
Output is correct |
38 |
Correct |
90 ms |
504 KB |
Output is correct |
39 |
Correct |
94 ms |
504 KB |
Output is correct |
40 |
Correct |
93 ms |
388 KB |
Output is correct |
41 |
Correct |
128 ms |
392 KB |
Output is correct |
42 |
Correct |
89 ms |
384 KB |
Output is correct |
43 |
Correct |
89 ms |
384 KB |
Output is correct |
44 |
Correct |
124 ms |
384 KB |
Output is correct |
45 |
Correct |
124 ms |
384 KB |
Output is correct |
46 |
Correct |
92 ms |
388 KB |
Output is correct |
47 |
Correct |
101 ms |
504 KB |
Output is correct |
48 |
Correct |
133 ms |
504 KB |
Output is correct |
49 |
Correct |
154 ms |
384 KB |
Output is correct |
50 |
Correct |
132 ms |
384 KB |
Output is correct |
51 |
Correct |
146 ms |
384 KB |
Output is correct |
52 |
Correct |
163 ms |
384 KB |
Output is correct |
53 |
Correct |
141 ms |
384 KB |
Output is correct |
54 |
Correct |
95 ms |
504 KB |
Output is correct |
55 |
Correct |
135 ms |
384 KB |
Output is correct |
56 |
Correct |
146 ms |
388 KB |
Output is correct |
57 |
Correct |
64 ms |
388 KB |
Output is correct |
58 |
Correct |
90 ms |
480 KB |
Output is correct |
59 |
Correct |
101 ms |
384 KB |
Output is correct |
60 |
Correct |
70 ms |
388 KB |
Output is correct |