QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#854718#9734. Identify Chorducup-team3099#TL 1ms3596kbC++205.8kb2025-01-12 06:46:132025-01-12 06:46:14

Judging History

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

  • [2025-01-12 06:46:14]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3596kb
  • [2025-01-12 06:46:13]
  • 提交

answer

#ifdef LOCAL
#define _GLIBCXX_DEBUG 1
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

#if 0
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
 
    template<class T>
    using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, std::less<T>, __gnu_pbds::rb_tree_tag,
        __gnu_pbds::tree_order_statistics_node_update>;
#endif

#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <queue>
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <ctime> 
#include <cstring>
#include <random>
#include <chrono>
#include <cassert>

using namespace std;
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)

#define each(a,x) for (auto& a: x)
#define tcT template<class T
#define tcTU tcT, class U
#define tcTUU tcT, class ...U
template<class T> using V = vector<T>; 
template<class T, size_t SZ> using AR = array<T,SZ>;

typedef string str;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
 
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
 
mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count());
 
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(vector<bool> v) { str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) { str res = ""; F0R(i,SZ) res += char('0'+b[i]); return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { bool fst = 1; str res = "{"; for (const auto& x: v) {if (!fst) res += ", ";	fst = 0; res += ts(x);}	res += "}"; return res;}
template<class A, class B> str ts(pair<A,B> p) {return "("+ts(p.first)+", "+ts(p.second)+")"; }
 
template<class A> void pr(A x) { cout << ts(x); }
template<class H, class... T> void pr(const H& h, const T&... t) { pr(h); pr(t...); }
void ps() { pr("\n"); }
template<class H, class... T> void ps(const H& h, const T&... t) { pr(h); if (sizeof...(t)) pr(" "); ps(t...); }
 
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {cerr << ts(h); if (sizeof...(t)) cerr << ", ";	DBG(t...); }

tcTU> void re(pair<T,U>& p);
tcT> void re(V<T>& v);
tcT, size_t SZ> void re(AR<T,SZ>& a);

tcT> void re(T& x) { cin >> x; }
void re(double& d) { str t; re(t); d = stod(t); }
void re(long double& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }

tcTU> void re(pair<T,U>& p) { re(p.first,p.second); }
tcT> void re(V<T>& x) { each(a,x) re(a); }
tcT, size_t SZ> void re(AR<T,SZ>& x) { each(a,x) re(a); }
tcT> void rv(int n, V<T>& x) { x.rsz(n); re(x); }

constexpr bool multitest() {return 1;}
void solve();
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int t = 1;
	if (multitest()) cin >> t;
	for (; t; t--) solve();
}

















#define int long long


int xxx, yyy;
int n;
int queries;

int dist(int a, int b) {
	if (a > b) swap(a,b);
	return min(b-a, a+n-b);
}

int ask(int a, int b) {
	if (a > b) swap(a,b);

	queries++;
#ifndef LOCAL
	cout << "? " << a+1 << " " << b+1 << endl;
	int ret; cin >> ret;
	return ret;
#else
	int ret = dist(a,b);
	ctmin(ret, dist(a,xxx)+1+dist(b,yyy));
	ctmin(ret, dist(a,yyy)+1+dist(b,xxx));
	//dbg("ask", a, b, ret);
	return ret;
#endif
}

int guess(int a, int b) {
	if (a > b) swap(a,b);
#ifndef LOCAL
	cout << "! " << a+1 << " " << b+1 << endl;
	int r; cin >> r;
	return r;
#else
	//dbg(queries);
	//dbg("guess", a, b);
	if (a == xxx && b == yyy) return 1;
	return -1;
#endif
}

void solve() {
#ifdef LOCAL
	n = 999999999;
#else
	re(n);
#endif
	queries = 0;

#ifdef LOCAL
	//xxx = rand()%n, yyy = rand()%n;
	xxx = uniform_int_distribution<int>(0,n-1)(rng); yyy = uniform_int_distribution<int>(0,n-1)(rng);//(xxx+n/2-1)%n;
	while (xxx == yyy || (xxx+1)%n == yyy || (xxx+n-1)%n == yyy) yyy = uniform_int_distribution<int>(0,n-1)(rng);//yyy = rand()%n;
	if (xxx > yyy) swap(xxx,yyy);
	//dbg("ans = ", xxx, yyy);
#endif

	int x = uniform_int_distribution<int>(0, n-1)(rng);
	int y;
	int ret;
	while (true) {
		y = (x+n/2)%n;
		while (x == y || (x+1)%n == y || (x+n-1)%n == y) y = uniform_int_distribution<int>(0,n-1)(rng);
		if (x > y) swap(x,y);
		ret = ask(x,y);
		if (ret != dist(x,y)) break;
		x++;
	}

	if (ask(x+1,y) == ret-1) {
		x++;
		ret--;

		int st = 0, ed = ret-1;
		while (st < ed) {
			int m = (st+ed+1)/2;
			int tret = ask(x+m, y);

			if (tret == ret - m) st = m;
			else ed = m-1;
		}

		x += st;
		ret -= st;
	}
	else if (ask( (x+n-1)%n , y) == ret-1) {
		x=(x+n-1)%n;
		ret--;

		int st = 0, ed = ret-1;
		while (st < ed) {
			int m = (st+ed+1)/2;
			int tret = ask( (x+n-m)%n, y );

			if (tret == ret - m) st = m;
			else ed = m-1;
		}

		x = (x+n-st)%n;
		ret -= st;
	}

	if (ask(x, (y+n+ret-1)%n) == 1) y=(y+n+ret-1)%n;
	else y = (y+n-ret+1)%n;

	if (queries > 40 || guess(x,y) != 1) {
		ps("OH NO");
		dbg(queries);
		exit(0);
	}
}


















































	







Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3596kb

input:

2
6
3
2
1
1
1
4
1
1
1
1
1

output:

? 3 6
? 1 4
? 2 4
? 2 4
! 2 4
? 1 3
? 2 3
? 3 4
? 1 3
! 1 3

result:

ok ok (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

1000
15
6
6
7
1
1
19
5
6
4
4
3
5
1
17
7
7
6
5
5
4
3
1
15
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7

output:

? 8 15
? 9 15
? 7 15
? 5 8
! 5 8
? 5 14
? 6 14
? 4 14
? 2 14
? 3 14
? 3 16
! 3 12
? 6 14
? 7 14
? 5 14
? 2 14
? 4 14
? 3 14
? 3 17
! 3 11
? 6 13
? 7 14
? 8 15
? 1 9
? 2 9
? 3 10
? 4 11
? 5 12
? 6 13
? 7 14
? 8 15
? 1 9
? 2 9
? 3 10
? 4 11
? 5 12
? 6 13
? 7 14
? 8 15
? 1 9
? 2 9
? 3 10
? 4 11
? 5 12
...

result: