2015 UESTC 数据结构专题D题 秋实大哥与战争 变化版本的线段树,合并区间,单点查询
D - 秋实大哥与战争
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://acm.uestc.edu.cn/#/contest/show/59
Description
男儿何不带吴钩,收取关山五十州。
征战天下是秋实大哥一生的梦想,所以今天他又在练习一个对战游戏。
秋实大哥命令所有士兵从左到右排成了一行来抵挡敌人的攻击。
敌方每一次会攻击一个士兵,这个士兵就会阵亡,整个阵列就会从这个位置断开;同时有的时候已阵亡的士兵会受人赢气息感染而复活。
秋实大哥想知道某一时刻某一个士兵所在的阵列的长度是多少。
Input
接下来m行,每一行是以下三种事件之一:
0 x : 表示x位置的士兵受到攻击阵亡
1 x : 表示x位置的士兵受人赢气息感染复活
2 x : 秋实大哥想知道第x个士兵所在阵列的长度
1≤n,m≤100000,1≤x≤n。
Output
Sample Input
2 2
0 3
2 2
Sample Output
2
HINT
题意
题解:
set或者线段树都行,线段树记录从左边延展的长度,记录从右边延展的长度,和区间最大长度
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 150001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/* int buf[10];
inline void write(int i) {
int p = 0;if(i == 0) p++;
else while(i) {buf[p++] = i % 10;i /= 10;}
for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
printf("\n");
}
*/
//**************************************************************************************
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} struct node
{
int l,r;
int len;
int lm,rm,mm;
};
node a[maxn*]; void build(int l,int r,int x)
{
a[x].l=l,a[x].r=r;
a[x].lm=a[x].rm=a[x].len=a[x].mm=r-l+;
if(l!=r)
{
int mid=(l+r)>>;
build(l,mid,x<<);
build(mid+,r,x<<|);
}
}
void updata(int i,int t,int x)
{
if(a[i].l == a[i].r)
{
a[i].lm = a[i].rm = a[i].mm = x;
return ;
}
int mid = (a[i].l+a[i].r)>>;
if(t<=mid)
updata(*i,t,x);
else
updata(*i+,t,x);
a[i].lm = a[*i].lm;
a[i].rm = a[*i+].rm;
a[i].mm = max(max(a[*i].mm,a[*i+].mm),a[*i].rm+a[*i+].lm);
if(a[*i].lm == a[*i].r-a[*i].l+)
a[i].lm += a[*i+].lm;
if(a[*i+].rm == a[*i+].r-a[*i+].l+)
a[i].rm += a[*i].rm;
}
int query(int x,int p)
{
if(a[x].l==a[x].r||a[x].mm==||a[x].mm==a[x].len)
return a[x].mm;
int mid=(a[x].l+a[x].r)>>;
if(p<=mid)
{
if(p>=a[x<<].r-a[x<<].rm+)
return query(x<<,p)+query(x<<|,mid+);
else
return query(x<<,p);
}
else
{
if(p<=a[x<<|].l+a[x<<|].lm-)
return query(x<<|,p)+query(x<<,mid);
else
return query(x<<|,p);
}
} int main()
{
int n,m,x,y;
n=read(),m=read();
build(,n,);
for(int i=;i<m;i++)
{
x=read(),y=read();
if(x==)
updata(,y,);
if(x==)
updata(,y,);
if(x==)
printf("%d\n",query(,y));
}
}
2015 UESTC 数据结构专题D题 秋实大哥与战争 变化版本的线段树,合并区间,单点查询的更多相关文章
- 2015 UESTC 数据结构专题D题 秋实大哥与战争 SET的妙用
D - 秋实大哥与战争 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 D ...
- 2015 UESTC 数据结构专题N题 秋实大哥搞算数 表达式求值/栈
秋实大哥搞算数 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1074 Des ...
- 2015 UESTC 数据结构专题B题 秋实大哥与花 线段树 区间加,区间查询和
B - 秋实大哥与花 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...
- 2015 UESTC 数据结构专题H题 秋实大哥打游戏 带权并查集
秋实大哥打游戏 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Descr ...
- 2015 UESTC 数据结构专题G题 秋实大哥去打工 单调栈
秋实大哥去打工 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Descr ...
- 2015 UESTC 数据结构专题E题 秋实大哥与家 线段树扫描线求矩形面积交
E - 秋实大哥与家 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...
- 2015 UESTC 数据结构专题C题 秋实大哥与快餐店 字典树
C - 秋实大哥与快餐店 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 ...
- 2015 UESTC 数据结构专题A题 秋实大哥与小朋友 线段树 区间更新,单点查询,离散化
秋实大哥与小朋友 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Desc ...
- 2015 UESTC 搜索专题K题 秋实大哥の恋爱物语 kmp
秋实大哥の恋爱物语 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 De ...
随机推荐
- Thinkphp的自定义路由(route.php)
废话:因为thinkphp的默认路由会导致URL特别长,从而会影响搜索引擎优化.所以就衍生了自定义路由,尽量将URL缩短. 这是默认的路由文件: <?php return [ '__patter ...
- phinx:php数据库迁移
Phinx使你的php app进行数据迁移的过程变得异常轻松,在五分钟之内你就可以安装好Phinx 并进行数据迁移. 特性 使用php代码进行数据迁移 部署模式下迁移 五分钟之内使用 不再担心数据库的 ...
- rabbitmq集群搭建方法简介(测试机linux centos)【转】
本文将介绍四台机器搭建rabbitmq集群: rabbitmq IP和主机名(每台机器已安装RabbitMQ 3.5.6, Erlang 18.1) 192.168.87.73 localhost73 ...
- 杂乱的code
/*o(n)的堆化方法*/ void myjust(vector<int>& A,int i){ int l=i*2+1; int r=i*2+2; int minn=i; if( ...
- Suse Linux下NTP缓慢调整配置,转载至http://www.gpstime.com.cn/
(1)系统内若有使用crontab 进行与时间调整相关的例行性工作排程,应注释掉(命令人工crontab -e修改,删除定时同步任务ntpdate -s ntpserver). (2)修改ntp配置文 ...
- Learning a Deep Compact Image Representation for Visual Tracking
这篇博客对论文进行了部分翻译http://blog.csdn.net/vintage_1/article/details/19546953,不过个人觉得博主有些理解有误. 这篇博客简单分析了代码htt ...
- android 代码设置、打开wifi热点及热点的连接(转)
用过快牙的朋友应该知道它们在两天设备之间传输文件的时候使用的是wifi热点,然后另一台便连接这个热点再进行传输.快牙传输速度惊人应该跟它的这种机制有关系吧.不知道它的搜索机制是怎样的,但我想应该可 ...
- IEEEXtreme 10.0 - Mysterious Maze
这是 meelo 原创的 IEEEXtreme极限编程大赛题解 Xtreme 10.0 - Mysterious Maze 题目来源 第10届IEEE极限编程大赛 https://www.hacker ...
- day1 python简介和入门
Linux的yum依赖自带Python,为防止错误,此处更新其实就是再安装一个Python: 安装Python 1.下载安装包 https://www.python.org/downloads ...
- mongodb卸载再重装
标题就凸显了尴尬,是的,本地(ubuntu16.04)自带的mongodb太老了,想要装最新版的 卸载: sudo dpkg -P mongodb 然后下载新版的mongodb: https://m ...