FZU 1968 Twinkling lights III
Twinkling lights III
This problem will be judged on FZU. Original ID: 1968
64-bit integer IO format: %I64d Java class name: Main
Twinkling lights一直以来都很好玩的游戏。或许你还记得FZU1069 Twinkling lights 和FZU1420 Twinkling lights II。现在,Bluewind改变了一下游戏规则,游戏将变得更好玩。
N盏灯排成一行,编号1..N,起初的时候,所有的灯是开着的。Bluewind将执行M个操作,操作分成五种:
C x y,把编号从x到y的灯都关掉,原来关着的灯保持不变。
S x y,把编号从x到y的灯都开起来,原来开着的灯依旧开着。
A x y,让编号从x到y的灯都改变状态,即把原来开的灯关了,原来关了的灯开起来。
Q x y,查询编号从x到y中开着的灯的个数。
L x y,查询编号从x到y中最长连续开着的灯的个数。
Input
第一行两个整数N,M(1<=N,M<=500,000)表示有N盏灯,M个操作。
接下来M行,每行按指定格式给出一个操作,其中(1<=x<=y<=N)。
Output
对于每条Q查询操作和L查询操作,输出相应的结果。
Sample Input
10 5
C 2 8
S 5 7
A 1 10
Q 1 10
L 1 10
Sample Output
4
3
Source
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = ;
struct node {
int lt,rt,cover;
} tree[maxn<<];
int ret;
void build(int L,int R,int v) {
tree[v].lt = L;
tree[v].rt = R;
tree[v].cover = ;
if(L == R) return;
int mid = (L + R)>>;
build(L,mid,v<<);
build(mid+,R,v<<|);
}
inline void pushup(int v) {
if(tree[v<<].cover == tree[v<<|].cover)
tree[v].cover = tree[v<<].cover;
else tree[v].cover = -;
}
inline void pushdown(int v) {
if(tree[v].cover >= ) {
tree[v<<].cover = tree[v<<|].cover = tree[v].cover;
tree[v].cover = -;
}
}
void update(int lt,int rt,int val,bool sel,int v) {
if(sel && tree[v].cover == val) return;
if(lt <= tree[v].lt && rt >= tree[v].rt && (sel || !sel && tree[v].cover >= )) {
if(sel) tree[v].cover = val;
else tree[v].cover ^= ;
return;
}
pushdown(v);
if(lt <= tree[v<<].rt) update(lt,rt,val,sel,v<<);
if(rt >= tree[v<<|].lt) update(lt,rt,val,sel,v<<|);
pushup(v);
}
void query(int lt,int rt,int &ans,int &r,bool sel,int v) {
if(!tree[v].cover) return;
if(lt <= tree[v].lt && rt >= tree[v].rt && tree[v].cover > ) {
if(sel) ans += tree[v].rt - tree[v].lt + ;
else {
if(r + == tree[v].lt) ans += tree[v].rt - tree[v].lt + ;
else ans = tree[v].rt - tree[v].lt + ;
}
r = tree[v].rt;
ret = max(ans,ret);
return;
}
pushdown(v);
if(lt <= tree[v<<].rt) query(lt,rt,ans,r,sel,v<<);
if(rt >= tree[v<<|].lt) query(lt,rt,ans,r,sel,v<<|);
pushup(v);
}
int main() {
int n,m,x,y,ans,r;
char op[];
while(~scanf("%d %d",&n,&m)) {
build(,n,);
while(m--) {
scanf("%s%d%d",op,&x,&y);
switch(op[]) {
case 'C':
update(x,y,,true,);
break;
case 'S':
update(x,y,,true,);
break;
case 'A':
update(x,y,,false,);
break;
case 'Q':
ret = ans = r = ;
query(x,y,ans,r,true,);
printf("%d\n",ret);
break;
case 'L':
ret = ans = r = ;
query(x,y,ans,r,false,);
printf("%d\n",ret);
break;
}
}
}
return ;
}
FZU 1968 Twinkling lights III的更多相关文章
- HDOJ 4770 Lights Against Dudely
状压+暴力搜索 Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- FZU 2137 奇异字符串 后缀树组+RMQ
题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...
- FZU 1914 单调队列
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...
- ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】
FZU 2105 Digits Count Time Limit:10000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- 用Kotlin开发Android应用(III):扩展函数和默认值
这是关于Kotlin的第三篇. 原文标题:Kotlin for Android (III): Extension functions and default values 原文链接:http://an ...
- LeetCode Single Number I / II / III
[1]LeetCode 136 Single Number 题意:奇数个数,其中除了一个数只出现一次外,其他数都是成对出现,比如1,2,2,3,3...,求出该单个数. 解法:容易想到异或的性质,两个 ...
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- BZOJ 1968: [Ahoi2005]COMMON 约数研究
1968: [Ahoi2005]COMMON 约数研究 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 2032 Solved: 1537[Submit] ...
- 【Codeforces717F】Heroes of Making Magic III 线段树 + 找规律
F. Heroes of Making Magic III time limit per test:3 seconds memory limit per test:256 megabytes inpu ...
随机推荐
- Linux下查询CPU 缓存的工具
在Linux下能够使用例如以下工具查询CPU缓存: 方式1: $ lscpu L1d cache: 32K <span style="white-space:pre"> ...
- 捕捉到来自宇宙深空的神奇X-射线信号
请看下图: 这是专门用于捕捉X-射线信号的航天望远镜,约有5吨重,执行轨道距离地面大约有5万多公里.6月24日,美国宇航局NASA宣布,这台航天望远镜从银河系深处捕捉到一种波长非常特殊的神奇X-射线信 ...
- IIS Express加入MIME映射
近期在用Grid Report做Web报表的时候,碰到一件非常挠头的事. 本地用VS2010写的代码,调试的时候Web报表无法显示,用24.248server上VS2013相同仍是无法显示.最后把项目 ...
- Excel操作之VLOOKUP
https://support.office.com/en-us/article/VLOOKUP-function-0bbc8083-26fe-4963-8ab8-93a18ad188a1 Use V ...
- thinkphp5项目--个人博客(八)
thinkphp5项目--个人博客(八) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- [JSOI2008] [BZOJ1567] Blue Mary的战役地图 解题报告 (hash)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1567 Description Blue Mary最近迷上了玩Starcraft(星际争霸 ...
- 36.创建模板mylist
node.h #pragma once //创建模板 template <class T> class Node { public: T t;//数据 Node *pNext;//指针域 ...
- linux中的挂载是什么意思?通俗点讲
mount /dev/sda1 /mnt解释:mount 就是挂载命令,/dev/sda1是要挂载的磁盘分区,/mnt是要绑定的目录挂载后就能到目录/mnt去访问磁盘分区/dev/sda1里面的资料了 ...
- Adobe Photoshop CC 2015(PS CC 2015)看图不说话
- [转]60fps on the mobile web
Flipboard launched during the dawn of the smartphone and tablet as a mobile-first experience, allowi ...