$des$

一个无限长的 01 序列,初始全为 0,每次选择一个区间 [l,r] 进行操作,有三种操作:
1. l r 将 [l,r] 中所有元素变成 1。
2. l r 将 [l,r] 中所有元素变成 0。
3. l r 将 [l,r] 中所有元素异或上 1。
每次操作后询问最左边的 0 在哪个位置.

$sol$

线段树

将所有可能成为答案的点加入线段树的根节点维护

$code$

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cmath>
#include <cstring> using namespace std; #define LL long long
#define Rep(i, a, b) for(int i = a; i <= b; i ++)
#define gc getchar() inline LL read() {
LL x = ; char c = gc;
while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc;
return x;
} const int N = 1e5 + , M = N * * ; struct Node {
LL opt, l, r;
} Ask[N];
LL A[M], js;
int n; struct Node_ {
int Cnt[][M << ], Size[M << ], F[M << ]; #define lson jd << 1
#define rson jd << 1 | 1 void Build_tree(int l, int r, int jd) {
F[jd] = -;
Size[jd] = r - l + ;
Cnt[][jd] = Size[jd];
if(l == r) return ;
int mid = (l + r) >> ;
Build_tree(l, mid, lson), Build_tree(mid + , r, rson);
} void Push_down(int jd) {
int f = F[jd];
if(f == ) {
F[lson] = F[rson] = ;
Cnt[][lson] = Size[lson], Cnt[][rson] = Size[rson];
Cnt[][lson] = , Cnt[][rson] = ;
F[jd] = -;
} else if(f == ) {
F[lson] = F[rson] = ;
Cnt[][lson] = Size[lson], Cnt[][rson] = Size[rson];
Cnt[][lson] = , Cnt[][rson] = ;
F[jd] = -;
} else {
if(F[lson] == ) {
swap(Cnt[][lson], Cnt[][lson]);
F[lson] = -;
} else {
if(F[lson] == -) {
F[lson] = ;
swap(Cnt[][lson], Cnt[][lson]);
} else if(F[lson] == ) {
F[lson] = ;
Cnt[][lson] = Size[lson], Cnt[][lson] = ;
} else {
F[lson] = ;
Cnt[][lson] = Size[lson], Cnt[][lson] = ;
}
}
if(F[rson] == ) {
swap(Cnt[][rson], Cnt[][rson]);
F[rson] = -;
} else {
if(F[rson] == -) {
F[rson] = ;
swap(Cnt[][rson], Cnt[][rson]);
} else if(F[rson] == ) {
F[rson] = ;
Cnt[][rson] = Size[rson], Cnt[][rson] = ;
} else {
F[rson] = ;
Cnt[][rson] = Size[rson], Cnt[][rson] = ;
}
}
F[jd] = -;
}
} void Sec_G(int l, int r, int jd, int x, int y, int num){
if(x <= l && r <= y) {
Cnt[num][jd] = Size[jd];
Cnt[num ^ ][jd] = ;
F[jd] = num;
// cout << Cnt[1][jd] << " " << Cnt[0][jd] << "\n";
return ;
}
if(F[jd] != -) Push_down(jd);
int mid = (l + r) >> ;
// cout << Cnt[0][lson] << "\n";
if(x <= mid) Sec_G(l, mid, lson, x, y, num);
if(y > mid) Sec_G(mid + , r, rson, x, y, num);
Cnt[][jd] = Cnt[][lson] + Cnt[][rson];
Cnt[][jd] = Cnt[][lson] + Cnt[][rson];
} int Ask(int l, int r, int jd) {
if(l == r) {
return l;
}
if(F[jd] != -) Push_down(jd);
int mid = (l + r) >> ;
// cout << Cnt[0][lson] << "\n";
if(Cnt[][lson]) return Ask(l, mid, lson);
else return Ask(mid + , r, rson);
} void Seg_fz(int l, int r, int jd, int x, int y) {
if(x <= l && r <= y) {
if(F[jd] == -) {
swap(Cnt[][jd], Cnt[][jd]);
F[jd] = ;
return ;
} else if(F[jd] == ) {
F[jd] = ;
Cnt[][jd] = Size[jd];
Cnt[][jd] = ;
} else if(F[jd] == ) {
F[jd] = ;
Cnt[][jd] = ;
Cnt[][jd] = Size[jd];
} else {
F[jd] = -;
swap(Cnt[][jd], Cnt[][jd]);
}
return ;
}
if(F[jd] != -) Push_down(jd);
int mid = (l + r) >> ;
// cout << Cnt[0][lson] << "\n";
if(x <= mid) Seg_fz(l, mid, lson, x, y);
if(y > mid) Seg_fz(mid + , r, rson, x, y);
Cnt[][jd] = Cnt[][lson] + Cnt[][rson];
Cnt[][jd] = Cnt[][lson] + Cnt[][rson];
}
} Segtree; inline LL Getans() {
int w = Segtree.Ask(, js, );
// if(A[w - 1] + 1 != A[w]) return A[w - 1] + 1;
// else return A[w];
return A[w];
} int main() {
freopen("a.in", "r", stdin);
freopen("a.out", "w", stdout);
n = read();
Rep(i, , n) {
LL opt = read(), l = read(), r = read();
A[++ js] = l, A[++ js] = r; A[++ js] = max(1ll, l - ), A[++ js] = r + ;
Ask[i] = (Node) {
opt, l, r
};
}
A[++ js] = ;
sort(A + , A + js + );
js = unique(A + , A + js + ) - A - ;
Segtree.Build_tree(, js, );
// Rep(i, 1, 10) cout << Segtree.F[i] << " ";
// return 0;
Rep(i, , n) {
LL opt = Ask[i].opt, l = Ask[i].l, r = Ask[i].r;
int wl = lower_bound(A + , A + js + , l) - A;
int wr = lower_bound(A + , A + js + , r) - A;
if(opt == ) {
Segtree.Sec_G(, js, , wl, wr, );
cout << Getans() << "\n";
} else if(opt == ) {
Segtree.Sec_G(, js, , wl, wr, );
cout << Getans() << "\n";
} else {
Segtree.Seg_fz(, js, , wl, wr);
cout << Getans() << "\n";
}
} return ;
}

Problem 2 线段树的更多相关文章

  1. BZOJ_2298_[HAOI2011]problem a_线段树

    BZOJ_2298_[HAOI2011]problem a_线段树 Description 一次考试共有n个人参加,第i个人说:“有ai个人分数比我高,bi个人分数比我低.”问最少有几个人没有说真话( ...

  2. HDU 5475(2015 ICPC上海站网络赛)--- An easy problem(线段树点修改)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5475 Problem Description One day, a useless calculato ...

  3. codeforces 459D D. Pashmak and Parmida's problem(离散化+线段树或树状数组求逆序对)

    题目链接: D. Pashmak and Parmida's problem time limit per test 3 seconds memory limit per test 256 megab ...

  4. ACM学习历程—HDU5475 An easy problem(线段树)(2015上海网赛08题)

    Problem Description One day, a useless calculator was being built by Kuros. Let's assume that number ...

  5. 2014 Super Training #9 F A Simple Tree Problem --DFS+线段树

    原题: ZOJ 3686 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3686 这题本来是一个比较水的线段树,结果一个ma ...

  6. zoj 3686 A Simple Tree Problem (线段树)

    Solution: 根据树的遍历道的时间给树的节点编号,记录下进入节点和退出节点的时间.这个时间区间覆盖了这个节点的所有子树,可以当做连续的区间利用线段树进行操作. /* 线段树 */ #pragma ...

  7. [Codeforces Round #296 div2 D] Clique Problem 【线段树+DP】

    题目链接:CF - R296 - d2 - D 题目大意 一个特殊的图,一些数轴上的点,每个点有一个坐标 X,有一个权值 W,两点 (i, j) 之间有边当且仅当 |Xi - Xj| >= Wi ...

  8. HDU5107---K-short Problem (线段树区间 合并、第k大)

    题意:二维平面上 N 个高度为 Hi 建筑物,M次询问,每次询问输出 位于坐标(x ,y)左下角(也就是xi <= x && yi <= y)的建筑物中的第k高的建筑物的高 ...

  9. CodeForces903G Yet Another Maxflow Problem 扫描线 + 线段树 + 最小割

    给定两条链\(A, B\),其中\(A\)链某些点向\(B\)链有连边,支持修改\(A\)链中的某条边权以及查询\(A_1\)到\(B_n\)的最大流 显而易见,\(A\)和\(B\)链中一定满足左部 ...

  10. ZOJ 3686 A Simple Tree Problem(线段树)

    Description Given a rooted tree, each node has a boolean (0 or 1) labeled on it. Initially, all the ...

随机推荐

  1. SpringCloud之Zuul网关简介、映射vs过滤配置使用

    目的: Zuul路由网关简介及基本使用 Zuul路由映射配置 Zuul请求过滤配置 Zuul路由网关简介及基本使用 Zuul简介: Zuul是从设备和网站到Netflix流应用程序后端的所有请求的前门 ...

  2. spring boot + vue实现图片上传及展示

    转载:https://blog.csdn.net/weixin_40337982/article/details/84031778 其中一部分对我很有帮助 转载记录下 首先,html页面: <! ...

  3. Centos 6.10 安装 Jenkins

    前言 持续集成的概念 持续集成,Continuous integration ,简称CI. 持续集成正是针对这一类问题的一种软件开发实践.它倡导团队开发成员必须经常集成他们的工作,甚至每天都可能发生多 ...

  4. GRE

    第一个技术是GRE,全称Generic Routing Encapsulation,它是一种IP-over-IP的隧道技术.它将IP包封装在GRE包里,外面加上IP头,在隧道的一端封装数据包,并在通路 ...

  5. MVC比WebForm的优势,为什么使用MVC

    前言 如果你看了最近微软的议程,你会发现他们现在的焦点除了MVC,还是MVC.问题在于为什么微软如此热衷于丢弃传统的APS.NET Webform而转向ASP.NET MVC?本文就主要来讨论这个问题 ...

  6. win10 idea启动Tomcat后控制台中文乱码

    idea 配置文件新增如下配置 -Dfile.encoding=UTF-8 -Dconsole.encoding=UTF-8

  7. 【转载】C#中List集合使用Remove方法移除指定的对象

    在C#的List集合操作中,有时候需要将特定的对象或者元素移除出List集合序列中,此时可使用到List集合的Remove方法,Remove方法的方法签名为bool Remove(T item),it ...

  8. [LeetCode] 581. 最短无序连续子数组 ☆

    描述 给定一个整数数组,你需要寻找一个连续的子数组,如果对这个子数组进行升序排序,那么整个数组都会变为升序排序. 你找到的子数组应是最短的,请输出它的长度. 示例 1: 输入: [2, 6, 4, 8 ...

  9. 【MySql】Explain笔记

    Explain -- 使用 Explain + SQL 分析执行计划: id:表示此表的执行优先级 id相同,表的执行顺序依次从上往下:                id不同,并且递增,id值越大执 ...

  10. [ipsec][crypto] 有点不同的数字证书到底是什么

    前言 前言是在写完了全文之后回头补的.本意是想完全抽象的把证书的抽象逻辑意义表达出来,因为你能找到的大部分 资料都深陷在技术细节与行业规范里.只有其型没有其理,没有什么比理解一个事物的内在合理性更有乐 ...