QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#829591#8939. PermutationOIer2008WA 120ms3688kbC++142.4kb2024-12-24 11:25:222024-12-24 11:25:22

Judging History

This is the latest submission verdict.

  • [2024-12-24 11:25:22]
  • Judged
  • Verdict: WA
  • Time: 120ms
  • Memory: 3688kb
  • [2024-12-24 11:25:22]
  • Submitted

answer

#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;++i)
#define fu(i,l,r) for(int i=l;i<r;++i)
#define fd(i,r,l) for(int i=r;i>=l;--i)
#define ll long long
#define I inline int
#define V inline void
#define B inline bool
#define L inline ll
#define pi pair<int,int>
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define vii vector<pi>
#define popc __builtin_popcount
using namespace std;
const int N=1e6+10,mod=998244353;
char St;
I read() {
	int x=0,y=1;char c=getchar();
	while(c<48||c>57) {if(c==45)y=-y;c=getchar();}
	while(c>=48&&c<=57) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*y;
}
L ksm(ll x,int y) {ll t(1);for(;y;y>>=1,x=x*x%mod)if(y&1)t=t*x%mod;return t;}
int s1(0),s2(0);
I ask(int l,int r) {
	if(l==r) return 0;
	cout<<"? "<<l<<" "<<r<<endl;
	s1++;s2+=r-l+1;
//	cerr<<"!!!!!!!!!!!!!!! "<<s1<<" "<<s2<<endl;
	int x;
	cin>>x;return x;
}
I solve(int l,int r) {
//	if(l>r) {
//		cerr<<"WA"<<endl;
//		exit(0);
//	}
//	cerr<<"#"<<l<<" "<<r<<endl;
	if(l==r) return l;
	int mid=l+r>>1,se=ask(l,r);
	if(se<=mid) {
		if(l==mid) return solve(mid+1,r);
		int se2=ask(l,mid);
		if(se==se2) {//[l,mid]
			r=mid;
			mid=l+r>>1;
			if(l==r) return l;
			int se3;
			if(se2<=mid) {
				se3=ask(l,mid);
				if(se3==se2) return solve(l,mid);
				else return solve(mid+1,r);
			}
			else {
				se3=ask(mid+1,r);
				if(se3==se2) return solve(mid+1,r);
				else return solve(l,mid);
			}
		}
		else {
			l=mid+1;mid=l+r>>1;
			if(l==r) return l;
			int se3=ask(se,mid);
			if(se3==se) return solve(l,mid);
			else return solve(mid+1,r);
		}
	}
	else {
		if(mid+1==r) return solve(l,mid);
		int se2=ask(mid+1,r);
		if(se==se2) {
			l=mid+1;
			mid=l+r>>1;
			if(l==r) return l;
			int se3;
			if(se2<=mid) {
				se3=ask(l,mid);
				if(se3==se2) return solve(l,mid);
				else return solve(mid+1,r);
			}
			else {
				se3=ask(mid+1,r);
				if(se3==se2) return solve(mid+1,r);
				else return solve(l,mid);
			}
		}
		else {
			r=mid;mid=l+r-1>>1;
			if(l==r) return l;
			int se3=ask(mid+1,se);
			if(se3==se) return solve(mid+1,r);
			else return solve(l,mid);
		}
	}
}
int n;
V solve() {
	s1=s2=0;
	cin>>n;
	int t=solve(1,n);
	cout<<"! "<<t<<endl;
}
char Ed;
int main() {
//	cerr<<"memory:"<<(&St-&Ed)/1024.0<<endl;
	int T;cin>>T;
	while(T--) solve();
//	cerr<<"time:"<<clock()<<endl;
	return 0;
}


详细

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: 0
Accepted
time: 72ms
memory: 3632kb

input:

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

output:

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

result:

ok Correct (10000 test cases)

Test #3:

score: 0
Accepted
time: 76ms
memory: 3532kb

input:

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

output:

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

result:

ok Correct (10000 test cases)

Test #4:

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

input:

10000
47
23
23
24
11
9
11
5
5
14
8
8
8
8
9
8
25
6
13
6
18
17
17
7
4
2
4
6
9
2
2
2
2
2
27
27
27
27
27
26
24
21
7
7
10
5
5
5
5
43
41
37
21
7
8
5
3
1
22
6
4
14
20
19
21
34
29
25
29
17
17
16
14
42
20
20
20
20
20
21
17
17
47
21
21
21
21
19
21
16
17
41
25
25
30
33
34
33
39
38
19
17
17
16
12
12
12
12
21
14...

output:

? 1 47
? 1 24
? 13 24
? 1 12
? 7 12
? 4 11
? 4 6
? 4 5
! 4
? 1 14
? 8 14
? 8 11
? 8 11
? 8 9
? 8 10
! 10
? 1 25
? 1 13
? 6 19
? 14 19
? 17 19
? 15 18
! 14
? 1 7
? 1 4
? 4 6
? 5 6
! 5
? 1 9
? 1 5
? 1 3
? 1 3
? 1 2
! 1
? 1 27
? 15 27
? 22 27
? 22 27
? 25 27
? 23 27
! 22
? 1 21
? 1 11
? 7 11
? 1 6
? 4 ...

result:

ok Correct (10000 test cases)

Test #5:

score: 0
Accepted
time: 96ms
memory: 3688kb

input:

10000
100
47
5
47
61
53
68
71
71
71
71
9
2
2
2
2
1
53
46
35
14
6
6
6
6
6
33
3
16
16
31
31
30
32
82
60
42
60
29
29
28
23
21
23
24
88
39
8
39
59
59
59
59
61
59
57
71
24
29
29
59
59
56
60
61
60
92
52
52
56
88
88
88
88
88
89
24
11
11
9
5
5
5
5
66
51
51
66
45
43
45
39
40
39
92
43
43
38
20
20
21
17
17
16
...

output:

? 1 100
? 1 50
? 47 75
? 51 75
? 51 63
? 61 69
? 70 75
? 70 72
? 70 71
? 70 71
! 70
? 1 9
? 1 5
? 1 3
? 1 3
? 1 2
! 3
? 1 53
? 28 53
? 14 46
? 1 13
? 1 7
? 5 7
? 5 7
? 5 6
! 5
? 1 33
? 1 17
? 3 25
? 26 33
? 30 33
? 30 31
? 32 33
! 33
? 1 82
? 42 82
? 21 60
? 21 41
? 21 31
? 27 31
? 21 26
? 21 23
? 2...

result:

ok Correct (10000 test cases)

Test #6:

score: -100
Wrong Answer
time: 16ms
memory: 3688kb

input:

10000
50
10
10
10
10
11
10
6
7
5
50
11
11
9
18
16
22
23
23
50
44
40
44
20
20
21
25
23
50
24
14
29
45
45
45
45
46
50
50
50
50
50
50
49
47
45
50
36
39
23
12
12
11
8
7
50
29
36
20
3
3
1
6
5
50
30
42
22
1
1
1
1
2
50
25
15
25
30
30
31
29
29
50
18
20
18
30
27
34
37
36
50
9
9
9
9
9
8
13
11
50
26
43
26
17
1...

output:

? 1 50
? 1 25
? 1 13
? 1 13
? 8 13
? 4 10
? 4 7
? 6 7
? 5 6
! 4
? 1 50
? 1 25
? 1 13
? 14 25
? 14 19
? 18 22
? 23 25
? 23 24
! 24
? 1 50
? 26 50
? 13 44
? 13 25
? 20 25
? 20 22
? 23 25
? 23 24
! 24
? 1 50
? 1 25
? 24 38
? 39 50
? 45 50
? 45 47
? 45 47
? 45 46
! 47
? 1 50
? 26 50
? 39 50
? 39 50
? 45...

result:

wrong answer Too long queries, n = 50, now length 151 (test case 592)