当前位置:网站首页>Codeworks round 803 (Div. 2) VP supplement
Codeworks round 803 (Div. 2) VP supplement
2022-07-01 08:13:00 【sophilex】
Carelessness :
There is one 1-n In ascending order , Choose from n-1/2 Exchange disjoint numbers , There will be a number that doesn't move .
After the operation, you will get a final sequence .
Interaction problem . Every time I ask l,r, Returns the... Of the final sequence l To r The ascending order of elements
15 The element that has not changed its position was found in the question
Ideas :
It's done , It's just a little hard ...( Another day when I can't read the questions
n What is the scope 1e4 So big , But I can only ask 15 A question , Almost 1/log The level of , Then naturally, you can think of two points .
If you deal with an interval at a time , The interval can be divided into two parts , You might as well check the left half first , If the left half is ok , That means our answer is in the right half .
Now the only problem is how to judge whether there is a problem in an interval .
You can define that an element is legal for an interval , If its element value satisfies val>=l&&val<=r.
Now look at our interval , Legal elements in this interval , There are only two cases of it :
1. It has not been exchanged , This is the answer we need .
2. It's swapped , But it is still within the range , So it is swapped with another element in the interval , We can see from this , The legal elements exchanged must be in pairs .
therefore :
If there are odd legal numbers in the current interval , It must be some pairs of legal elements of exchange and an answer , Let's divide this interval by two . If there are even numbers , So long, it means that the answer is in another range .
Finally, the range becomes 1 When , That value is the answer .
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=2e5+10;
ll n,m,k;
ll t;
ll a;
ll mas[N];
void cx(ll l,ll r)
{
if(l==r)
{
std::cout<<"? "<<l<<' '<<r<<endl;
cin>>a;
std::cout<<"! "<<a<<endl;
return;
}
ll mid=l+r>>1;
ll cnt=0;
std::cout<<"? "<<l<<" "<<mid<<endl;
for(int i=1;i<=mid-l+1;++i) std::cin>>mas[i];
for(int i=1;i<=mid-l+1;++i)
{
if(mas[i]>=l&&mas[i]<=mid) cnt++;
}
if(cnt%2)
{
cx(l,mid);
}
else cx(mid+1,r);
}
void solve()
{
std::cin>>n;
cx(1,n);
}
int main()
{//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
std::cin>>t;
while(t--)
{
solve();
}
return 0;
}( I don't know why , I always feel that interactive questions are more interesting than ordinary questions ...)
边栏推荐
- Programmer's regimen
- Day5: scanner object, next() and nextline(), sequential structure, selection structure, circular structure
- 如何使用layui将数据库中的数据以表格的形式展现出来
- Use threejs simple Web3D effect
- Instead of houses, another kind of capital in China is rising
- Transaction method call @transactional
- [staff] high and low octave mark (the notes in the high octave mark | mark range are increased by one octave as a whole | low octave mark | mark range are decreased by one octave as a whole)
- sqlalchemy创建MySQL_Table
- Rk3399 platform development series explanation (network debugging) 7.30. What will affect the sending process of TCP packets?
- Insufficient executors to build thread pool
猜你喜欢

Use threejs simple Web3D effect

Erreur de hauteur du clavier souple

window c盘满了

Principle and process of embossing
![[staff] high and low octave mark (the notes in the high octave mark | mark range are increased by one octave as a whole | low octave mark | mark range are decreased by one octave as a whole)](/img/ff/ebd936eaa6e57b1eabb691b0642957.jpg)
[staff] high and low octave mark (the notes in the high octave mark | mark range are increased by one octave as a whole | low octave mark | mark range are decreased by one octave as a whole)
![[batch DOS CMD summary] extension variables - delay variables CMD /v:on, CMD /v:off, SETLOCAL enabledelayedexpansion, disabledelayedexpansion](/img/ce/6c9e4f2c54710610e8b1f68d6d8088.png)
[batch DOS CMD summary] extension variables - delay variables CMD /v:on, CMD /v:off, SETLOCAL enabledelayedexpansion, disabledelayedexpansion

软键盘高度报错

Latex table

【网站架构】一招搞定90%的分布式事务,实打实介绍数据库事务、分布式事务的工作原理应用场景

Airsim雷达相机融合生成彩色点云
随机推荐
一套十万级TPS的IM综合消息系统的架构实践与思考
软键盘高度报错
5大组合拳,解决校园6大难题,护航教育信息化建设
Instead of houses, another kind of capital in China is rising
Aardio - [problem] the problem of memory growth during the callback of bass Library
[kv260] generate chip temperature curve with xadc
How to use layui to display the data in the database in the form of tables
empirical study and case study
postgresql源码学习(26)—— Windows vscode远程调试Linux上的postgresql
Using settoolkit to forge sites to steal user information
Teach you how to apply for domestic trademark online step by step
【批处理DOS-CMD命令-汇总和小结】-Cmd窗口中常用操作符(<、<<、&<、>、>>、&>、&、&&、||、|、()、;、@)
Airsim雷达相机融合生成彩色点云
P4 安装bmv2 详细教程
Microsoft stream - how to modify video subtitles
The Windows C disk is full
[untitled]
038 network security JS
Uni hot update
String coordinates of number to excel