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, ...
随机推荐
- 【刷题】LOJ 6002 「网络流 24 题」最小路径覆盖
题目描述 给定有向图 \(G = (V, E)\) .设 \(P\) 是 \(G\) 的一个简单路(顶点不相交)的集合.如果 \(V\) 中每个顶点恰好在 \(P\) 的一条路上,则称 \(P\) 是 ...
- spring hibernate实现动态替换表名(分表)
1.概述 其实最简单的办法就是使用原生sql,如 session.createSQLQuery("sql"),或者使用jdbcTemplate.但是项目中已经使用了hql的方式查询 ...
- bzoj3920: Yuuna的礼物(莫队+分块套分块)
思路挺简单的,但是总感觉好难写...码力还是差劲,最后写出来也挺丑的 这题显然是个莫队题,考虑怎么转移和询问... 根据莫队修改多查询少的特点,一般用修改快查询慢的分块来维护.查第$k_1$小的出现次 ...
- springboot配置文件的配置
转:https://www.cnblogs.com/zheting/p/6707036.html Spring Boot使用了一个全局的配置文件application.properties,放在src ...
- Nginx配置——区分PC或手机访问不同域名以及http跳转https
新官网上线,但在手机上访问新官网的体验很差,要求在手机上访问新官网时访问旧官网,可以通过修改Nginx配置来实现自动跳转.首先是新官网的Nginx配置文件加个跳转判断,通过user-agent判断来源 ...
- 「Vue」nrm
nrm使用只是单纯的提供了几个常用的下载包的URL地址,并能让我们在这几个地址之间很方便的切换,但是我们每次装包的时候,使用的装包工具都是npmnpm i nrm -g 安装nrmnrm ls 查看镜 ...
- A*算法–A* algorithm tutorial
Author:Justin Heyes-Jones From: http://heyes-jones.com/astar.php Date:2014.8.16 本文地址:http://www.cnbl ...
- SpringBoot Logback日志配置
Logback的配置介绍: 1.Logger.appender及layout Logger作为日志的记录器,把它关联到应用的对应的context上后,主要用于存放日志对象,也可以定义日志类型.级别. ...
- SQL语句(六)成批导入导出数据
(六) 成批导入导出数据 假设已经存在teaching数据库, 存在一张Student表,如图: 右键teaching->任务->导入数据 下一步->数据源(Microsoft Ex ...
- BFS搜索算法应用_Codevs 1004 四子连棋
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <algorithm> #include <cs ...