QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#565403#8939. PermutationUNos_maricones#WA 2ms3688kbC++231.4kb2024-09-15 21:11:442024-09-15 21:11:50

Judging History

This is the latest submission verdict.

  • [2024-09-15 21:11:50]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3688kb
  • [2024-09-15 21:11:44]
  • Submitted

answer

#include<bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define pb push_back
using namespace std;
int ask(int l, int r){
  if(l == r)return l;
  cout << "? " << l << " " << r << endl;
  cout.flush();
  int answ;
  cin >> answ;
  return answ;
}
void responder(int v){
  cout << "! " << v << endl;
  cout.flush();
}

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--){
    int n;
    cin >> n;
    int p = ask(1, n);

    bool atras = false;
    if(p == 1)atras = false;
    else if(p == n)atras = true;
    else if(p <= n/2 && ask(1, p) == p || p > n/2 && ask(p, n) != p)atras = true;
    int answ = 0;
    if(atras){

      int li = 1, ls = p - 1, mid;
      while(li + 1 < ls){
        mid = (li + ls)/2;
        if(ask(mid, p) == p)li = mid;
        else ls = mid - 1;
      }
      for(int i = ls ; i >= li ; i --){
        if(ask(i, p)){
          answ = i;
          break;
        }
      }
    }else{
      int li = p + 1, ls = n, mid;
      while(li + 1 < ls){
        mid = (li + ls)/2;
        if(ask(p, mid) == p)ls = mid;
        else li = mid + 1;
      }
      for(int i = li ; i <= ls ; i ++){
        if(ask(p, i)){
          answ = i;
          break;
        }
      }
    }
    responder(answ);

  }


}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3668kb

input:

10000
10
2
1
2
2
3

output:

? 1 10
? 1 2
? 2 6
? 2 4
? 2 3
! 3

result:

wrong answer Wrong prediction (test case 1)