QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#378628#6394. Turn on the LightDestiny#RE 0ms0kbC++142.2kb2024-04-06 13:49:212024-04-06 13:49:22

Judging History

你现在查看的是最新测评结果

  • [2024-04-06 13:49:22]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-04-06 13:49:21]
  • 提交

answer

// #define NDEBUG
#include <bits/stdc++.h>

using namespace std;
namespace LIN
{
#if defined(LOCAL) and not defined(ONLINE_JUDGE)
#include "C:\Users\ushop\Desktop\CodeFile\CODE_C++\vscode\LOCAL\debug.h"
#define DBG(X) cout << #X " = " << X << endl
#else
#define dbg(...) ;
#define DBG(...) ;
#endif
	using ll = long long;
	using db = double;
	// using LL = __int128;
	// using ldb = long double;

	// void print(LL x)
	//{
	// if (x < 0)
	//{
	// x = -x;
	// putchar('-');
	//}
	// if (x > 9)
	// print(x / 10);
	// putchar(x % 10 + '0');
	//}

	ll fast(ll u, ll v, ll p)
	{
		ll res = 1;
		while (v)
		{
			if (v & 1)
				res = res * u % p;
			v >>= 1;
			u = u * u % p;
		}
		return res;
	}

#define SPO(X) fixed << setprecision(X)
#define fo(i, l, r) for (ll i = l; i <= r; i++)
#define of(i, r, l) for (ll i = r; i >= l; i--)
#define inf(u, p) fast(u, p - 2, p)
#define edl '\n'
#define HEAP priority_queue
#define PII pair<ll, ll>
#define PIIL pair<PII, ll>
#define PIIR pair<ll, PII>
#define F first
#define S second
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define ANS() cout << ans << endl

	constexpr int N = 1e6 + 10;
	constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
	constexpr db EPS = 1.0e-9;
	constexpr ll MOD = 1e9 + 7;
	constexpr ll SZ = 1e5 + 5;

}
using namespace LIN;
#define ll int
int n;
ll p;
ll last;

void out(ll u)
{
	last = p;
	printf("? %d\n",u);fflush(stdout);scanf("%d",&p);
}

bool ans(ll u){
	printf("! %d\n",u);
    fflush(stdout);
}

void solve()
{
	scanf("%d", &n);

	if (n == 1)
	{
		ans(1);
		return;
	}
	ll l = 1, r = n, x = 1, y = n;

	while(1){
		// cout << "l r = " << l << ' ' << r << endl;
		out(l);
		ll mid = l + r >> 1;
		if(last == p){
			ans(mid);
			return;
		}
		l ++;
		while(l < r){
			int mid = l + r >> 1;
			out(mid);
			if(last == p) {
				ans(mid);
				return;
			} 
			if(last > p){
				r = mid - 1;	
				break;
			}else {
				l = mid + 1;
			}
		}
		if(l == r) {
			ans(l);
			return;
		}
	}

	return;
}

int main()
{
	// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int T = 1;
	// cin >> T;
	while (T--)
	{
		solve();
	}

	return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

3
1
2

output:

? 1
? 2
! 3

result: