\(\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. 关于python导包问题(新手向)

    包和模块 首先要弄清这两个概念, 在python 中 一个文件夹中包含__init__.py 文件(这个文件是包的初始化文件,在你导入包或包下面的模块的时候,这个文件会最开始运行),就会被python ...

  2. 关于linux上mysql导出excel 文件

    这里简单介绍两种方法导出 1.在mysql交互中 首先查看"secure_file_priv"变量 SHOW VARIABLES LIKE "secure_file_pr ...

  3. 【数据库】union和union all合并结果操作

    一.含义 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每条 SELECT 语句中的 ...

  4. 【每日一题】【栈和队列、双端队列】20. 有效的括号/NC52 有效括号序列-211127/220126

    给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合.左括号必须以正确的顺序闭合. 来源:力扣(L ...

  5. requests模块和openpyxl模块

    第三方模块的下载和使用 1,第三方模块就是别人大神们已经写好的模块,功能特别强大.我们如果像使用第三方模块就先要进行下载.下载完成后 才可以在python中直接调用 2.下载方式一:pip工具 pip ...

  6. layui table 表头抖动

    原本table超出页面宽度(即table有横向滚动条)的情况下,缩放页面然后再设置定时器定时更新表单,会发现数据不变的时候table头部会左右抖动 而且th td比设置的minWidth 或者cell ...

  7. Elasticsearch模糊查询、多字段in查询、时间范围查询,DSL和java API两种方式

    Elasticsearch模糊查询.多字段in查询.时间范围查询,DSL和java API两种方式 项目场景: Elasticsearch模糊查询某字段.多字段in查询.时间范围查询,通过DSL和ja ...

  8. 封装 avm 组件经验分享

    avm.js 是一个跨端开发框架,AVM(Application-View-Model)前端组件化开发模式基于标准Web Components组件化思想,提供包含虚拟DOM和Runtime的编程框架a ...

  9. [OpenCV实战]46 在OpenCV下应用图像强度变换实现图像对比度均衡

    本文主要介绍基于图像强度变换算法来实现图像对比度均衡.通过图像对比度均衡能够抑制图像中的无效信息,使图像转换为更符合计算机或人处理分析的形式,以提高图像的视觉价值和使用价值.本文主要通过OpenCV ...

  10. Python从0到1丨细说图像增强及运算

    摘要:本文主要讲解常见的图像锐化和边缘检测方法,即Roberts算子和Prewitt算子. 本文分享自华为云社区<[Python从零到壹] 五十七.图像增强及运算篇之图像锐化Roberts.Pr ...