This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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]);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |