QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#297307 | #6303. Inversion | 552Hz | TL | 1ms | 3432kb | C++14 | 2.6kb | 2024-01-04 10:14:58 | 2024-01-04 10:14:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N=2010;
const ll mod=998244353;
//const ll mod=1e9+7;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define vi vector <int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(a) ((int) (a).size())
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsigned int
#define ull unsigned long long
#define i128 __int128
#define pb emplace_back
#define pii pair<int,int>
#define debug(x) std::cout<<x<<endl
//#define endl '\n'
#define mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
template<typename type>
inline void read(type &x)
{
x=0;bool flag(0);char ch=getchar();
while(!isdigit(ch)) flag=ch=='-',ch=getchar();
while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
flag?x=-x:0;
}
template<typename type>
inline void write(type x,bool mode=1)//0为空格,1为换行
{
x<0?x=-x,putchar('-'):0;static short Stack[50],top(0);
do Stack[++top]=x%10,x/=10; while(x);
while(top) putchar(Stack[top--]|48);
mode?putchar('\n'):putchar(' ');
}
//head~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//begin~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//end~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ll a[N],n;
int query(int l,int r){
int cnt=0,x;
if(r-l==1){
cout<<"? "<<l<<" "<<r<<endl;
cout.flush();
cin>>x;
return x;
}
cout<<"? "<<l<<" "<<r<<endl;
cout.flush();
cin>>x;
cnt+=x;
cout<<"? "<<l+1<<" "<<r<<endl;
cout.flush();
cin>>x;
cnt-=x;
cout<<"? "<<l<<" "<<r-1<<endl;
cout.flush();
cin>>x;
cnt-=x;
cout<<"? "<<l+1<<" "<<r-1<<endl;
cout.flush();
cin>>x;
cnt+=x;
return (cnt%2+2)%2;
}
void divide(vector<int> q,int ll,int rr){
if(q.size()==0){
return;
}
if(ll==rr){
a[q[0]]=ll;
return;
}
vector<int>l,r;
for(int i=1;i<q.size();i++){
if(query(q[0],q[i])){
l.push_back(q[i]);
}else{
r.push_back(q[i]);
}
}
a[q[0]]=ll+l.size();
divide(l,ll,ll+l.size());
divide(r,ll+l.size()+1,rr);
}
void solve(){
cin>>n;
vector<int> q;
for(int i=1;i<=n;i++){
q.push_back(i);
}
divide(q,1,n);
cout<<"! ";
cout.flush();
for(int i=1;i<=n;i++){
cout<<a[i]<<" ";
cout.flush();
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int _=1;
while(_--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3432kb
input:
3 0 0 1 0 0
output:
? 1 2 ? 1 3 ? 2 3 ? 1 2 ? 2 2 ! 2 3 1
result:
ok OK, guesses=5
Test #2:
score: -100
Time Limit Exceeded
input:
1993 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0 1 0 1 0 1 0 0 0 1 1 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 0 1 1 0 0 1 0 0 1 0 0 1 0 0 1 1 0 1 0 1 1 1 1 0 0 1 1 1 1 0 1 0 1 1 1 1 1 0 1 0 1 1 1 0 1 0 0 0 1 0 0 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 0 1 0 0 1 1 0 1 1 0 1...
output:
? 1 2 ? 1 3 ? 2 3 ? 1 2 ? 2 2 ? 1 4 ? 2 4 ? 1 3 ? 2 3 ? 1 5 ? 2 5 ? 1 4 ? 2 4 ? 1 6 ? 2 6 ? 1 5 ? 2 5 ? 1 7 ? 2 7 ? 1 6 ? 2 6 ? 1 8 ? 2 8 ? 1 7 ? 2 7 ? 1 9 ? 2 9 ? 1 8 ? 2 8 ? 1 10 ? 2 10 ? 1 9 ? 2 9 ? 1 11 ? 2 11 ? 1 10 ? 2 10 ? 1 12 ? 2 12 ? 1 11 ? 2 11 ? 1 13 ? 2 13 ? 1 12 ? 2 12 ? 1 14 ? 2 14 ? ...