HDU 4031 Attack(离线+线段树)(The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest)
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
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std; const int MAXN = ;
const int MAXT = MAXN << ;
const int MAXP = ; struct Node {
int pos, op, time;
Node() {}
Node(int pos, int op, int time): pos(pos), op(op), time(time) {}
bool operator < (const Node &rhs) const {
return pos < rhs.pos;
}
}; vector<int> qtime[MAXN], qid[MAXN];
Node attack[MAXN * ];
int ans[MAXN];
int T, n, q, t, ncnt, atime; void init() {
for(int i = ; i <= n; ++i) qtime[i].clear(), qid[i].clear();
memset(ans, -, q * sizeof(int));
ncnt = atime = ;
} #define ll (x << 1)
#define rr (ll | 1)
#define mid ((l + r) >> 1)
int atk[MAXT][MAXP], empty[MAXT][MAXP];
int cnt[MAXN]; void update(int x) {
for(int i = ; i < t; ++i) {
int t = empty[ll][i];
atk[x][i] = atk[ll][i] + atk[rr][t];
empty[x][i] = empty[rr][t];
}
} void build(int x, int l, int r) {
if(l == r) {
atk[x][] = empty[x][] = cnt[l] = ;
for(int i = ; i < t; ++i)
atk[x][i] = , empty[x][i] = i - ;
} else {
build(ll, l, mid);
build(rr, mid + , r);
update(x);
}
} void modify(int x, int l, int r, int a, int b) {
if(a <= l && r <= b) {
atk[x][] = ; empty[x][] = cnt[a] ? t - : ;
for(int i = ; i < t; ++i)
atk[x][i] = cnt[a], empty[x][i] = i - ;
} else {
if(a <= mid) modify(ll, l, mid, a, b);
if(mid < b) modify(rr, mid + , r, a, b);
update(x);
}
} void modify(int pos) {
modify(, , atime, pos, pos);
} int query(int x, int l, int r, int a, int b, int e) {
if(a <= l && r <= b) {
return atk[x][e];
} else {
int res = query(ll, l, mid, a, b, e);
if(mid < b) res += query(rr, mid + , r, a, b, empty[ll][e]);
return res;
}
} int query(int pos) {
if(pos == ) return ;
return query(, , atime, , pos, );
} char s[]; int main() {
scanf("%d", &T);
for(int kase = ; kase <= T; ++kase) {
scanf("%d%d%d", &n, &q, &t);
init();
for(int i = , a, b; i < q; ++i) {
scanf("%s", s);
if(strcmp(s, "Attack") == ) {
scanf("%d%d", &a, &b);
atime++;
attack[ncnt++] = Node(a, , atime);
attack[ncnt++] = Node(b + , -, atime);
} else {
scanf("%d", &a);
qtime[a].push_back(atime);
qid[a].push_back(i);
}
}
sort(attack, attack + ncnt); build(, , atime);
int p = ;
for(int i = ; i <= n; ++i) {
while(p < ncnt && attack[p].pos == i) {
cnt[attack[p].time] += attack[p].op;
modify(attack[p++].time);
}
for(size_t k = ; k < qtime[i].size(); ++k)
ans[qid[i][k]] = query(qtime[i][k]);
} printf("Case %d:\n", kase);
for(int i = ; i < q; ++i)
if(ans[i] != -) printf("%d\n", ans[i]);
}
}
HDU 4031 Attack(离线+线段树)(The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest)的更多相关文章
- HDU 4069 Squiggly Sudoku(DLX)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4069 Problem Description Today we play a squiggly sud ...
- HDU 4064 Carcassonne(插头DP)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4064 Problem Description Carcassonne is a tile-based ...
- HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4063 Description You are playing a flying game. In th ...
- hdu 5877 线段树(2016 ACM/ICPC Asia Regional Dalian Online)
Weak Pair Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online)
HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online) 题目链接http://acm.hdu.edu.cn/showp ...
- HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)
Football Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)
Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Sub ...
- HDU 4031 Attack (线段树)
成功袭击次数=所有袭击次数-成功防守次数 需要一个辅助pre来记录上一次袭击成功什么时候,对于每个查询,从上一次袭击成功开始,每隔t更新一次. 感觉这样做最坏时间复杂度是O(n^2),这里 说是O(q ...
- HDU 4729 An Easy Problem for Elfness(主席树)(2013 ACM/ICPC Asia Regional Chengdu Online)
Problem Description Pfctgeorge is totally a tall rich and handsome guy. He plans to build a huge wat ...
随机推荐
- MessageQueue 一 简单的创建和读取
创建一个队列,并写入数据 在读取出来 using System; using System.Collections.Generic; using System.Linq; using System.M ...
- Silverlight页面通过继承扩展实现
在Silverlight中有些项目对UserControl重新做了封装基类,如PageBase,要求项目中每个页面都要从PageBase派生,但是过程比较坎坷,本文针对这个功能点的实现以及实现过程中遇 ...
- android 直接启动其他应用的Service
最近在做一个小插件,没有图标没有activity,利用其他APK启动它的service. 直奔主题,插件A,安装插件的应用B. B安装A后,由于A刚被安装,没有注册广播接收器,这里不考虑AIDL.需求 ...
- DPM总结
DPM:Deformable Parts Model(来自http://www.cs.berkeley.edu/~rbg/latent/index.html) 目标检测算法 先计算梯度方向直方图,在用 ...
- ArcGIS API for Silverlight 调用GP服务加载等值线图层
原文:ArcGIS API for Silverlight 调用GP服务加载等值线图层 第二篇.Silverlight客户端调用GP服务 利用ArcGIS API for Silverlight实现G ...
- boost.compressed_pair源码剖析
意义 当compressed_pair的某一个模板参数为一个空类的时候将对其进行“空基类优化”,这样可以使得compressed_pair占用的空间比std::pair的更小. 参考如下代码: #in ...
- tag标签调取
{dede:tag row='10' sort='new' getall='1'} <li> <a href='[fie ...
- CentOS6.7搭建蜜罐dionaea
yum -y install epel-release wget tar git autoconf* libtool-* mkdir /opt/dionaea 1.安装liblcfg软件.git cl ...
- rpyc 回调模式工作不正常
rpyc 回调模式工作不正常 最近使用了 rpyc 来处理一个多节点间的文件同步的任务,目标是使用 rpyc 来实现简单的 p2p 文件传输机制,以减少单点负载和单点失败对传输的影响. 和 p2p 的 ...
- 11月23日《奥威Power-BI报表集成到其他系统》腾讯课堂开课啦
听说明天全国各地区都要冷到爆了,要是天气冷到可以放假就好了.想象一下大冷天的一定要在被窝里度过才对嘛,索性明天晚上来个相约吧,相约在被窝里看奥威Power-BI公开课如何? 上周奥威公开 ...