QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#566731 | #8941. Even or Odd Spanning Tree | UNos_maricones | WA | 0ms | 3664kb | C++23 | 2.0kb | 2024-09-16 01:22:49 | 2024-09-16 01:22:50 |
Judging History
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));
}
}
Details
Tip: Click on the bar to expand more detailed information
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