QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#566694#8939. PermutationUNos_maricones#WA 121ms3716kbC++231.7kb2024-09-16 01:13:122024-09-16 01:13:14

Judging History

This is the latest submission verdict.

  • [2024-09-16 01:13:14]
  • Judged
  • Verdict: WA
  • Time: 121ms
  • Memory: 3716kb
  • [2024-09-16 01:13:12]
  • Submitted

answer

#include<bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define pb push_back
using namespace std;

map<pair<int, int>, int > respuestas;

int rangos = 0, n;

int ask(int l, int r){
  if(l >= r)return -1;
  rangos += r - l + 1;
  //assert(rangos <= 3* n);
  if(respuestas.count({l, r})){
    return respuestas[{l, r}];
  }
  cout << "? " << l << " " << r << endl;
  cout.flush();
  int answ;
  cin >> answ;
  respuestas[{l, r}] = answ;
  return answ;
}
void responder(int v){
  cout << "! " << v << endl;
  cout.flush();
}

int solv(int l, int r, int p);
int solv(int l, int r){
  if(l == r)return l;
  int p = ask(l, r);
  return solv(l, r, p);
}

int solv(int l, int r, int p){
  if(l == r)return l;
  if(p == l && r - l == 1)return r;
  if(p == r && r - l == 1)return l;
  int mita = (l + r )/2;

  int q1, q2;
  if(p <= mita){
    int s = ask(l, mita);
    if(s == p){
      return solv(l, mita, p);
    }
    q2 = (mita + 1 + r - 1)/2;
    s = ask(p, q2);
    if(s == p){
      return solv(mita + 1, q2);
    }else{
      return solv(q2 + 1, r);
    }
  }else{

    int s = ask(mita + 1, r);
    if(s == p){
      return solv(mita + 1, r, p);
    }
    q1 = (l + mita + 2) / 2;
    s = ask(q1, p);
    if(s == p){
      return solv(q1, mita);
    }else{
      return solv(l, q1-1);
    }

  }
}





int main(){
  #ifdef LOCAL
  //freopen("in.txt", "r", stdin);
  #endif // LOCAL

  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(NULL);

  int t;
  cin >> t;
  while(t--){
      respuestas.clear();
    cin >> n;
    rangos = 0;
    responder(solv(1, n));

  }


}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: 0
Accepted
time: 89ms
memory: 3576kb

input:

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

output:

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

result:

ok Correct (10000 test cases)

Test #3:

score: 0
Accepted
time: 82ms
memory: 3712kb

input:

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

output:

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

result:

ok Correct (10000 test cases)

Test #4:

score: 0
Accepted
time: 97ms
memory: 3572kb

input:

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

output:

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

result:

ok Correct (10000 test cases)

Test #5:

score: 0
Accepted
time: 87ms
memory: 3656kb

input:

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

output:

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

result:

ok Correct (10000 test cases)

Test #6:

score: 0
Accepted
time: 98ms
memory: 3588kb

input:

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

output:

? 1 50
? 1 25
? 1 13
? 8 13
? 5 10
? 1 4
? 1 2
? 2 3
! 4
? 1 50
? 1 25
? 1 13
? 11 19
? 20 25
? 23 25
? 23 24
! 24
? 1 50
? 26 50
? 14 44
? 14 25
? 20 25
? 20 22
? 20 23
? 24 25
! 24
? 1 50
? 1 25
? 24 37
? 38 50
? 45 50
? 45 47
? 45 46
! 47
? 1 50
? 26 50
? 39 50
? 45 50
? 48 50
? 47 50
? 45 46
! 4...

result:

ok Correct (10000 test cases)

Test #7:

score: 0
Accepted
time: 121ms
memory: 3652kb

input:

10000
100
76
78
35
5
5
3
5
9
8
100
29
29
50
29
20
20
22
22
24
100
64
64
69
64
86
86
87
84
83
100
51
51
57
51
79
81
79
84
83
100
44
44
50
42
13
13
12
12
9
100
64
92
64
41
44
41
33
35
35
37
100
93
56
93
40
40
44
40
45
45
100
37
2
37
57
54
57
68
68
67
100
76
76
76
76
80
76
85
85
100
32
32
32
31
44
49
4...

output:

? 1 100
? 51 100
? 26 76
? 1 25
? 1 13
? 1 7
? 5 10
? 8 10
? 8 9
! 10
? 1 100
? 1 50
? 26 50
? 14 29
? 14 25
? 20 25
? 20 22
? 20 23
? 24 25
! 25
? 1 100
? 51 100
? 51 75
? 64 87
? 76 87
? 82 87
? 85 87
? 84 86
? 82 83
! 82
? 1 100
? 51 100
? 51 75
? 51 87
? 76 87
? 76 81
? 79 84
? 82 84
? 83 84
! 8...

result:

ok Correct (10000 test cases)

Test #8:

score: 0
Accepted
time: 14ms
memory: 3592kb

input:

1000
1000
475
426
728
896
974
896
867
867
869
858
847
847
848
847
1000
278
17
278
598
534
598
679
665
679
652
655
647
645
645
1000
75
128
75
607
604
644
713
695
732
749
745
749
742
741
742
1000
239
239
45
350
432
429
432
442
451
458
462
462
463
462
1000
978
978
978
978
997
978
914
920
914
927
927
92...

output:

? 1 1000
? 1 500
? 475 750
? 751 1000
? 876 1000
? 814 896
? 814 875
? 845 875
? 861 875
? 853 867
? 845 852
? 845 848
? 847 848
? 846 847
! 846
? 1 1000
? 1 500
? 278 750
? 501 750
? 501 625
? 598 687
? 626 687
? 657 687
? 642 679
? 642 656
? 650 656
? 646 652
? 642 645
? 644 645
! 644
? 1 1000
? 1...

result:

ok Correct (1000 test cases)

Test #9:

score: 0
Accepted
time: 13ms
memory: 3588kb

input:

1017
272
246
186
246
111
110
110
73
73
71
73
75
114
105
91
91
2
2
2
2
2
910
173
173
173
127
127
14
29
29
56
51
56
48
48
726
229
229
201
201
63
71
63
28
28
28
29
27
24
861
315
104
315
491
528
551
632
641
614
593
593
593
594
593
1984
133
133
406
133
571
512
571
673
682
673
650
650
651
650
647
1145
988...

output:

? 1 272
? 137 272
? 69 246
? 69 136
? 103 136
? 86 111
? 69 85
? 69 77
? 69 73
? 73 75
? 74 75
! 74
? 1 114
? 58 114
? 30 105
? 1 29
? 1 15
? 1 8
? 1 4
? 1 2
! 1
? 1 910
? 1 455
? 1 228
? 115 228
? 58 173
? 1 57
? 1 29
? 14 43
? 44 57
? 51 57
? 48 56
? 48 50
? 48 49
! 49
? 1 726
? 1 363
? 183 363
? ...

result:

ok Correct (1017 test cases)

Test #10:

score: 0
Accepted
time: 3ms
memory: 3708kb

input:

10
100000
3893
3893
3505
30673
43582
43582
43582
43582
43582
43470
43582
43242
43197
43242
43289
43298
43279
43268
43267
43268
43272
43272
100000
32066
19090
54928
88585
88585
88585
89959
88585
91599
91474
91599
91257
91257
91225
91257
91325
91312
91339
91348
91349
91348
91354
91353
100000
50288
867...

output:

? 1 100000
? 1 50000
? 1 25000
? 3893 37500
? 37501 50000
? 37501 43750
? 40626 43750
? 42189 43750
? 42970 43750
? 43361 43750
? 43166 43582
? 43166 43360
? 43166 43263
? 43242 43311
? 43264 43311
? 43288 43311
? 43276 43289
? 43264 43275
? 43264 43269
? 43268 43272
? 43270 43272
? 43271 43272
! 43...

result:

ok Correct (10 test cases)

Test #11:

score: 0
Accepted
time: 4ms
memory: 3592kb

input:

21
84335
47947
60969
22445
9296
1509
11772
20931
19830
20931
17510
17510
17606
17510
17352
17352
17346
17352
17338
17337
17328
17320
17318
17321
17323
159962
128177
145530
128177
54814
54814
59035
49869
40850
42103
40850
43214
43214
43231
43550
43675
43675
43675
43670
43689
43695
43695
43696
43694
4...

output:

? 1 84335
? 42169 84335
? 21085 47947
? 1 21084
? 1 10542
? 9296 15813
? 15814 21084
? 18450 21084
? 17132 20931
? 17132 18449
? 17132 17790
? 17462 17790
? 17297 17510
? 17297 17461
? 17297 17379
? 17339 17379
? 17318 17352
? 17318 17338
? 17329 17338
? 17324 17338
? 17318 17323
? 17318 17320
? 173...

result:

ok Correct (21 test cases)

Test #12:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

1
1000000
641602
641602
561698
641602
783270
783270
783270
783270
786055
786055
794273
794682
794682
796734
796734
796734
796686
796788
796850
796850
796851
796850
796864
796864
796863
796864

output:

? 1 1000000
? 500001 1000000
? 500001 750000
? 641602 875000
? 750001 875000
? 750001 812500
? 781251 812500
? 781251 796875
? 781251 789063
? 783270 792969
? 792970 796875
? 792970 794922
? 794273 795898
? 795899 796875
? 796388 796875
? 796632 796875
? 796632 796753
? 796734 796814
? 796815 796875...

result:

ok Correct (1 test case)

Test #13:

score: 0
Accepted
time: 2ms
memory: 3716kb

input:

16
232936
229707
229707
229707
229707
229707
231039
229707
223556
223533
224031
225261
225261
225261
225290
225290
225375
225395
225407
225417
225419
225417
225425
225425
8676
6498
6498
6498
5867
4978
4731
4731
4731
4731
4717
4717
4684
4681
4690
4692
4693
4692
221085
172303
209705
142841
20545
20545...

output:

? 1 232936
? 116469 232936
? 174703 232936
? 203820 232936
? 218379 232936
? 225658 232936
? 222019 229707
? 222019 225657
? 222019 223838
? 223556 224747
? 224748 225657
? 225203 225657
? 225203 225430
? 225203 225316
? 225261 225373
? 225374 225430
? 225374 225402
? 225375 225416
? 225417 225430
?...

result:

ok Correct (16 test cases)

Test #14:

score: 0
Accepted
time: 48ms
memory: 3580kb

input:

1994
667
666
667
665
167
166
166
42
41
41
11
10
10
3
2
374
373
374
372
94
93
93
24
23
23
6
5
5
2
488
486
488
485
122
121
121
31
30
30
8
7
7
2
922
921
922
920
231
230
230
58
57
57
15
14
14
4
3
3
639
637
639
636
160
159
159
40
39
39
10
9
9
3
2
353
350
353
349
89
88
88
23
22
22
6
5
5
2
71
66
71
65
18
1...

output:

? 1 667
? 335 667
? 168 666
? 1 167
? 85 167
? 43 167
? 1 42
? 22 42
? 12 42
? 1 11
? 7 11
? 4 11
? 1 3
? 2 3
! 1
? 1 374
? 188 374
? 95 373
? 1 94
? 48 94
? 25 94
? 1 24
? 13 24
? 7 24
? 1 6
? 4 6
? 3 6
? 1 2
! 1
? 1 488
? 245 488
? 123 486
? 1 122
? 62 122
? 32 122
? 1 31
? 17 31
? 9 31
? 1 8
? 5 ...

result:

ok Correct (1994 test cases)

Test #15:

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

input:

18
153667
153667
153666
153666
38417
38416
38416
9605
9604
9604
2402
2401
2401
601
600
600
151
150
150
38
37
37
10
9
9
3

output:

? 1 153667
? 76835 153667
? 38418 153667
? 1 38417
? 19210 38417
? 9606 38417
? 1 9605
? 4804 9605
? 2403 9605
? 1 2402
? 1202 2402
? 602 2402
? 1 601
? 302 601
? 152 601
? 1 151
? 77 151
? 39 151
? 1 38
? 20 38
? 11 38
? 1 10
? 6 10
? 4 10
? 1 3
? 2 3

result:

wrong answer Too long queries, n = 153667, now length 461003 (test case 1)