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 "xylophone.h"
#define ll long long
#define pb push_back
#define pu push
#define ins insert
#define bruh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ff(x,a,b,c) for (auto x=a;x<=b;x+=c)
#define fd(x,a,b,c) for (auto x=a;x>=b;x-=c)
using namespace std;
const int N = 1e4+5;
const int mod = 1e9+7;
int power(int a,int b) {ll x = 1;if (a >= mod) a%=mod; while (b) {if (b & 1) x = x*a % mod;a = a*a % mod;b>>=1;}return x;}
int a[N];
int check[N];
int ans[N];
void solve(int n)
{
a[2] = query(1,2); check[2] = 0;
for (int i=3;i<=n;i++)
{
int x = query(i-1,i),y = query(i-2,i);
a[i] = x;
if (a[i-1]+a[i]==y) check[i] = check[i-1];
else check[i] = 1-check[i-1];
}
for (int i=1;i<=n;i++) ans[i] = ans[i-1]+a[i]*(1-check[i]*2);
int mx = INT_MIN,mn = INT_MAX,idx1,idx2;
for (int i=1;i<=n;i++)
{
if (mx<ans[i]) mx = ans[i],idx1 = i;
if (mn>ans[i]) mn = ans[i],idx2 = i;
}
int tmp = mn;
if (idx1<idx2)
{
for (int i=1;i<=n;i++) ans[i] = ans[i-1]+a[i]*(check[i]*2-1);
tmp = -mx;
}
for (int i=1;i<=n;i++) answer(i,ans[i]-tmp+1);
}
Compilation message (stderr)
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:39:2: warning: 'idx2' may be used uninitialized in this function [-Wmaybe-uninitialized]
39 | if (idx1<idx2)
| ^~
xylophone.cpp:39:2: warning: 'idx1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |