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 线段树的更多相关文章

  1. 数据结构(线段树):CodeForces 145E Lucky Queries

    E. Lucky Queries time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  2. Codeforces 1117G Recursive Queries [线段树]

    Codeforces 洛谷:咕咕咕 思路 设\(L_i,R_i\)为\(i\)左右第一个大于它的位置. 对于每一个询问\(l,r\),考虑区间每一个位置的贡献就是\(\min(r,R_i-1)-\ma ...

  3. Buses and People CodeForces 160E 三维偏序+线段树

    Buses and People CodeForces 160E 三维偏序+线段树 题意 给定 N 个三元组 (a,b,c),现有 M 个询问,每个询问给定一个三元组 (a',b',c'),求满足 a ...

  4. CodeForces 877E DFS序+线段树

    CodeForces 877E DFS序+线段树 题意 就是树上有n个点,然后每个点都有一盏灯,给出初始的状态,1表示亮,0表示不亮,然后有两种操作,第一种是get x,表示你需要输出x的子树和x本身 ...

  5. [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路)

    [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路) 题面 有n个空心物品,每个物品有外部体积\(out_i\)和内部体积\(in_i\),如果\(in_i& ...

  6. [Codeforces 1199D]Welfare State(线段树)

    [Codeforces 1199D]Welfare State(线段树) 题面 给出一个长度为n的序列,有q次操作,操作有2种 1.单点修改,把\(a_x\)修改成y 2.区间修改,把序列中值< ...

  7. [Codeforces 316E3]Summer Homework(线段树+斐波那契数列)

    [Codeforces 316E3]Summer Homework(线段树+斐波那契数列) 顺便安利一下这个博客,给了我很大启发(https://gaisaiyuno.github.io/) 题面 有 ...

  8. 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 ...

  9. [CodeForces - 678F] Lena and Queries 线段树维护凸包

    大致题意: 给出三种操作 1.往平面点集中添加一个点 2.删除第i次添加的点 3.给出一个q,询问平面点集中的q*x+y的最大值 首先对于每个询问,可将z=q*x+y转化为y=z-q*x,即过点(x, ...

随机推荐

  1. MT【180】齐次化+换元

    已知实数$a,b$满足$a^2-ab-2b^2=1,$则$a^2+b^2$的取值范围_____ 解答:$\textbf{方法一}$由已知得$(a-2b)(a+b)=1$,设$x=a-2b,y=a+b$ ...

  2. 【枚举Day1】20170529-2枚举算法专题练习 题解

    题目: http://www.cnblogs.com/ljc20020730/p/6918328.html 评测器:cena 评测记录: 1.OneMoreRectangle 一个矩形 ●如果任意枚举 ...

  3. 洛谷 P2862 [USACO06JAN]把牛Corral the Cows 解题报告

    P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...

  4. 【bzoj2669】 cqoi2012—局部极小值

    http://www.lydsy.com/JudgeOnline/problem.php?id=2669 (题目链接) 题意 给出一个$n*m$的整数矩阵,其中$[1,nm]$中的整数每个出现一次,有 ...

  5. coin

    Decsription 数据范围:\(n<=3000,m<=300\),保证\(\forall i,\sum\limits_{j}p_{ij}=1000\) Solution 日常期望算不 ...

  6. Python之旅:并发编程之协程

    一 引子 本节的主题是基于单线程来实现并发,即只用一个主线程(很明显可利用的cpu只有一个)情况下实现并发,为此我们需要先回顾下并发的本质:切换+保存状态 cpu正在运行一个任务,会在两种情况下切走去 ...

  7. NO.4: 确定对象被使用前已被初始化

    1.为内置对象进行 "手工初始化",因为C++不保证初始化他们(内置类型在赋值与初始化销毁基本相同,最好还是进行初始化列表),在内置类型过多情况下,可选择private函数统一初始 ...

  8. python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件

    python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 python操作txt文件中 ...

  9. 何凯文每日一句打卡||DAY7

  10. python AjaxSpider 代码演示

    import re # 引入正则表达式 import json # 引入 json import pymongo # 引入mongo数据库 import requests # 引入HTTP请求协议 f ...