QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#422500#8239. Mysterious Treelmeowdn#TL 0ms0kbC++141.9kb2024-05-27 15:20:112024-05-27 15:20:11

Judging History

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

  • [2024-05-27 15:20:11]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-05-27 15:20:11]
  • 提交

answer

//Shirasu Azusa 2024.5
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;  
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} 
  return x*w;
}

bool query(int u,int v) {
  printf("? %lld %lld\n",u,v);
  return read();
}
void work() {
  int n=read(), x=0, y=0; bool ch=0;
  rep(i,1,n) {
    int j=(i==n?1:i+1);
    if(query(i,j)) {
      if(x) {
        ch=1; break;
      } else {
        x=i, y=j;
      }
    }
    i++;
  }
  if(!x) ch=1;
  if(ch) {
    puts("! 1"); fflush(stdout);
    return;
  }
  int z=1, w=1;
  while(z==x||z==y) z++;
  while(w==z||w==x||w==y) w++;
  if(query(x,z)) {
    if(query(x,w)) {
      puts("! 2"); fflush(stdout);
    } else {
      puts("! 1"); fflush(stdout);
    }
  } else {
    if(query(y,w)&&query(y,z)) {
      puts("! 2"); fflush(stdout);
    } else {
      puts("! 1"); fflush(stdout);
    }
  }
}

signed main() {
  int T=read();
  while(T--) {
    work();
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

2
4

output:


result: