\(\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. CLion和动态链接库

    目录 生成链接库 链接库的使用 生成链接库 创建一个library项目 在项目中写好自己的代码 cmakelist cmake_minimum_required(VERSION 3.21) proje ...

  2. 【Linux】通过Crontab和shell脚本实现定期备份和删除PG数据库表数据

    〇.参考资料 一.Crontab使用 1.查看状态 service crond status 2.新建crontab任务 crontab -e 输入字符串 * * * * * cd /home/big ...

  3. 利用node快速生成脚本

    整理框架时突然发现两个文件从来没有使用过,删除的瞬间仿佛get到了用处. fs 可用于与文件系统进行交互模块 path 提供一些实用工具,用于处理文件和目录的路径 process.argv 返回一个数 ...

  4. 边框 display属性 盒子模型 浮动 溢出 定位 z-index

    目录 边框 隐藏属性 钓鱼网站 display visibility 盒子模型 调整方式 浮动 溢出 圆形头像的制作 定位 z-index属性 边框 /*border-left-width: 5px; ...

  5. 常用内置模块之collections模块、时间模块、随机数random模块

    今日内容回顾 目录 今日内容回顾 包的具体使用 编程思想的转变 软件开发目录规范 常用内置模块之collections模块 常用内置模块之时间模块 常用内置模块之随机数random模块 报的具体使用 ...

  6. 从面试题入手,畅谈 Vue 3 性能优化

    前言 今年又是一个非常寒冷的冬天,很多公司都开始人员精简.市场从来不缺前端,但对高级前端的需求还是特别强烈的.一些大厂的面试官为了区分候选人对前端领域能力的深度,经常会在面试过程中考察一些前端框架的源 ...

  7. 【转载】SQL SERVER2008 修改数据库名相关的脚本

    -- 修改数据库名 -- 1.首先查找数据库是否占用,杀掉占用的id select spid from master.dbo.sysprocesses where dbid=db_id('ClothC ...

  8. 使用Zolom内存解析运行python脚本(不落地)

    在目标机器运行python工具 好多工具都是python写的,如果目标机器是linux的话自带python环境可以很方便的运行这些工具,但是windows下是不自带python环境的,所以一种办法是直 ...

  9. mysql 列约束

    mysql可以对插入的数据进行特定得验证,只有满足条件才可以插入到数据表中,否则认为是非法插入: 例如:人性别只可以是男.女.年龄只能是0-100. ①主键约束查重-PRIMARY KEY,1表一个: ...

  10. 实操记录之-----Ant Design of Vue 增强版动态合并单元格,自动根据数据进行合并,可自定义横纵向合并

    前几天搞了个简易版的动态合并单元格 但是需求有变化,就只能稍微改改了~~ 欢迎路过的各位大佬指出我代码的问题~~~~ 另: 代码执行效率不是很高,如果需要大量渲染更多数据建议可以直接使用原生 < ...