QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#542550 | #8939. Permutation | ucup-team520# | WA | 37ms | 4000kb | C++20 | 2.0kb | 2024-09-01 02:33:09 | 2024-09-01 02:33:10 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define nline "\n"
#define f first
#define s second
#define sz(x) x.size()
#define vl vector<ll>
const ll INF_MUL=1e13;
const ll INF_ADD=1e18;
#define all(x) x.begin(),x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
const ll MOD=998244353;
const ll MAX=500500;
map<pair<ll,ll>,ll> cache;
ll query(ll l,ll r){
if(cache.find({l,r})!=cache.end()){
return cache[{l,r}];
}
cout<<"? "<<l<<" "<<r<<endl;
ll x; cin>>x;
cache[{l,r}]=x;
return x;
}
ll getv(ll l,ll r){
ll x=rng()%(r-l+1);
return l+x;
}
ll solve(ll l,ll r,ll pos=-1){
if(l==r){
return l;
}
if(l+1==r){
return l+r-query(l,r);
}
if(pos==-1){
pos=query(l,r);
}
ll now=(l+r)/2;
if(pos<=now){
if(query(l,now)==pos){
return solve(l,now,pos);
}
else{
return solve(now+1,r,-1);
}
}
else{
if(query(now,r)==pos){
return solve(now,r,pos);
}
else{
return solve(l,now-1,-1);
}
}
}
void solve(){
ll n; cin>>n;
cache.clear();
ll ans=solve(1,n,-1);
cout<<"! "<<ans<<endl;
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll test_cases=1;
cin>>test_cases;
while(test_cases--){
solve();
}
cout<<fixed<<setprecision(10);
cerr<<"Time:"<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3980kb
input:
3 5 3 2 5 6 6 3 1 4 3 3 2
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 2 4 ? 2 3 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 37ms
memory: 3988kb
input:
10000 10 2 2 3 5 10 10 10 7 5 10 5 1 10 9 6 10 4 4 4 4 10 10 6 3 4 10 3 3 3 2 10 1 5 9 9 9 10 1 3 8 8 8 10 2 4 9 9 8 10 3 3 1 5 10 4 1 7 8 9 10 8 7 1 2 4 10 4 1 9 9 8 10 7 7 7 6 10 5 1 7 6 10 10 8 8 8 7 9 10 2 1 7 7 7 10 6 6 5 10 10 10 1 3 8 8 8 10 7 9 4 4 4 10 7 8 4 4 4 10 3 4 7 8 10 10 4 4 4 3 10 ...
output:
? 1 10 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 10 ? 5 10 ? 7 10 ? 5 6 ! 6 ? 1 10 ? 1 5 ? 6 10 ? 8 10 ? 6 7 ! 7 ? 1 10 ? 1 5 ? 3 5 ? 3 4 ! 3 ? 1 10 ? 5 10 ? 1 4 ? 2 4 ! 1 ? 1 10 ? 1 5 ? 1 3 ? 2 3 ! 1 ? 1 10 ? 1 5 ? 6 10 ? 8 10 ? 8 9 ! 8 ? 1 10 ? 1 5 ? 6 10 ? 6 8 ? 7 8 ! 7 ? 1 10 ? 1 5 ? 6 10 ? 8 10 ? 8 9 ! 10 ? 1 ...
result:
ok Correct (10000 test cases)
Test #3:
score: -100
Wrong Answer
time: 5ms
memory: 4000kb
input:
10000 3 1 2 11 5 5 5 5 4 2 2 19 3 3 4 6 8 9 7 5 7 1 2 3 3 3 19 6 6 10 1 2 4 2 2 15 11 11 11 11 10 14 1 1 1 2 3 16 4 4 1 8 8 7 3 3 2 19 13 17 5 5 5 4 2 2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