#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<cassert>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(((long long)(n))-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
//#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr)
#define pb push_back
#define mk make_pair
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define spln(i,n) (i==n?'\n':' ')
#define fac_init(n){fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;fz(i,2,n){fac[i]=1ll*fac[i-1]*i%mod;inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;}}
using namespace std;
typedef long long i64;
typedef long double f80;
typedef unsigned int u32;
typedef unsigned long long u64;
#include "grader.h"
i64 n;
i64 solve(i64 l,i64 r,i64 k)
{
if(l==r) return l;i64 md=(l+r)/2;
if(l<=3&&n-r>3) md=(l+l+r)/3;
if(n-r<=3&&l>3) md=(l+r+r)/3;
i64 p=md*2-k;p=max(1ll,p);p=min(n,p);
if(p==k){if(p<=(l+r)/2)p++; else p--;}
i64 ml=(p+k+1)/2-1,mr=(p+k)/2+1;
if(ml-l+1<(r-l+1)/4-2||r-mr+1<(r-l+1)/4-2) p=md,ml=(p+k+1)/2-1,mr=(p+k)/2+1;
int t=Guess(p);
if(t==0) return (k+p)/2;
if((t==1)==(p<k)) return solve(l,min(r,ml),p); else return solve(max(l,mr),r,p);
}
int std(int N){
int L = 1, R = N, prv, nxt, t, W = log(3 * N) / log(2);
while (L < R) {
if (R == 2) {
Guess(1);
return Guess(2) < 0 ? 1 : 2;
}
int cut = W & 1 ? (2 << W - 2) / 3 + 1 : (2 << W - 2) / 3 + 2;
nxt = R == N ? cut + cal(R - cut) : cut + cut - 1;
prv = cut + cut - nxt;
Guess(prv);
t = Guess(nxt);
if (t == -1) R = prv + nxt - 1 >> 1;
if (t == 0) return prv + nxt >> 1;
if (t == 1) {
L = prv + nxt + 2 >> 1;
prv = nxt;
while (L < R) {
nxt = (L + R >> 1 << 1) - prv;
if (nxt == prv) nxt++;
if (nxt < 1) nxt = 1;
if (nxt > N) nxt = N;
t = Guess(nxt);
if (t == -1) {
if (prv < nxt) R = nxt + prv - 1 >> 1;
else L = nxt + prv + 2 >> 1;
}
if (t == 0) return nxt + prv >> 1;
if (t == 1) {
if (prv < nxt) L = nxt + prv + 2 >> 1;
else R = nxt + prv - 1 >> 1;
}
prv = nxt;
}
}
W -= 2;
}
return L;
}
int HC(int nn)
{
if(nn<1e6) return std(nn);
n=nn;Guess(1);return solve(1,n,1);
}
Compilation message
hottercolder.cpp: In function 'i64 solve(i64, i64, i64)':
hottercolder.cpp:44:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
44 | if(l==r) return l;i64 md=(l+r)/2;
| ^~
hottercolder.cpp:44:20: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
44 | if(l==r) return l;i64 md=(l+r)/2;
| ^~~
hottercolder.cpp: At global scope:
hottercolder.cpp:55:14: error: 'int std(int)' redeclared as different kind of entity
55 | int std(int N){
| ^
<built-in>: note: previous declaration 'namespace std { }'
hottercolder.cpp: In function 'int std(int)':
hottercolder.cpp:62:31: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
62 | int cut = W & 1 ? (2 << W - 2) / 3 + 1 : (2 << W - 2) / 3 + 2;
| ~~^~~
hottercolder.cpp:62:54: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
62 | int cut = W & 1 ? (2 << W - 2) / 3 + 1 : (2 << W - 2) / 3 + 2;
| ~~^~~
hottercolder.cpp:63:26: error: 'cal' was not declared in this scope
63 | nxt = R == N ? cut + cal(R - cut) : cut + cut - 1;
| ^~~
hottercolder.cpp:67:32: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
67 | if (t == -1) R = prv + nxt - 1 >> 1;
| ~~~~~~~~~~^~~
hottercolder.cpp:68:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
68 | if (t == 0) return prv + nxt >> 1;
| ~~~~^~~~~
hottercolder.cpp:70:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
70 | L = prv + nxt + 2 >> 1;
| ~~~~~~~~~~^~~
hottercolder.cpp:73:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
73 | nxt = (L + R >> 1 << 1) - prv;
| ~~^~~
hottercolder.cpp:79:40: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
79 | if (prv < nxt) R = nxt + prv - 1 >> 1;
| ~~~~~~~~~~^~~
hottercolder.cpp:80:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
80 | else L = nxt + prv + 2 >> 1;
| ~~~~~~~~~~^~~
hottercolder.cpp:82:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
82 | if (t == 0) return nxt + prv >> 1;
| ~~~~^~~~~
hottercolder.cpp:84:40: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
84 | if (prv < nxt) L = nxt + prv + 2 >> 1;
| ~~~~~~~~~~^~~
hottercolder.cpp:85:30: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
85 | else R = nxt + prv - 1 >> 1;
| ~~~~~~~~~~^~~
hottercolder.cpp: In function 'int HC(int)':
hottercolder.cpp:96:23: error: expected primary-expression before '(' token
96 | if(nn<1e6) return std(nn);
| ^