이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }
void solve(int n){
int l = 0, r = n - 2;
while(l < r){
int mid = (l + r + 1) / 2;
int q = query(mid + 1, n);
if(q == (n - 1)) l = mid;
else r = mid - 1;
}
vi ans(n, 0);
ans[l] = 1;
if(l > 0){
int qu = query(l, l + 1);
ans[l - 1] = qu + 1;
for(int i = l - 2; i >= 0; i--){
int qu = query(i + 1, i + 3);
int qu1 = query(i + 1, i + 2);
vi cur = {ans[i + 1], ans[i + 2], ans[i + 1] + qu1};
sort(all(cur));
if(cur[2] - cur[0] == qu) ans[i] = ans[i + 1] + qu1;
else ans[i] = ans[i + 1] - qu1;
}
}
if(l < (n - 1)){
int qu = query(l + 1, l + 2);
ans[l + 1] = qu + 1;
for(int i = l + 2; i < n; i++){
int qu = query(i - 1, i + 1);
int qu1 = query(i, i + 1);
vi cur = {ans[i - 2], ans[i - 1], ans[i - 1] + qu1};
sort(all(cur));
if(cur[2] - cur[0] == qu) ans[i] = ans[i - 1] + qu1;
else ans[i] = ans[i - 1] - qu1;
}
}
rep(i, n) answer(i + 1, ans[i]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |