QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#566731#8941. Even or Odd Spanning TreeUNos_mariconesWA 0ms3664kbC++232.0kb2024-09-16 01:22:492024-09-16 01:22:50

Judging History

你现在查看的是最新测评结果

  • [2024-09-16 01:22:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3664kb
  • [2024-09-16 01:22:49]
  • 提交

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 mitadDer(int l, int r){
  int sum = l + r;
  if(sum % 2 == 0){
    return sum / 2 + 1;
  }else return sum / 2 + 1;

}
int mitadIzq(int l, int r){
  int sum = l + r;
  if(sum % 2 == 0){
    return sum / 2 - 1;
  }else return sum / 2 ;

}


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 mid = (l + r )/2;

  int q1, q2;
  if(p <= mid){
    int mita = mitadIzq(l, r);
    int s = ask(l, mita);
    if(s == p){
      return solv(l, mita, p);
    }
    q2 = mitadIzq(mita + 1, r);
    s = ask(p, q2);
    if(s == p){
      return solv(mita + 1, q2);
    }else{
      return solv(q2 + 1, r);
    }
  }else{
    int mita = mitadDer(l, r);
    int s = ask(mita, r);
    if(s == p){
      return solv(mita, r, p);
    }
    q1 = mitadDer(l, mita - 1);
    s = ask(q1, p);
    if(s == p){
      return solv(q1, mita - 1);
    }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));

  }


}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3664kb

input:

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

output:

? 1 2
! 2
! 1
? 1 2
? 2 5
! 1

result:

wrong output format Expected integer, but "?" found