当前位置:网站首页>【集训Day1】 Dwarves line up
【集训Day1】 Dwarves line up
2022-07-26 16:55:00 【SSL_GYX】
Dwarves line up

解题思路
用线段树维护每个人当前的位置的区间最大值和最小值,查询时若区间的长度和位置的最大值与最小值的差相对,则已经形成。
code
#include<iostream>
#include<cstdio>
using namespace std;
int n,m;
int a[200010];
struct abc{
int maxn,minn;
}tree[800010];
abc mix(abc a,abc b)
{
return (abc){
max(a.maxn,b.maxn),min(a.minn,b.minn)};
}
void in(int num,int l,int r,int x,int a)
{
tree[num].maxn=max(tree[num].maxn,a);
tree[num].minn=min(tree[num].minn,a);
if(l==r)
return;
int mid=(l+r)/2;
if(x<=mid)
in(num*2,l,mid,x,a);
else
in(num*2+1,mid+1,r,x,a);
}
void chang(int num,int l,int r,int x,int a)
{
if(l==r)
{
tree[num]=(abc){
a,a};
return;
}
int mid=(l+r)/2;
if(x<=mid)
chang(num*2,l,mid,x,a);
else
chang(num*2+1,mid+1,r,x,a);
tree[num].maxn=max(tree[num*2].maxn,tree[num*2+1].maxn);
tree[num].minn=min(tree[num*2].minn,tree[num*2+1].minn);
}
abc fd(int num,int l,int r,int a,int b)
{
if(l==a&&r==b)
return tree[num];
int mid=(l+r)/2;
if(b<=mid)
return fd(num*2,l,mid,a,b);
else if(a>mid)
return fd(num*2+1,mid+1,r,a,b);
else
return mix(fd(num*2,l,mid,a,mid),fd(num*2+1,mid+1,r,mid+1,b));
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n*4;i++) tree[i].minn=0x3f3f3f3f;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
in(1,1,n,a[i],i);
}
while(m--)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
if(x==1)
{
chang(1,1,n,a[z],y);
chang(1,1,n,a[y],z);
swap(a[z],a[y]);
}
else
{
abc t=fd(1,1,n,y,z);
if(t.maxn-t.minn==z-y)
printf("YES\n");
else
printf("NO\n");
}
}
}
边栏推荐
- Pytest(思维导图)
- TD database syntax
- Kudu design tablet
- Heavy announcement! Icml2022 Awards: 15 outstanding papers, selected by Fudan University, Xiamen University and Shanghai Jiaotong University
- 第16周OJ实践1 计算该日在本年中是第几天
- Tree DP problem
- 6-19 vulnerability exploitation -nsf to obtain the target password file
- [cloud native] IVX low code development was introduced into Tencent map and previewed online
- 浅析接口测试
- How to use align regexp to align userscript meta information
猜你喜欢

In depth exploration of ribbon load balancing

Definition of graph traversal and depth first search and breadth first search (I)

6-19漏洞利用-nsf获取目标密码文件

来吧开发者!不只为了 20 万奖金,试试用最好的“积木”来一场头脑风暴吧!

Asemi rectifier bridge kbpc3510, kbpc3510 package, kbpc3510 application

SCCM tips - improve the download speed of drivers and shorten the deployment time of the system when deploying the system

点击劫持攻击

国际大咖 VS 本土开源新星 | ApacheCon Asia 主题演讲议程全览

Kudu design tablet

The latest interface of Taobao / tmall keyword search
随机推荐
What kind of product is the Jetson nano? (how about the performance of Jetson nano)
Eureka Registry - from entry to application
如何快速使用 ELisp 进行插件编写
Everything is available Cassandra: the fairy database behind Huawei tag
【OpenCV 例程 300篇】240. OpenCV 中的 Shi-Tomas 角点检测
Kudu design tablet
leetcode:1206. 设计跳表【跳表板子】
pip安装模块,报错
Ascend目标检测与识别-定制自己的AI应用
Tree DP problem
【模板】线段树 1
E-week finance | postal Huiwanjia bank opened; Wechat public call to stop four types of financial marketing publicity
(25) top level menu of blender source code analysis blender menu
重磅!《2022中国开源发展蓝皮书》正式发布
OpenWrt之feeds.conf.default详解
JS closure simulates private variable interview questions and immediately executes function Iife
[cloud native kubernetes actual combat] kubeopertor installation tutorial
What is a test case? How to design?
In the first half of the year, sales increased by 10% against the trend. You can always trust Volvo, which is persistent and safe
On the growth of data technicians