QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#565530#8939. PermutationUNos_maricones#WA 0ms3612kbC++231.6kb2024-09-15 21:35:132024-09-15 21:35:14

Judging History

This is the latest submission verdict.

  • [2024-09-15 21:35:14]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3612kb
  • [2024-09-15 21:35:13]
  • 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 ask(int l, int r){
  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 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();
    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: 0ms
memory: 3612kb

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3604kb

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)