QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#557797#8939. PermutationsynonymWA 40ms3640kbC++171.5kb2024-09-11 11:27:032024-09-11 11:27:04

Judging History

This is the latest submission verdict.

  • [2024-09-11 11:27:04]
  • Judged
  • Verdict: WA
  • Time: 40ms
  • Memory: 3640kb
  • [2024-09-11 11:27:03]
  • Submitted

answer

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define fnt long double
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

map<array<int,2>,int> answers;

int get_second(int l, int r) {
	if (answers.count({l,r})) {
		return answers[{l,r}];
	}
	cout<<"? "<<l<<" "<<r<<endl;
	int res; cin>>res;
	answers[{l,r}] = res;
	return res;
}

void output_answer(int k) {
	cout<<"! "<<k<<endl;
}

const fnt V = .618;
const fnt V1 = .5;

void solve() {
	int n; cin>>n;
	answers.clear();
	int l=1,r=n;
	int iter = 0;
	while (l != r) {
		assert(iter<100);
		iter++;
		int p = get_second(l,r);
		if (l+2==r) {
			if (p==l+1) {
				int pp = get_second(l,l+1);
				if (pp == p) {
					output_answer(l);
					return;
				} else {
					output_answer(r);
					return;
				}
			}
			if (p==l) {
				l++;
			} else {
				r--;
			}
			continue;
		}
		if (l+1==r) {
			output_answer(l+r-p);
			return;
		}
		
		int lrp, rrp;
		
		if (r-l+1 <= 6) {
			lrp = l+V1*(r-l+1);
			rrp = r-V1*(r-l);
		} else {
			lrp = l+V*(r-l+1);
			rrp = r-V*(r-l);
		}
		int p2 = -1;
		if (p <= lrp) {
			p2 = get_second(l,lrp);
			if (p2 == p) {
				r = lrp;
			} else {
				l = lrp+1;
			}
		} else {
			assert(p >= rrp);
			p2 = get_second(rrp,r);
			if (p2 == p) {
				l = rrp;
			} else {
				r = rrp-1;
			}
		}
	}
	output_answer(l);
}

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int t; cin>>t;
	while (t--) {
		solve();
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: 0
Accepted
time: 40ms
memory: 3560kb

input:

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

output:

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

result:

ok Correct (10000 test cases)

Test #3:

score: -100
Wrong Answer
time: 10ms
memory: 3640kb

input:

10000
3
1
2
11
5
5
3
7
2
2
19
3
3
4
12
12
11
7
5
5
5
4
3
3
1
19
6
6
6
6
6
5
2
2
15
11
11
11
11
12
8
14
1
1
1
1
3
16
4
4
4
1
7
3
3
2
19
13
17
5
5
5
4
2
2
4
1
3
7
2
2
2
2
3
2
2
17
1
1
1
1
2
4
14
9
1
12
12
11
20
9
9
3
13
13
11
6
4
2
5
18
7
7
7
7
7
5
8
8
8
6
3
8
6
6
6
6
5
16
10
10
10
10
10
8
6
1
1
3
10
...

output:

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

result:

wrong answer Too long queries, n = 11, now length 34 (test case 54)