#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
template<class T>
bool operator()(T const &a, T const &b) const { return a > b; }
};
vector<int>sol;
set<int>nowi;
map<pair<int,int>,int>gg;
void solve(int n)
{
//debug(n);
int low=1,high=n-1;
int lo=1;
sol.resize(n+1,0);
while(low<=high)
{
int med=(low+high)/2;
//debug(med);
int k=query(med,n);
if(k==(n-1))
{
lo=med;
low=med+1;
}
else
{
high=med-1;
}
}
//debug(lo);
answer(lo,1);
sol[lo]=1;
//debug(lo);
if(lo!=1)
{int yo=query(lo-1,lo);
//debug(yo);
gg[{lo-1,lo}]=yo;
sol[lo-1]=yo+1;
answer(lo-1,sol[lo-1]);
nowi.insert(sol[lo-1]);
//debug(sol[lo-1]);
}
if(lo!=n)
{int yo=query(lo,lo+1);
gg[{lo,lo+1}]=yo;
sol[lo+1]=yo+1;
answer(lo+1,sol[lo+1]);
nowi.insert(sol[lo+1]);
//debug(sol[lo+1]);
}
nowi.insert(sol[lo]);
for (int i = lo-2; i > 0; --i)
{
int z1=0,z2=0,z3=0;
int n=query(i,i+1);
gg[{i,i+1}]=n;
z1=sol[i+1]-n;
z2=sol[i+1]+n;
if(z1<1 || nowi.find(z1)!=nowi.end())
{
nowi.insert(z2);
sol[i]=z2;
answer(i,z2);
}
else if(z2>n || nowi.find(z2)!=nowi.end())
{
nowi.insert(z1);
sol[i]=z1;
answer(i,z1);
}
else
{
if(sol[i+2]<sol[i+1])
{
if(z1<sol[i+2])
{
if(query(i,i+2)==gg[{i,i+1}])
{
z3=z1;
}
else z3=z2;
}
else
{
if(query(i,i+2)==gg[{i+1,i+2}])
{
z3=z1;
}
else z3=z2;
}
}
else
{
if(z2>sol[i+2])
{
if(query(i,i+2)==gg[{i,i+1}])
{
z3=z2;
}
else z3=z1;
}
else
{
if(query(i,i+2)==gg[{i+1,i+2}])
{
z3=z2;
}
else z3=z1;
}
}
sol[i]=z3;
nowi.insert(z3);
answer(i,z3);
}
}
for (int i = lo+2; i <= n; ++i)
{
int z1=0,z2=0,z3=0;
int n=query(i-1,i);
gg[{i-1,i}]=n;
z1=sol[i-1]-n;
z2=sol[i-1]+n;
if(z1<1 || nowi.find(z1)!=nowi.end())
{
nowi.insert(z2);
sol[i]=z2;
answer(i,z2);
}
else if(z2>n || nowi.find(z2)!=nowi.end())
{
nowi.insert(z1);
sol[i]=z1;
answer(i,z1);
}
else
{
if(sol[i-2]<sol[i-1])
{
if(z1<sol[i-2])
{
if(query(i-2,i)==gg[{i-1,i}])
{
z3=z1;
}
else z3=z2;
}
else
{
if(query(i-2,i)==gg[{i-2,i-1}])
{
z3=z1;
}
else z3=z2;
}
}
else
{
if(z2>sol[i-2])
{
if(query(i-2,i)==gg[{i-1,i}])
{
z3=z2;
}
else z3=z1;
}
else
{
if(query(i-2,i)==gg[{i-2,i-1}])
{
z3=z2;
}
else z3=z1;
}
}
sol[i]=z3;
nowi.insert(z3);
answer(i,z3);
}
}
}
//code the AC sol !
// BS/queue/map
Compilation message
xylophone.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization ("O3")
xylophone.cpp:6:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization ("unroll-loops")
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
248 KB |
Output is correct |
3 |
Incorrect |
5 ms |
248 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
248 KB |
Output is correct |
3 |
Incorrect |
5 ms |
248 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
248 KB |
Output is correct |
3 |
Incorrect |
5 ms |
248 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |