当前位置:网站首页>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;
}边栏推荐
猜你喜欢

pytest(1) 用例收集规则

Latex warning: citation "*****" on page y undefined on input line*

There is no way to drag the win10 desktop icon (you can select it, open it, delete it, create it, etc., but you can't drag it)

Find the highest value of the current element Z-index of the page

Présence d'une panne de courant anormale; Problème de gestion de la fsck d'exécution résolu
![[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

20201002 vs 2019 qt5.14 developed program packaging

web自动中利用win32上传附件

Latex 编译报错 I found no \bibstyle & \bibdata & \citation command

Linux MySQL 5.6.51 Community Generic 安装教程
随机推荐
Build learning tensorflow
20201002 vs 2019 qt5.14 developed program packaging
(第一百篇BLOG)写于博士二年级结束-20200818
apt命令报证书错误 Certificate verification failed: The certificate is NOT trusted
Automation - when Jenkins pipline executes the nodejs command, it prompts node: command not found
Redis——Cluster数据分布算法&哈希槽
Blog directory of zzq -- updated on 20210601
selenium+msedgedriver+edge浏览器安装驱动的坑
[literature reading and thought notes 13] unprocessing images for learned raw denoising
FE - Eggjs 结合 Typeorm 出现连接不了数据库
Codeforces Round #797 (Div. 3) A—E
Virtualenv and pipenv installation
Redis - hot key issues
FE - weex 开发 之 使用 weex-ui 组件与配置使用
Functions of tensorrt
Flask-Migrate 检测不到db.string() 等长度变化
Warp matrix functions in CUDA
pytest(1) 用例收集规则
Vscode installation, latex environment, parameter configuration, common problem solving
The default Google browser cannot open the link (clicking the hyperlink does not respond)