QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#642876#8939. PermutationWolam#WA 129ms3796kbC++201.5kb2024-10-15 16:48:252024-10-15 16:48:26

Judging History

This is the latest submission verdict.

  • [2024-10-15 16:48:26]
  • Judged
  • Verdict: WA
  • Time: 129ms
  • Memory: 3796kb
  • [2024-10-15 16:48:25]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int base,tot;
map<pair<int,int>,int> mp;
int ask(int l,int r)
{
    if(mp[{l,r}])
    {
        return mp[{l,r}];
    }
    tot++;
    assert(tot<=base);
    cout<<"? "<<l<<" "<<r<<endl;
    int pos;
    cin>>pos;
    return mp[{l,r}]=pos;
}
int query(int l,int r)
{
    if(l==r)
    {
        return l;
    }
    else if(r-l+1==2)
    {
        int p=ask(l,r);
        if(p==l)
        {
            return r;
        }
        else
        {
            return l;
        }
    }
    else
    {
        int p=ask(l,r);
        int mid=(l+(r-l+3)/3);
        if(p>=mid&&p<=r)//[l,mid-1] [mid,r]
        {
            if(ask(mid,r)==p)
            {
                return query(mid,r);
            }
            else
            {
                return query(l,mid-1);
            }
        }
        else//[l,mid] [mid+1,r]
        {
            mid=(r-(r-l+3)/3);
            if(ask(l,mid)==p)
            {
                return query(l,mid);
            }
            else
            {
                return query(mid+1,r);
            }
        }
    }
}
void solve(void)
{
    mp.clear();
    base=tot=0;
    int n;
    cin>>n;
    base=ceill(1.5*log2l(n))+1;
    int ans=query(1,n);
    cout<<"! "<<ans<<endl;
}
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: 0
Accepted
time: 73ms
memory: 3796kb

input:

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

output:

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

result:

ok Correct (10000 test cases)

Test #3:

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

input:

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

output:

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

result:

ok Correct (10000 test cases)

Test #4:

score: 0
Accepted
time: 110ms
memory: 3612kb

input:

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

output:

? 1 47
? 17 47
? 1 16
? 7 16
? 1 6
? 1 4
? 1 2
? 3 4
! 4
? 1 14
? 6 14
? 6 11
? 8 11
? 8 9
? 10 11
! 10
? 1 25
? 1 16
? 1 10
? 11 16
? 13 16
? 13 14
! 14
? 1 7
? 4 7
? 4 5
! 5
? 1 9
? 1 6
? 1 4
? 1 2
! 1
? 1 27
? 10 27
? 16 27
? 20 27
? 23 27
? 20 22
? 21 22
! 22
? 1 21
? 1 14
? 6 14
? 1 5
? 3 5
? 4...

result:

ok Correct (10000 test cases)

Test #5:

score: 0
Accepted
time: 112ms
memory: 3676kb

input:

10000
100
47
47
47
61
71
71
71
72
69
9
2
2
2
1
4
53
46
35
6
6
6
6
6
7
33
3
16
31
31
31
30
32
82
60
29
4
8
23
23
23
24
26
88
39
39
39
51
59
59
61
56
57
71
24
29
59
59
59
60
65
64
63
92
52
52
45
88
88
88
88
88
87
89
24
11
20
5
5
5
6
66
51
51
51
66
45
43
39
38
40
92
43
50
20
20
25
12
13
17
17
48
1
1
1
...

output:

? 1 100
? 35 100
? 35 78
? 35 63
? 64 78
? 69 78
? 69 74
? 71 74
? 69 70
! 70
? 1 9
? 1 6
? 1 4
? 1 2
? 3 4
! 3
? 1 53
? 19 53
? 1 18
? 1 12
? 5 12
? 5 9
? 5 7
? 6 7
! 5
? 1 33
? 1 22
? 23 33
? 27 33
? 30 33
? 30 31
? 32 33
! 33
? 1 82
? 29 82
? 1 28
? 1 18
? 19 28
? 23 28
? 23 26
? 23 24
? 25 26
! ...

result:

ok Correct (10000 test cases)

Test #6:

score: 0
Accepted
time: 129ms
memory: 3680kb

input:

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

output:

? 1 50
? 1 33
? 1 22
? 9 22
? 1 8
? 1 5
? 1 3
? 4 5
! 4
? 1 50
? 1 33
? 1 22
? 23 33
? 27 33
? 23 26
? 23 24
! 24
? 1 50
? 18 50
? 29 50
? 18 28
? 18 24
? 18 21
? 22 24
? 23 24
! 24
? 1 50
? 18 50
? 18 39
? 40 50
? 44 50
? 44 47
? 44 45
? 46 47
! 47
? 1 50
? 18 50
? 29 50
? 37 50
? 42 50
? 45 50
? 4...

result:

ok Correct (10000 test cases)

Test #7:

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

input:

10000
100
76
35
5
5
5
3
11
11
12
100
29
29
29
29
29
29
30
26
26
100
64
64
64
64
69
78
76
84
85
83
100
51
51
57
98
92
79
79
81
83
100
44
75
13
24
1
1
4
6
7
100
64
64
92
41
41
44
35
36
39
100
93
93
86
56
56
49
44
45
47
100
37
37
37
57
76
76
77
70
70
100
76
76
76
76
76
74
86
86
87
85
100
32
32
32
32
31...

output:

? 1 100
? 35 100
? 1 34
? 1 22
? 1 14
? 1 9
? 10 14
? 10 12
? 11 12
! 10
? 1 100
? 1 66
? 23 66
? 23 51
? 23 41
? 23 34
? 27 34
? 23 26
? 25 26
! 25
? 1 100
? 35 100
? 57 100
? 57 85
? 57 75
? 76 85
? 76 81
? 82 85
? 84 85
? 82 83
! 82
? 1 100
? 35 100
? 35 78
? 79 100
? 87 100
? 79 86
? 79 83
? 79 ...

result:

ok Correct (10000 test cases)

Test #8:

score: -100
Wrong Answer
time: 11ms
memory: 3580kb

input:

1000
1000
475
475
728
896
867
831
831
831
841
844
844
845
847
848
1000
278
278
278
446
598
598
573
637
637
637
639
647
645
643
1000
75
128
871
985
686
686
713
732
732
732
735
737
738
739
1000
239
239
239
239
228
432
432
442
485
474
467
471
466
465
1000
978
978
978
978
978
978
978
997
914
914
914
920...

output:

? 1 1000
? 335 1000
? 335 778
? 779 1000
? 853 1000
? 779 852
? 804 852
? 821 852
? 821 841
? 842 852
? 842 848
? 842 845
? 846 848
? 847 848
! 846
? 1 1000
? 1 666
? 223 666
? 223 518
? 519 666
? 569 666
? 569 633
? 634 666
? 634 655
? 634 647
? 634 642
? 643 647
? 645 647
? 643 644
! 644
? 1 1000
...

result:

wrong answer Too many queries , n = 1000 , now_q 16 (test case 364)