\(\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. 1.2 Hadoop简介-hadoop-最全最完整的保姆级的java大数据学习资料

    目录 1.2 Hadoop简介 1.2.1 什么是Hadoop 1.2.2 Hadoop的起源 1.2.3 Hadoop的特点 1.2.4 Hadoop的发行版本 1.2.5 Apache Hadoo ...

  2. 【数据库】pgsql窗口函数,分组求sum的方式

    select distinct    quantity,    standard_cost,    sum(a.quantity*a.standard_cost) over(partition by ...

  3. include指令和include动作的区别

    include指令和<jsp:include>动作标识的区别 1.include指令通过file属性指定被包含的文件,并且file属性不支持任何表达式: <jsp:include&g ...

  4. uniapp onLoad里面拿不到reject的参数

    在onLoad中直接调用自己用promise封装的请求 reject居然会收不到参数.. onLoad(){ this.$fetch(xxxx) .catch(err=>{ }) // 这里获取 ...

  5. Nginx rewrite 详解

    Nginx rewrite 详解 本篇主要介绍 nginx 的 rewrite 重定向这个功能进行 详解介绍, 以及介绍它的使用场景 1. rewrite 基本介绍 rewrite是实现URL重写的关 ...

  6. Day38:Lambda表达式

    Lambda表达式 1.1 概述 Lambda是JDK8开始后的一种新语法形式. 作用:简化函数式匿名内部类的代码写法. 简化格式: /*部类被重写方法的参数)->{ 被重写方法的方法体代码 } ...

  7. 安装aio-pika报错

    报错内容: WARNING: You are using pip version 21.1.2; however, version 21.3.1 is available. You should co ...

  8. vulnhub靶场之DARKHOLE: 1

    准备: 攻击机:虚拟机kali.本机win10. 靶机:DarkHole: 1,下载地址:https://download.vulnhub.com/darkhole/DarkHole.zip,下载后直 ...

  9. Qt网络编程-从0到多线程编程

    网络编程开发 1.简介 两个协议,一个是TCP协议,一个是UDP协议 先说TCP: TCP的话,服务器端需要端口监听,直到有客户端进行连接发送过来请求数据,然后客户端根据请求数据进行应答,之后就算tc ...

  10. 音频音量调整中的ramp up & down

    在日常生活中不管是打电话还是听音乐,都会遇到音量不合适而去调整音量的情况.如果音量调整软件处理不好,就会听到pop noise.产生pop noise的原因是音量直接从当前值骤变到目标值,而不是缓慢的 ...