当前位置:网站首页>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;
}边栏推荐
- MySql索引
- kali最新更新指南
- Pytest (3) parameterize
- 浏览器滚动加载更多实现
- Automation - when Jenkins pipline executes the nodejs command, it prompts node: command not found
- Deployment API_ automation_ Problems encountered during test
- 【文献阅读与想法笔记13】 Unprocessing Images for Learned Raw Denoising
- Latex 报错 LaTeX Error: The font size command \normalsize is not defined问题解决
- Loops in tensorrt
- Asynchronous data copy in CUDA
猜你喜欢

CTF three count

Redis - cluster data distribution algorithm & hash slot

Latex在VSCODE中编译中文,使用中文路径问题解决

pytest(2) mark功能

Usage of map and foreach in JS

Latex error: the font size command \normalsize is not defined problem solved

Redis - big key problem

Sentinel Alibaba open source traffic protection component

Latex 报错 LaTeX Error: The font size command \normalsize is not defined问题解决

Pytest (1) case collection rules
随机推荐
virtualenv和pipenv安装
Pytest (1) case collection rules
The default Google browser cannot open the link (clicking the hyperlink does not respond)
Android - Kotlin 下使用 Room 遇到 There are multiple good constructors and Room will ... 问题
Eggjs -typeorm 之 TreeEntity 实战
AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组
Record RDS troubleshooting once -- RDS capacity increases dramatically
QQ email cannot receive the email sent by Jenkins using email extension after construction (timestamp or auth...)
Latex在VSCODE中编译中文,使用中文路径问题解决
Nodejs - Express middleware modification header: typeerror [err_invalid_char]: invalid character in header content
Redis - big key problem
Pytest (3) parameterize
Solution to the black screen of win computer screenshot
Loops in tensorrt
20201025 visual studio2019 qt5.14 use of signal and slot functions
Fe - weex uses a simple encapsulated data loading plug-in as the global loading method
Pytest (2) mark function
FE - weex 开发 之 使用 weex-ui 组件与配置使用
Win10桌面图标没有办法拖动(可以选中可以打开可以删除新建等操作但是不能拖动)
ZZQ的博客目录--更新于20210601