Submission #391664

#TimeUsernameProblemLanguageResultExecution timeMemory
391664ronnithZagrade (COI20_zagrade)C++14
100 / 100
1166 ms5320 KiB
#include <bits/stdc++.h>

using namespace std;

int n, q;

inline bool query(int l, int r) {
	cout << "? " << l << ' ' << r << endl;
	bool res;
	cin >> res;
	return res;
}

int main() {
	cin >> n >> q;
	set<int> pos;
	for(int i = 1;i <= n;i ++) {
		pos.insert(i);
	}
	char ans[n+1];
	ans[n] = '\0';
	auto it = pos.begin();
	while(it != (--pos.end())) {
		auto crr = (it++);
		if(query(*crr, *it)) {
			ans[(*crr) - 1] = '(';
			ans[(*it) - 1] = ')';
			int values = -1;
			set<int>::iterator ptr;
			if(crr != pos.begin()) {
				ptr = crr;
				ptr --;
				values = *ptr;
			} else {
				if(it != (--pos.end())) {
					ptr = it;
					ptr ++;
					values = *ptr;
				}
			}
			pos.erase(crr);
			pos.erase(it);
			if(values != -1) {
				it = pos.find(values);
			}
		}
		if((int)pos.size() == 0) {
			break;
		}
	}
	if((int)pos.size()) {
		it = pos.begin();
		for(int rep = 0;rep < (int)pos.size() / 2;rep ++) {
			ans[(*it)-1] = ')';
			it ++;
		}
		while(it != pos.end()) {
			ans[(*it)-1] = '(';
			it ++;
		}
	}
	string out = ans;
	cout << "! " << out << '\n';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...