QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#858115 | #8939. Permutation | sandforce | WA | 0ms | 3584kb | C++23 | 2.8kb | 2025-01-16 14:13:40 | 2025-01-16 14:13:58 |
Judging History
answer
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define il inline
#define ll long long
#define lll __int128
#define ull unsigned long long
#define ld long double
#define db double
#define gc getchar();
#define pc(x) putchar(x)
#define O(x) cout<<x<<'\n';
#define adde(x,y) emplace_back(make_pair(x,y))
#define pbset(typ) tree< typ ,null_type,std::less< typ >, __gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>
#define pbmap(typ1,typ2) tree< typ1 , typ2 ,std::less< typ1 >, __gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>
namespace constant_warrior{
template<typename T> inline void fr(T& num){
num=0;short sign=1;char ch=std::getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')sign=-1;
ch=std::getchar();
}
while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
num=num*sign;
}
template<typename T>inline void fw(T x){
if(x<0)std::putchar('-'),x=-x;
if(x>9)fw(x/10);
std::putchar(x%10+'0');
}
template<typename T>inline const T& maxf(const T& a,const T& b){
if(a>b)return a;
return b;
}
template<typename T>inline const T& minf(const T& a,const T& b){
if(a>b)return b;
return a;
}
template<typename T>inline void swapf(T& a,T& b){
a^=b^=a^=b;
}
}
using namespace constant_warrior;
const int N=1<<18;
const double d=(sqrt(5)-1)/2;
int n;
inline int query(int l,int r){
cout<<"? "<<l<<" "<<r<<endl;
int x;cin>>x;
return x;
}
int solve(){
cin>>n;
if(n==1)return 1;
int l=1,r=n,p=query(1,n);
while(r-l>2){
int mid=l+(int)((r-l+1)*d);
if(p<=mid){
if(query(l,mid)==p)r=mid;
else p=query(mid+1,r),l=mid+1;
}else{
mid=r-(int)((r-l+1)*d);
if(query(mid+1,r)==p)l=mid+1;
else p=query(l,mid),r=mid;
}
}
if(r-l==1)return p==l?r:l;
if(p<=l+1){
if(query(l,l+1)==p)return p==l?l+1:l;
return r;
}
else{
if(query(r-1,r)==p)return p==r?r-1:r;
return l;
}
}
int main(){
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
int T=1;cin>>T;
while(T-->0){
int res=solve();
cout<<"! "<<res<<endl;
}
}
/*
暴力出奇迹,卡常能AC。
Violent makes miracle,pursuing better constant can AC.
多测不清空,OI见祖宗。
multitesting without clearing,oier meets the LCA.
十年OI一场空,不开LL见祖宗。
Ten years of OI just AFO,no #define int long long sees the LCA.
似是神犇成才处,实为蒟蒻黄泉路。
It is likely to be the Au medal for the big old,but in fact it is the Si medal for me.
黄题有恨无正解,码力不若小学生。
A yellow problem I can't AC,codeforces is not as NB as HNO3(Dilute nitric acid).
今生无奈入OI,来世不做信竞人。
This life I am a Siliy Being in oi,next life I won't f**k the sh*t of infomatics.
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3584kb
input:
3 5 3 3 2
output:
? 1 5 ? 1 4 ? 1 3 ? 4 4
result:
wrong answer Integer 4 violates the range [5, 5] (test case 1)