J - Joseph and Tests Gym - 102020J (二分+线段树)
题目链接:https://cn.vjudge.net/contest/283920#problem/J
题目大意:首先给你n个门的高度,然后q次询问,每一次询问包括两种操作,第一种操作是将当前的门的高度提高到某一个值,第二种操作是给你一个起点,以及最大的跨越高度d,问你最远能走到哪里(如果能从a到达b则说明|Ha-Hb|<=d)。
具体思路:用线段树维护每一个区间的最大值,对于操作1就是单点修改了,对于操作二的话,用二分+线段树的方法查询最远能到达的地方就可以了。
AC代码:
#include<iostream>
#include<stack>
#include<cstring>
#include<iomanip>
#include<stdio.h>
#include<algorithm>
#include<cmath>
using namespace std;
# define ll long long
# define lson l,m,rt<<
# define rson m+,r,rt<<|
const int maxn = 2e5+;
int tree[maxn<<],a[maxn];
int maxx;
void up(int rt)
{
tree[rt]=max(tree[rt<<],tree[rt<<|]);
}
void buildtree(int l,int r,int rt)
{
if(l==r)
{
tree[rt]=abs(a[l]-a[l+]);
return ;
}
int m=(l+r)>>;
buildtree(lson);
buildtree(rson);
up(rt);
}
void update(int l,int r,int rt,int pos)
{
if(l==r)
{
tree[rt]=abs(a[l+]-a[l]);
return ;
}
int m=(l+r)>>;
if(pos<=m)
update(lson,pos);
else
update(rson,pos);
up(rt);
}
void query(int l,int r,int rt,int L,int R)
{
if(L<=l&&R>=r)
{
maxx=max(maxx,tree[rt]);
return ;
}
int m=(l+r)>>;
if(L<=m)
query(lson,L,R);
if(R>m)
query(rson,L,R);
up(rt);
}
int Find(int n,int t2,int t3)
{
int l=t2,r=n;
int ans=n+;
while(l<=r)
{
int mid=(l+r)>>;
maxx=;
query(,n,,l,mid);
// cout<<l<<" "<<r<<" "<<maxx<<" "<<t3<<endl;
if(maxx<=t3)
{
l=mid+;
}
else
{
ans=mid;
r=mid-;
}
}
return ans;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
int q,t1,t2,t3;
if(n==){
scanf("%d",&q);
while(q--){
scanf("%d %d %d",&t1,&t2,&t3);
if(t1==){
a[t2]=t3;
}
else if(t1==){
printf("1\n");
}
}
}
else{
buildtree(,n-,); scanf("%d",&q);
while(q--)
{
scanf("%d %d %d",&t1,&t2,&t3);
// cout<<t1<<" "<<t2<<" "<<t3<<endl;
if(t1==)
{
a[t2]=t3;
if(t2->)
update(,n-,,t2-);
if(t2<=n-)
update(,n-,,t2);
}
else if(t1==)
{
int ans=Find(n-,t2,t3);
printf("%d\n",ans);
}
}
}
return ;
}
J - Joseph and Tests Gym - 102020J (二分+线段树)的更多相关文章
- Hacker Cups and Balls Gym - 101234A 二分+线段树
题目:题目链接 题意:有编号从1到n的n个球和n个杯子. 每一个杯子里有一个球, 进行m次排序操作,每次操作给出l,r. 如果l<r,将[l,r]范围内的球按升序排序, 否则降序排, 问中间位置 ...
- Codeforces Gym 100231B Intervals 线段树+二分+贪心
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...
- K-th occurrence HDU - 6704 (后缀数组+二分线段树+主席树)
大意: 给定串s, q个询问(l,r,k), 求子串s[l,r]的第kk次出现位置. 这是一篇很好的题解: https://blog.csdn.net/sdauguanweihong/article/ ...
- HDU4614 Vases and Flowers 二分+线段树
分析:感觉一看就是二分+线段树,没啥好想的,唯一注意,当开始摆花时,注意和最多能放的比大小 #include<iostream> #include<cmath> #includ ...
- Educational Codeforces Round 61 D 二分 + 线段树
https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...
- 【BZOJ-3110】K大数查询 整体二分 + 线段树
3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6265 Solved: 2060[Submit][Sta ...
- hdu6070 Dirt Ratio 二分+线段树
/** 题目:hdu6070 Dirt Ratio 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6070 题意:给定n个数,求1.0*x/y最小是多少.x ...
- 【Codeforces】Gym 101608G WiFi Password 二分+线段树
题意 给定$n$个数,求有最长的区间长度使得区间内数的按位或小于等于给定$v$ 二分区间长度,线段树处理出区间或,对每一位区间判断 时间复杂度$O(n\log n \log n)$ 代码 #inclu ...
- 牛客网 中南林业科技大学第十一届程序设计大赛J题 二分+线段树
https://www.nowcoder.com/acm/contest/124#question 题意 找第一个不小于K的数的下标,然后对它前一个数加一 解析 我们可以维护一个最大值数组 1 ...
随机推荐
- Educational Codeforces Round 58 Div. 2 自闭记
明明多个几秒就能场上AK了.自闭. A:签到. #include<iostream> #include<cstdio> #include<cmath> #inclu ...
- OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用
解决方案:oracle 版本太低,请装11G或以上版本..
- MT【1】终点在球面上的向量
解答: 评:最小值在Q为球心时取到,体现数学对称性的美!
- 自学Aruba1.3-WLAN厂家魔力象限
点击返回:自学Aruba之路 自学Aruba1.3-WLAN厂家魔力象限 以下为2017<有线和无线局域网接入基础设施的魔力象限>报告: Aruba.cisco为无线领域领导者. ...
- 自学Aruba4.2-Aruba AC基础配置(1)
点击返回:自学Aruba之路 自学Aruba4.2-Aruba AC基础配置(1) 管理员登陆(admin/saic_admin): Cli Web 管理帐号 控制器基础设置: 控制器恢复出厂设置 查 ...
- 自学Aruba6.2-控制器基本维护操作(web页面配置)
点击返回:自学Aruba之路 自学Aruba6.2-控制器基本维护操作(web页面配置) 1 显示当前控制器版本 Dashboard---Controller中 2 升级Aruab os版本 Main ...
- How to Add Trust Sites into IE before IE10 through Group Policy
Due to IE10 published, I'll conclude the methods that how to add trust sites in to IE of the version ...
- 牛客练习赛 小D的剑阵 解题报告
小D的剑阵 题意链接: https://ac.nowcoder.com/acm/contest/369/F 来源:牛客网 现在你有 \(n\) 把灵剑,其中选择第i把灵剑会得到的 \(w_i\) 攻击 ...
- 2018 ACM 网络选拔赛 焦作赛区
A. Magic Mirror #include <cstdio> #include <cstdlib> #include <cmath> #include < ...
- EClipse for PHP 中文乱码问题
UTF-8 格式的php,中文都是乱码. 如果此时在EClipse中输入中文会有 CP1252 错误( CP1252不支持xxxx ) 解决方法: windows->preferences-&g ...