Codeforces 145E Lucky Queries 线段树
感觉是很简单的区间合并, 但是好像我写的比较麻烦。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = 1e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1 struct info {
int up[][];
int dn[][];
} a[N << ]; info operator + (const info& a, const info& b) {
info ans;
ans.up[][] = a.up[][] + b.up[][];
ans.up[][] = max(a.up[][] + max(b.up[][], b.up[][]), a.up[][] + b.up[][]);
ans.up[][] = a.up[][] + b.up[][];
ans.dn[][] = a.dn[][] + b.dn[][];
ans.dn[][] = max(a.dn[][] + max(b.dn[][], b.dn[][]), a.dn[][] + b.dn[][]);
ans.dn[][] = a.dn[][] + b.dn[][];
return ans;
} int lazy[N << ]; void change(int rt) {
swap(a[rt].up[][], a[rt].dn[][]);
swap(a[rt].up[][], a[rt].dn[][]);
swap(a[rt].up[][], a[rt].dn[][]);
} void push(int rt) {
if(lazy[rt]) {
change(rt << ); change(rt << | );
lazy[rt << ] ^= ;
lazy[rt << | ] ^= ;
lazy[rt] = ;
}
} void build(int l, int r, int rt) {
if(l == r) {
int x; scanf("%1d", &x);
if(x == ) {
a[rt].up[][] = ;
a[rt].up[][] = ;
a[rt].up[][] = ;
a[rt].dn[][] = ;
a[rt].dn[][] = ;
a[rt].dn[][] = ;
}
else {
a[rt].up[][] = ;
a[rt].up[][] = ;
a[rt].up[][] = ;
a[rt].dn[][] = ;
a[rt].dn[][] = ;
a[rt].dn[][] = ;
}
return;
}
int mid = l + r >> ;
build(lson); build(rson);
a[rt] = a[rt << ] + a[rt << | ];
} void update(int L, int R, int l, int r, int rt) {
if(l >= L && r <= R) {
lazy[rt] ^= ;
change(rt);
return;
}
int mid = l + r >> ;
push(rt);
if(L <= mid) update(L, R, lson);
if(R > mid) update(L, R, rson);
a[rt] = a[rt << ] + a[rt << | ];
} int n, m;
char s[]; int main() {
scanf("%d%d", &n, &m);
build(, n, );
while(m--) {
scanf("%s", s);
if(s[] == 'c') {
printf("%d\n", max(a[].up[][], max(a[].up[][], a[].up[][])));
} else {
int L, R;
scanf("%d%d", &L, &R);
update(L, R, , n, );
}
}
return ;
} /*
*/
Codeforces 145E Lucky Queries 线段树的更多相关文章
- 数据结构(线段树):CodeForces 145E Lucky Queries
E. Lucky Queries time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces 1117G Recursive Queries [线段树]
Codeforces 洛谷:咕咕咕 思路 设\(L_i,R_i\)为\(i\)左右第一个大于它的位置. 对于每一个询问\(l,r\),考虑区间每一个位置的贡献就是\(\min(r,R_i-1)-\ma ...
- Buses and People CodeForces 160E 三维偏序+线段树
Buses and People CodeForces 160E 三维偏序+线段树 题意 给定 N 个三元组 (a,b,c),现有 M 个询问,每个询问给定一个三元组 (a',b',c'),求满足 a ...
- CodeForces 877E DFS序+线段树
CodeForces 877E DFS序+线段树 题意 就是树上有n个点,然后每个点都有一盏灯,给出初始的状态,1表示亮,0表示不亮,然后有两种操作,第一种是get x,表示你需要输出x的子树和x本身 ...
- [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路)
[Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路) 题面 有n个空心物品,每个物品有外部体积\(out_i\)和内部体积\(in_i\),如果\(in_i& ...
- [Codeforces 1199D]Welfare State(线段树)
[Codeforces 1199D]Welfare State(线段树) 题面 给出一个长度为n的序列,有q次操作,操作有2种 1.单点修改,把\(a_x\)修改成y 2.区间修改,把序列中值< ...
- [Codeforces 316E3]Summer Homework(线段树+斐波那契数列)
[Codeforces 316E3]Summer Homework(线段树+斐波那契数列) 顺便安利一下这个博客,给了我很大启发(https://gaisaiyuno.github.io/) 题面 有 ...
- Codeforces Round #590 (Div. 3) D. Distinct Characters Queries(线段树, 位运算)
链接: https://codeforces.com/contest/1234/problem/D 题意: You are given a string s consisting of lowerca ...
- [CodeForces - 678F] Lena and Queries 线段树维护凸包
大致题意: 给出三种操作 1.往平面点集中添加一个点 2.删除第i次添加的点 3.给出一个q,询问平面点集中的q*x+y的最大值 首先对于每个询问,可将z=q*x+y转化为y=z-q*x,即过点(x, ...
随机推荐
- 【BZOJ5281】Talent Show(分数规划)
[BZOJ5281]Talent Show(分数规划) 题面 BZOJ 洛谷 题解 二分答案直接就是裸的分数规划,直接跑背包判断是否可行即可. #include<iostream> #in ...
- 【转】Example of using the --info linker option
5.3 Example of using the --info linker option This is an example of the output generated by the --in ...
- docker 原理
docker项目的目标是实现轻量级的操作系统虚拟化,Docker的基础是Linux容器(LXC)等技术. 在LXC的基础上,Docker做了进一步的封装,让用户不关心容器的管理,使得操作更为简单.用户 ...
- 在线Python学习网站
目前我们使用的Python集成环境是Anaconda3,然后使用Jupyter Notebook和Spyder两个开发环境 Goole推出了在线的开发环境,在线网站: https://colab.re ...
- vim文本删除方法 Linux
1,先打开某个文件: vim filename 2,转到文件结尾 在命令模式输入 G 3,转到10行 在命令模式输入 10G 4,删除所有内容:先用G 转到文件尾,然后使用下面命令: :1, .d ...
- Spark记录-官网学习配置篇(二)
### Spark SQL Running the SET -v command will show the entire list of the SQL configuration. #scala/ ...
- bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹
http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...
- Zephir入门教程一
一.如何安装 zephir-安装和初体验:http://blog.csdn.net/u011142688/article/details/51619811 二.如何使用 需要切到工作目录下,也就是co ...
- python学习笔记7-excel操作
一.操作excel import xlwt book = xlwt.Workbook() #新建一个excel sheet = book.add_sheet('sheet1') #添加一个sheet页 ...
- [iOS]图片高清度太高, 导致内存过大Crash
先说一下状况, 后台提供的图片太高清了, 每个图片都在2-4MB, iOS上每个页面需要同时下载并展示10-15张. 这个时候, 如果我多滑动collectionView几次, 直接App就崩溃了(r ...