CF1638E Colorful Operations
\(\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的更多相关文章
- 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> ...
- HDU 5938 Four Operations(四则运算)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- ios基础篇(二十九)—— 多线程(Thread、Cocoa operations和GCD)
一.进程与线程 1.进程 进程是指在系统中正在运行的一个应用程序,每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内: 如果我们把CPU比作一个工厂,那么进程就好比工厂的车间,一个工厂有 ...
- OpenCascade Modeling Algorithms Boolean Operations
Modeling Algorithms Boolean Operations of Opencascade eryar@163.com 布尔操作(Boolean Operations)是通过两个形状( ...
- A.Kaw矩阵代数初步学习笔记 4. Unary Matrix Operations
“矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...
- A.Kaw矩阵代数初步学习笔记 3. Binary Matrix Operations
“矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...
- mouse scrollings and zooming operations in linux & windows are opposite
mouse scrollings and zooming operations in linux & windows are opposite. windows中, 鼠标滚动的方向是: 查看页 ...
- MongoDB—— 写操作 Core MongoDB Operations (CRUD)
MongoDB使用BSON文件存储在collection中,本文主要介绍MongoDB中的写操作和优化策略. 主要有三种写操作: Create Update ...
- MongoDB—— 读操作 Core MongoDB Operations (CRUD)
本文主要介绍内容:从MongoDB中请求数据的不同的方法 Note:All of the examples in this document use the mongo shell interface ...
- [codeforces 339]D. Xenia and Bit Operations
[codeforces 339]D. Xenia and Bit Operations 试题描述 Xenia the beginner programmer has a sequence a, con ...
随机推荐
- 基于pyecharts的中医药知识图谱可视化
基于pyecharts的中医药知识图谱可视化 关键词: pyecharts:可视化:中医药知识图谱 摘要: 数据可视化是一种直观展示数据结果和变化情况的方法,可视化有助于知识发现与应用.Neo4j数据 ...
- angr_ctf——从0学习angr(一):angr简介与核心概念
我在学习angr时,先是阅读了开发者发布在IEEE上的论文IEEE Xplore Full-Text PDF:该文章讲述了自动化漏洞挖掘的背景和方法,并对angr的架构和核心模块进行了介绍,非常经典值 ...
- 使用python批量更改文件
最近整理之前学爬虫存储的文件,发现有很多文件名有重复,而我有一点点强迫症,不想文件名重复,就写了一个Python代码来解决文件名重复问题 import os import random import ...
- AWVS漏洞扫描器的使用
前言 AWVS是一款强大的web漏洞扫描工具,扫描速度快,可针对特定的漏洞进行扫描测试,用于在按全人员对指定企业进行安全扫描以及测试人员对web应用检测漏洞. AWVS使用以及功能介绍 这里介绍的是使 ...
- Redis基础学习笔记
技术分类: 1.解决功能性的问题:Java.Jsp.RDBMS.Tomcat.HTML.Linux.JDBC.SVN 2.解决扩展性的问题:Struts.Spring.SpringMVC.Hibern ...
- 旧酒换新瓶,新版M1/M2芯片Macos(Ventura)安装古早版本Python2.7(Python2.x)
向下兼容特性是软件开发系统的一个重要指标,它是指一个新的系统或者软件能够与旧的系统或软件兼容并正常运行.这意味着旧系统或软件可以在新系统或软件中使用,而不会出现问题.向下兼容对于提高软件或系统的可用性 ...
- python之路45 初识django框架
纯手撸web框架 1.web框架的本质 理解1:连接前端与数据库的中间介质 理解2:socket服务端 2.手写web框架 1.编写socket服务端代码 2.浏览器访问响应无效>>> ...
- KMP 与 Z 函数
\(\text{By DaiRuiChen007}\) 一.KMP 算法 I. 问题描述 在文本串 \(S\) 中找到模式串 \(T\) 的所有出现,其中 \(|S|=n,|T|=m\) II. 前置 ...
- .NET 7新特性
2022年11月份微软推出了带有STS(标准期限支持)的.NET版本7,仅提供18个月的支持. 微软今年推出了STS版本,因为它已经在2019年提到,它将在每年11月左右发布一个新版本的.NET. 但 ...
- 震网(Stuxnet)病毒深度解析:首个攻击真实世界基础设施的病毒
摘要:震网病毒主要是通过改变离心机的转速,来破坏离心机,并影响生产的浓缩铀质量. 本文分享自华为云社区<[安全技术]震网(Stuxnet)病毒深度解析:首个攻击真实世界基础设施的病毒(1)[原创 ...