当前位置:网站首页>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 ...)
边栏推荐
- 数字转excel的字符串坐标
- How to use layui to display the data in the database in the form of tables
- Sqlalchemy creating MySQL_ Table
- Aardio - Method of self constructed geticonhandle
- 【批处理DOS-CMD命令-汇总和小结】-Cmd窗口中常用操作符(<、<<、&<、>、>>、&>、&、&&、||、|、()、;、@)
- LM08丨网格系列之网格反转(精)
- [question brushing] character statistics [0]
- Anddroid 文本合成语音TTS实现
- 力扣每日一题-第31天-1790.仅执行一次字符串交换能否使两个字符串相等
- Php laraver Wechat payment
猜你喜欢

使用beef劫持用户浏览器

【入门】取近似值
![[getting started] extract non repeating integers](/img/88/3e96df88e980bd98ac112b18a8678c.png)
[getting started] extract non repeating integers

Vhost kick & call principle

window c盘满了

STM32 uses esp01s to go to the cloud, mqtt FX debugging
![[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)

使用 setoolkit 伪造站点窃取用户信息

如何使用layui将数据库中的数据以表格的形式展现出来
![[introduction] approximate value](/img/6b/597178d848dd21110f36601fc31092.png)
[introduction] approximate value
随机推荐
【批处理DOS-CMD-汇总】扩展变量-延迟变量cmd /v:on、cmd /v:off、setlocal enabledelayedexpansion、DisableDelayedExpansion
防“活化”照片蒙混过关,数据宝“活体检测+人脸识别”让刷脸更安全
[batch dos-cmd command - summary and summary] - Common operators in the CMD window (<, < <, & <,>, > >, & >, & >, & &, ||, (),;, @)
Learn the knowledge you need to know about the communication protocol I2C bus
How to get a SharePoint online site created using the office365 group template
5大组合拳,解决校园6大难题,护航教育信息化建设
Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
Latex table
Sqlalchemy creating MySQL_ Table
Gru of RNN
Serial port oscilloscope software ns-scope
Connect timed out of database connection
The difference between interceptors and filters
[untitled]
【无标题】
Access报表实现小计功能
go通用动态重试机制解决方案的实现与封装
Soft keyboard height error
CPU设计实战-第四章实践任务一简单CPU参考设计调试
Hijacking a user's browser with beef