QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#558698#8939. PermutationYarema#WA 4ms3596kbC++201.8kb2024-09-11 17:46:402024-09-11 17:46:41

Judging History

This is the latest submission verdict.

  • [2024-09-11 17:46:41]
  • Judged
  • Verdict: WA
  • Time: 4ms
  • Memory: 3596kb
  • [2024-09-11 17:46:40]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;

int ask(int l, int r)
{
	if (l >= r)
		return -1;
	cout << "? " << l + 1 << ' ' << r + 1 << endl;
	int x;
	cin >> x;
	return x - 1;
}

int solve(int l, int r)
{
	if (l + 1 == r)
		return l + 1;
	if (l + 2 == r)
	{
		int x = ask(l, l + 1);
		return 2 * l + 1 - x + 1;
	}
	int n = r - l;
	VI sz(3, n / 3);
	int rem = n % 3;
	FOR (i, 0, rem)
		sz[i]++;
	int x = ask(l, r - 1);
	if (x == l)
		reverse(ALL(sz));
	if (x < l + sz[0])
	{
		int y = ask(l, l + sz[0] - 1);
		if (x == y)
			return solve(l, l + sz[0]);
		y = ask(x, l + sz[0] + sz[1] - 1);
		if (x == y)
			return solve(l + sz[0], l + sz[0] + sz[1]);
		return solve(l + sz[0] + sz[1], r);
	}
	if (x < l + sz[0] + sz[1])
	{
		int y = ask(l + sz[0], l + sz[0] + sz[1] - 1);
		if (x == y)
			return solve(l + sz[0], l + sz[0] + sz[1]);
		y = ask(x, r - 1);
		if (x == y)
			return solve(l + sz[0] + sz[1], r);
		return solve(l, l + sz[0]);
	}
	else
	{
		int y = ask(l + sz[0] + sz[1], r - 1);
		if (x == y)
			return solve(l + sz[0] + sz[1], r);
		y = ask(l + sz[0], x);
		if (x == y)
			return solve(l + sz[0], l + sz[0] + sz[1]);
		return solve(l, l + sz[0]);
	}
}

void solve()
{
	int n;
	cin >> n;
	int res = solve(0, n);
	cout << "! " << res << endl;
}

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

	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}




详细

Test #1:

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

input:

3
5
3
3
3
6
6
5
3
1
4
3
3

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 4ms
memory: 3472kb

input:

10000
10
2
2
2
1
3
10
10
8
10
5
5
10
5
5
5
6
10
4
4
4
4
10
10
9
6
3
4

output:

? 1 10
? 1 4
? 1 4
? 1 2
? 2 3
! 4
? 1 10
? 8 10
? 5 10
? 5 7
? 5 6
! 6
? 1 10
? 5 7
? 5 7
? 5 6
! 7
? 1 10
? 1 4
? 1 4
? 3 4
! 3
? 1 10
? 8 10
? 5 10
? 1 4
? 3 4
? 1 2

result:

wrong answer Too many queries , n = 10 , now_q 6 (test case 5)