当前位置:网站首页>Atcoder beginer contest 253 F - operations on a matrix / / tree array
Atcoder beginer contest 253 F - operations on a matrix / / tree array
2022-07-02 06:43:00 【Jakon_】
Subject portal :F - Operations on a Matrix (atcoder.jp)
The question :
Give me a N*M Zero matrix of size , as well as Q operations . operation 1(l,r,x): about [l,r] Add... To each column in the interval x; operation 2(i,x): For the first i That's ok , Replace with x; operation 3(i,j): Query matrix page i That's ok , The first j Value of column element .
N、M、Q All sizes are 2E5.
Ideas : Tree array
First of all, consider no operation 2 The situation of , Then it is easy to use the tree array to realize the interval addition of columns and single point query .
When there is an operation 2 when , For operation 3 Query for : The last operation of this line 2 The line modification value of is recorded as x, From the last operation 2 All... To this operation 1 The added value of the operation column is recorded as sum2, Then the output answer is x + sum2. All... From the beginning to this operation 1 The added value of the operation column is recorded as sum, From the beginning to the last operation 2 The column added value of is recorded as sum1, So there are sum2 = sum - sum1, The answer is :x + sum - sum1. You can query offline .
Code reference :
#include <bits/stdc++.h>
#define LL long long
#define lowbit(x) (x & -x)
using namespace std;
const int N = 200010;
int n, m, Q, last[N];
LL tr[N], ans[N];
vector<int> v[N];
struct query {
int op, a, b, c;
} q[N];
void add(int x, int c)
{
for(int i = x; i <= m; i += lowbit(i)) tr[i] += c;
}
LL sum(int x)
{
LL res = 0;
for(int i = x; i; i -= lowbit(i)) res += tr[i];
return res;
}
int main()
{
cin >> n >> m >> Q;
for(int i = 1; i <= Q; i++) {
scanf("%d%d%d", &q[i].op, &q[i].a, &q[i].b);
if(q[i].op == 1) scanf("%d", &q[i].c);
else if(q[i].op == 2) last[q[i].a] = i;
else v[last[q[i].a]].push_back(i);
}
for(int i = 1; i <= Q; i++) {
if(q[i].op == 1) add(q[i].a, q[i].c), add(q[i].b + 1, -q[i].c);
else if(q[i].op == 2) for(auto item : v[i]) ans[item] = q[i].b - sum(q[item].b);
else printf("%lld\n", ans[i] + sum(q[i].b));
}
return 0;
}边栏推荐
- virtualenv和pipenv安装
- Win10: add or delete boot items, and add user-defined boot files to boot items
- Deployment API_ automation_ Problems encountered during test
- 2020-9-23 use of QT timer qtimer class.
- NodeJs - Express 中间件修改 Header: TypeError [ERR_INVALID_CHAR]: Invalid character in header content
- 提高用户体验 防御性编程
- selenium的web自动化中常用的js-修改元素属性翻页
- Nodejs - Express middleware modification header: typeerror [err_invalid_char]: invalid character in header content
- Solution to the black screen of win computer screenshot
- unittest. Texttestrunner does not generate TXT test reports
猜你喜欢

PgSQL学习笔记

Win电脑截图黑屏解决办法

由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决

The intern left a big hole when he ran away and made two online problems, which made me miserable

Redis——大Key问题

Redis——Cluster数据分布算法&哈希槽

Utilisation de la carte et de foreach dans JS
![[literature reading and thought notes 13] unprocessing images for learned raw denoising](/img/a5/ed26a90b3edd75a37b2e5164f6b7d2.png)
[literature reading and thought notes 13] unprocessing images for learned raw denoising

Redis——热点key问题

Sentinel rules persist to Nacos
随机推荐
提高用户体验 防御性编程
Linux MySQL 5.6.51 Community Generic 安装教程
20201025 visual studio2019 qt5.14 use of signal and slot functions
Log (common log framework)
FE - weex 开发 之 使用 weex-ui 组件与配置使用
eslint配置代码自动格式化
Loops in tensorrt
unittest. Texttestrunner does not generate TXT test reports
Redis - cluster data distribution algorithm & hash slot
Cglib agent - Code enhancement test
Redis——大Key问题
Fe - wechat applet - Bluetooth ble development research and use
Storage space modifier in CUDA
PIP install
After reading useful blogs
Redis——Cluster数据分布算法&哈希槽
Kali latest update Guide
web自动中利用win32上传附件
kali最新更新指南
Nodejs - Express middleware modification header: typeerror [err_invalid_char]: invalid character in header content