Submission #1331224

#TimeUsernameProblemLanguageResultExecution timeMemory
1331224kevinsMađioničar (COI22_madionicar)C++20
63 / 100
498 ms412 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n;
	cin >> n;

	ll len = 1;

	auto extend = [&](ll mid){
		//get minimum odd and even number > len
		//even: gap between mid and mid-1
		//odd: mid itself
		
		//cout << "Processing middle at " << mid << "\n";
		
		ll minOdd = (len%2 ? len+2 : len+1);
		ll minEven = (len%2 ? len+1 : len+2);
		
		//cout << "Min odd length can extend: " << minOdd << "\n";
		
		
		//cout << "Min even length can extend: " << minEven << "\n";

		ll left1 = mid - (minOdd-1)/2, right1 = mid + (minOdd-1)/2; //for odd
		//cout << "For odd length: ";
		//cout << left1 << " to. " << right1 << "\n";
		ll left2 = mid - (minEven)/2, right2 = mid + (minEven)/2 - 1; //for even

		//cout << "For even length: ";
		//cout << left2 << " to. " << right2 << "\n";
		bool a = false, b = false;
		if (minOdd >= minEven){
			if (left1 >= 1 && right1 <= n){
				cout << "? " << left1 << " " << right1 << "\n";
				cout.flush();
				cin >> a;
			}
		}
		else{
			if (left2 >= 1 && right2 <= n){
				cout << "? " << left2 << " " << right2 << "\n";
				cout.flush();
				cin >> a;
			}
		}
		
		if (a) return 2LL;

		if (minOdd >= minEven){
			if (left2 >= 1 && right2 <= n){
				cout << "? " << left2 << " " << right2 << "\n";
				cout.flush();
				cin >> b;
			}
		}
		else{
			if (left1 >= 1 && right1 <= n){
				cout << "? " << left1 << " " << right1 << "\n";
				cout.flush();
				cin >> b;
			}
		}

		if (b) return 1LL;

		return 0LL;
	};

	for (ll i = 2; i <= n; ++i){
		while (true){
			ll res = extend(i);
			//cout << "can extend by " << res << "\n";
			if (res == 0) break;
			if (len >= n){
				cout << "! " << n << "\n";
				cout.flush();
				return 0;
			}
			len += res;
		}
	}

	cout << "! " << len << "\n";
	cout.flush();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...