当前位置:网站首页>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 ...)
边栏推荐
- 【入门】提取不重复的整数
- 使用 setoolkit 伪造站点窃取用户信息
- 038 network security JS
- [redis] it takes you through redis installation and connection at one go
- [batch DOS CMD summary] extension variables - delay variables CMD /v:on, CMD /v:off, SETLOCAL enabledelayedexpansion, disabledelayedexpansion
- How to troubleshoot SharePoint online map network drive failure?
- CPU设计实战-第四章实践任务一简单CPU参考设计调试
- OJ输入输出练习
- 0 basic introduction to single chip microcomputer: how to use digital multimeter and precautions
- STM32 uses esp01s to go to the cloud, mqtt FX debugging
猜你喜欢

软键盘高度报错

如何使用layui将数据库中的数据以表格的形式展现出来

OJ输入输出练习

Erreur de hauteur du clavier souple

0 basic introduction to single chip microcomputer: how to use digital multimeter and precautions

How to troubleshoot SharePoint online map network drive failure?

How to check ad user information?

凸印的印刷原理及工艺介绍

Access report realizes subtotal function

Office365 - how to use stream app to watch offline files at any time
随机推荐
php laravel微信支付
Set up file server Minio for quick use
量化交易之读书篇 - 《征服市场的人》读书笔记
slice扩容机制分析
手工挖XSS漏洞
Latex table
Rumtime 1200 upgrade: London upgrade support, pledge function update and more
谈谈数字化转型的几个关键问题
Scala语言学习-07-构造器
[force deduction 10 days SQL introduction] Day10 control flow
Programmer's regimen
[getting started] input n integers and output the smallest K of them
[kv260] generate chip temperature curve with xadc
How to check ad user information?
初学者如何正确理解google官方建议架构原则(疑问?)
[question brushing] character statistics [0]
empirical study and case study
力扣每日一题-第31天-1790.仅执行一次字符串交换能否使两个字符串相等
Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
window c盘满了