当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Warp shuffle in CUDA
AWD learning
The default Google browser cannot open the link (clicking the hyperlink does not respond)
Linked list (linear structure)
Solution to the black screen of win computer screenshot
Unexpected inconsistency caused by abnormal power failure; Run fsck manually problem resolved
Log (common log framework)
Win10桌面图标没有办法拖动(可以选中可以打开可以删除新建等操作但是不能拖动)
Usage of map and foreach in JS
Présence d'une panne de courant anormale; Problème de gestion de la fsck d'exécution résolu
随机推荐
Blog directory of zzq -- updated on 20210601
Storage space modifier in CUDA
Error "list" object is not callable in Web automatic switching window
Three suggestions for all students who have graduated and will graduate
There are multiple good constructors and room will problem
ModuleNotFoundError: No module named ‘jieba. analyse‘; ‘ jieba‘ is not a package
Promise中有resolve和无resolve的代码执行顺序
The win10 network icon disappears, and the network icon turns gray. Open the network and set the flash back to solve the problem
【文献阅读与想法笔记13】 Unprocessing Images for Learned Raw Denoising
由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
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)
virtualenv和pipenv安装
Find the highest value of the current element Z-index of the page
华为MindSpore开源实习机试题
Flask-Migrate 检测不到db.string() 等长度变化
Win10网络图标消失,网络图标变成灰色,打开网络设置闪退等问题解决
Redis——热点key问题
automation - Jenkins pipline 执行 nodejs 命令时,提示 node: command not found
Utilisation de la carte et de foreach dans JS
Latex warning: citation "*****" on page y undefined on input line*