hdu 4031 attack 线段树区间更新
Attack
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 2496 Accepted Submission(s): 788
During the war, it is very important to understand the situation of both self and the enemy. So the commanders of American want to know how much time some part of the wall is successfully attacked. Successfully attacked means that the attack is not defended by the shield.
The first line of each test case is three integers, N, Q, t, the length of the wall, the number of attacks and queries, and the time each shield needs to cool down.
The next Q lines each describe one attack or one query. It may be one of the following formats
1. Attack si ti
Al Qaeda attack the wall from si to ti, inclusive. 1 ≤ si ≤ ti ≤ N
2. Query p
How many times the pth unit have been successfully attacked. 1 ≤ p ≤ N
The kth attack happened at the kth second. Queries don’t take time.
1 ≤ N, Q ≤ 20000
1 ≤ t ≤ 50
0
1
0
1
3
2
/*
hdu 4031 attack 线段树区间更新 problem:
每个位置有一个防御塔,每次敌人会对一个区间进行攻击。防御塔有一个冷却时间t。
问某个时间时,某个位置被成功攻击的次数(没有被防御) solve:
主要是怎么处理这个冷却值的问题,区间攻击都可以使用 线段树区间更新来解决。
最开始考虑的是通过 更新来维护每个点,那每次就要更新[1,n],感觉应该会超时吧
然后想到是 通过每次-1来体现时间的变化,但是无法知道每个点攻击成功的情况 所以直接暴力搞了- -
通过线段树记录被攻击了多少次,然后通过记录可以知道防御成功了多少次
于是就能得出答案。 hhh-2016-08-05 21:16:55
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <vector>
#include <set>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define lson (i<<1)
#define rson ((i<<1)|1)
using namespace std;
typedef long long ll;
const int maxn=100000 + 10;
const int INF=0x3f3f3f3f;
const int mod = 1e9+7;
int n; struct node
{
int l,r;
int val;
int len ;
int mid()
{
return (l+r)>> 1;
}
} tree[maxn<<2]; void push_up(int i)
{
} void build(int i,int l,int r)
{
tree[i].l = l;
tree[i].r = r;
tree[i].val = tree[i].len = 0;
if(l == r)
{
return ;
}
int mid = tree[i].mid();
build(lson,l,mid);
build(rson,mid+1,r);
push_up(i);
} void push_down(int i)
{
if(tree[i].val)
{
tree[lson].val += tree[i].val;
tree[rson].val += tree[i].val;
tree[i].val = 0;
}
} void Insert(int i,int l,int r,int val)
{
if(tree[i].l >= l && tree[i].r <= r)
{
tree[i].val += val;
push_up(i);
return ;
}
push_down(i);
int mid = tree[i].mid();
if(l <= mid)
Insert(lson,l,r,val);
if(r > mid)
Insert(rson,l,r,val);
push_up(i);
} int query(int i,int k)
{
if(tree[i].l == tree[i].r && tree[i].l == k)
{
return tree[i].val;
}
push_down(i);
int mid = tree[i].mid();
if(k <= mid)
return query(lson,k);
else
return query(rson,k);
}
struct Point
{
int l,r;
Point()
{ }
Point(int a,int b)
{
l = a,r = b;
}
};
Point pt[maxn];
char op[5]; int main()
{
int T,n,m,k;
int cas = 1;
int a,b;
//freopen("in.txt","r",stdin);
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
int cnt = 0;
build(1,1,n);
printf("Case %d:\n",cas++);
for(int i = 1;i <= m;i++)
{
scanf("%s",op);
if(op[0] == 'Q')
{
int num = 0;
scanf("%d",&a);
for(int i = 0;i < cnt;)
{
if( a>= pt[i].l && a <= pt[i].r)
{
num++;
i += k;
}
else
{
i++;
}
}
printf("%d\n",query(1,a) - num);
}
else
{
scanf("%d%d",&a,&b);
Insert(1,a,b,1);
pt[cnt++] = Point(a,b);
}
}
}
return 0;
}
hdu 4031 attack 线段树区间更新的更多相关文章
- hdu 4031 Attack 线段树
题目链接 Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total ...
- HDU 5861 Road 线段树区间更新单点查询
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...
- HDU 3308 LCIS 线段树区间更新
最近开始线段树一段时间了,也发现了不少大牛的博客比如HH大牛 ,小媛姐.这个题目是我在看HH大牛的线段树专题是给出的习题,(可以去他博客找找,真心推荐)原本例题是POJ3667 Hotel 这个题目 ...
- hdu 1698(线段树区间更新)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 1556【线段树区间更新】
这篇lazy讲的很棒: https://www.douban.com/note/273509745/ if(tree[rt].l == l && r == tree[rt].r) 这里 ...
- HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...
- HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...
- hdu 3966(树链剖分+线段树区间更新)
传送门:Problem 3966 https://www.cnblogs.com/violet-acmer/p/9711441.html 学习资料: [1]线段树区间更新:https://blog.c ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
随机推荐
- 第201621123043 《Java程序设计》第14周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结与数据库相关内容. 2. 使用数据库技术改造你的系统 2.1 简述如何使用数据库技术改造你的系统.要建立什么表?截图你的表设计. 2 ...
- Python strip()方法
描述 Python strip() 方法用于移除字符串头尾指定的字符(默认为空格). 语法 strip()方法语法: str.strip([chars]); 参数 chars -- 移除字符串头尾指定 ...
- NodeJs实现自定义分享功能,获取微信授权+用户信息
最近公司搞了个转盘抽奖的运营活动,入口放在了微信公众号里,好久没碰过微信了,刚拾起来瞬间感觉有点懵逼....似乎把之前的坑又都重新踩了一遍,虽然过程曲折,不过好在顺利完成了,而且印象也更加深刻了,抽时 ...
- SpringBoot的重要特性
一.Web特性 Spring Boot 提供了spring-boot-starter-web来为Web开发予以支持,spring-boot-starter-web为我们提供了嵌入的Tomcat以及Sp ...
- OpendID是什么?
一.OpenID的概念 1.问题的提出 2.OpenID是什么? 3.规范演进 二.OpenID 的运行原理 1.参与者 2.运行原理 3.典型场景 4.开源实现 5.优点&缺点 优点: ...
- linux下的Shell编程(3)shell里的流程控制
if 语句 if 表达式如果条件命令组为真,则执行 then 后的部分.标准形式: if 判断命令,可以有很多个,真假取最后的返回值 then 如果前述为真做什么 [ # 方括号代表可选,别真打进去了 ...
- zuul入门(1)zuul 的概念和原理
一.zuul是什么 zuul 是netflix开源的一个API Gateway 服务器, 本质上是一个web servlet应用. Zuul 在云平台上提供动态路由,监控,弹性,安全等边缘服务的框架. ...
- 基于python的统计公报关键数据爬取
# -*- coding: utf-8 -*- """ Created on Wed Nov 8 14:23:14 2017 @author: 123 "&qu ...
- bootstrap时间区间设置方法
我们在开发过程中经常有时间区间的要求,在多次"失败"及翻阅资料之后终于找到了适合我的方法,所以给大家分享出来. 基本需求为可以设置时间,设置时间区间,后一时间日期不可提前于前一时间 ...
- Python基础数据类型之int、bool、str
数据类型:int bool str list 元祖 dict 集合 int:整数型,用于各种数学运算. bool:只有两种,True和False,用户判断. str:存储少量数据,进行操作 ...