\(\text{Solution}\)

\(\text{code}\)

#include <cstdio>
#include <iostream>
#include <set>
#define IN inline
#define RE register
using namespace std;
typedef long long LL; const int N = 1e6 + 5;
int n, q;
LL tag[N]; struct BIT{
LL c[N];
IN int lowbit(int x){return x & (-x);}
IN void add(int x, LL v){for(; x <= n; x += lowbit(x)) c[x] += v;}
IN LL Query(int x){LL s = 0; for(; x; x -= lowbit(x)) s += c[x]; return s;}
}T; struct node{
int l, r; mutable int v;
IN node(int l, int r, int v):l(l), r(r), v(v){};
IN bool operator < (const node &a) const {return l < a.l;}
};
set<node> odt;
typedef set<node>::iterator IT; IN IT split(int x)
{
if (x > n) return odt.end();
IT it = --odt.upper_bound(node{x, 0, 0});
if (it->l == x) return it;
int l = it->l, r = it->r, v = it->v;
odt.erase(it), odt.insert(node{l, x - 1, v});
return odt.insert(node{x, r, v}).first;
}
IN void assign(int l, int r, int c)
{
IT itr = split(r + 1), itl = split(l);
for(RE IT it = itl; it != itr; it++)
T.add(it->l, tag[it->v]), T.add(it->r + 1, -tag[it->v]);
odt.erase(itl, itr), odt.insert(node{l, r, c});
T.add(l, -tag[c]), T.add(r + 1, tag[c]);
}
IN int find(int x)
{
IT it = odt.lower_bound(node{x, 0, 0});
if (it->l == x) return it->v;
return (--it)->v;
} IN void read(int &x)
{
x = 0; int f = 1; char ch = getchar();
for(; !isdigit(ch); f = (ch == '-' ? -1 : 1), ch = getchar());
for(; isdigit(ch); x = (x<<3)+(x<<1)+(ch^48), ch = getchar());
x *= f;
} int main()
{
read(n), read(q), odt.insert(node{1, n, 1});
char op[10];
for(RE int l, r, c, x; q; --q)
{
scanf("%s", op);
if (op[0] == 'C') read(l), read(r), read(c), assign(l, r, c);
else if (op[0] == 'A') read(c), read(x), tag[c] += x;
else read(x), printf("%lld\n", T.Query(x) + tag[find(x)]);
}
}

CF1638E Colorful Operations的更多相关文章

  1. backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized.

    昨天在检查YourSQLDba备份时,发现有台数据库做备份时出现了下面错误信息,如下所示: <Exec>   <ctx>yMaint.ShrinkLog</ctx> ...

  2. HDU 5938 Four Operations(四则运算)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  3. ios基础篇(二十九)—— 多线程(Thread、Cocoa operations和GCD)

    一.进程与线程 1.进程 进程是指在系统中正在运行的一个应用程序,每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内: 如果我们把CPU比作一个工厂,那么进程就好比工厂的车间,一个工厂有 ...

  4. OpenCascade Modeling Algorithms Boolean Operations

    Modeling Algorithms Boolean Operations of Opencascade eryar@163.com 布尔操作(Boolean Operations)是通过两个形状( ...

  5. A.Kaw矩阵代数初步学习笔记 4. Unary Matrix Operations

    “矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...

  6. A.Kaw矩阵代数初步学习笔记 3. Binary Matrix Operations

    “矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...

  7. mouse scrollings and zooming operations in linux & windows are opposite

    mouse scrollings and zooming operations in linux & windows are opposite. windows中, 鼠标滚动的方向是: 查看页 ...

  8. MongoDB—— 写操作 Core MongoDB Operations (CRUD)

    MongoDB使用BSON文件存储在collection中,本文主要介绍MongoDB中的写操作和优化策略. 主要有三种写操作:        Create        Update        ...

  9. MongoDB—— 读操作 Core MongoDB Operations (CRUD)

    本文主要介绍内容:从MongoDB中请求数据的不同的方法 Note:All of the examples in this document use the mongo shell interface ...

  10. [codeforces 339]D. Xenia and Bit Operations

    [codeforces 339]D. Xenia and Bit Operations 试题描述 Xenia the beginner programmer has a sequence a, con ...

随机推荐

  1. Java开发学习(四十五)----MyBatisPlus查询语句之映射匹配兼容性

    1.映射匹配兼容性 我们已经能从表中查询出数据,并将数据封装到模型类中,这整个过程涉及到一张表和一个模型类: 之所以数据能够成功的从表中获取并封装到模型对象中,原因是表的字段列名和模型类的属性名一样. ...

  2. 运用领域模型——DDD

    模型被用来描述人们所关注的现实或想法的某个方面.模型是一种简化.它是对现实的解释 -- 把与解决问题密切相关的方面抽象出来,而忽略无关的细节. 每个软件程序是为了执行用户的某项活动,或是满足客户的某种 ...

  3. day24 JDBC批处理(通用泛型查询方法 & 下划线转驼峰命名法)

    批处理 public static Integer addBatch(String[] sqls){ init(); try { //设置关闭自动提交 conn.setAutoCommit(false ...

  4. 【Java EE】Day07 HTML

    一.WEB概念 1.软件架构 C/S:安卓.QQ.迅雷,开发两端 B/S 2.资源分类 静态资源:浏览器内置解析引擎 HTML:展示内容 CSS:页面布局 JavaScript:控制页面元素,产生动态 ...

  5. Windows10下python3和python2同时安装(三)VS 2013配置python环境

    Windows10下python3和python2同时安装(三) VS 2013配置python环境 说明:本文基于python2和python3同时安装之后,对VS 2013进行配置,下面有些地方文 ...

  6. ChatGPT杀疯了,这人工智能也太离谱了吧

    转载请注明出处️ 作者:测试蔡坨坨 原文链接:caituotuo.top/2ac8440d.html 你好,我是测试蔡坨坨. 这几天被ChatGPT刷屏,各大网站平台都能看到关于它的文章和视频,上线短 ...

  7. JAVA学到方法写了一个四则运算计算器,请教一下有什么需要改进的

    package method; /* * 四则运算计算器 * */ import java.util.Scanner; public class Demo07 { public static void ...

  8. vue 点击按钮添加一行dom节点

    如图,最近项目需求,点击添加一行dom节点,包含下拉框和input输入框 ,下面展示一下代码 <ul class="sales-menuItem-ul"> <li ...

  9. MongoDB - 模式设计

    注意事项 模式设计,即在文档中表示数据的方式,对于数据表示来说时非常关键的. 为 MongoDB 做模式设计时,在性能.可伸缩性和简单性方面是重中之重,也需要考虑一些特别的注意事项. 限制条件 与常见 ...

  10. iOS根据两点经纬度坐标计算指南针方位角

    目录 需求 设计 代码实现 新建CLLocation 分类方法 调用示例 结论 需求 在地图导航时,始终保持当前路段竖直超前. 设计 因地图暴露的方法中只有设置地图相对于正北的方向角的方法.因此,需要 ...