当前位置:网站首页>ABC253F Operations on a Matrix
ABC253F Operations on a Matrix
2022-06-12 09:03:00 【andyc_03】
题意
给定一个n*m的方格,初始均为0,有以下三种操作:
1.给l-r行每个位置加x
2.给l列每个位置修改为x
3.询问x列y行的值
分析
我们考虑第q次询问的答案,是由上一次修改第y列的位置q',和q'-q次之间修改x行的和组成的
因为加x的操作可加减,所以这里不需要主席树,可以离线下来做一个用前缀差计算,维护树状数组即可
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
int n,m,q;
int opt[maxn],a[maxn],b[maxn],c[maxn];
int pos[maxn],cnt;
vector <int> del[maxn];
ll val[maxn],ans[maxn];
int lowbit(int x)
{
return x&(-x);
}
void modify(int pos,ll x)
{
while(pos<=m+1)
{
val[pos]+=x;
pos+=lowbit(pos);
}
}
ll query(int pos)
{
ll res=0;
while(pos)
{
res+=val[pos];
pos-=lowbit(pos);
}
return res;
}
int id[maxn],rev[maxn];
int main()
{
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=q;i++)
{
scanf("%d",&opt[i]);
if(opt[i]==1)
{
scanf("%d%d%d",&a[i],&b[i],&c[i]);
b[i]++;
}
if(opt[i]==2)
{
scanf("%d%d",&a[i],&c[i]);
pos[a[i]]=i;
}
if(opt[i]==3)
{
scanf("%d%d",&a[i],&b[i]);
swap(a[i],b[i]);
int x=c[pos[b[i]]];
ans[++cnt]=x;
id[i]=cnt; rev[cnt]=i;
del[pos[b[i]]].push_back(cnt);
}
}
// for(int i=1;i<=cnt;i++) printf("%lld\n",ans[i]);
for(int i=1;i<=q;i++)
{
if(opt[i]==1)
{
modify(a[i],c[i]);
modify(b[i],-c[i]);
}
if(opt[i]==2)
for(auto v:del[i]) ans[v]-=query(a[rev[v]]);
if(opt[i]==3)
ans[id[i]]+=query(a[i]);
}
for(int i=1;i<=cnt;i++) printf("%lld\n",ans[i]);
return 0;
}边栏推荐
- sql中的Exists用法
- 【字符集八】char8_t、char16_t、char32_t、wchar、char
- Can you migrate backwards before the first migration in the south- Can you migrate backwards to before the first migration in South?
- 机器学习笔记 - 循环神经网络备忘清单
- 《MATLAB 神經網絡43個案例分析》:第7章 RBF網絡的回歸--非線性函數回歸的實現
- Load the source code of 2D 3D virtual anchor in the web page (1: project introduction and source code)
- Application method of new version UI of idea + use method of non test qualification and related introduction
- Cookies and sessions
- The newline character with in the string is converted to an array
- Background color translucent
猜你喜欢

Background location case II

IDEA新版UI申请方法+无测试资格使用方法及相关介绍

第三章 寄存器 (内存访问)

Display the remaining valid days according to the valid period

Filters and listeners

分库分表会带来读扩散问题?怎么解决?

网页中加载二次元3D虚拟主播源码(1:项目介绍和源码)

Binlog in mysql:

2022 low voltage electrician retraining question bank and online simulation examination

Unittest test framework
随机推荐
Cookies and sessions
Notes used by mqtt (combined with source code)
长安链节点证书、角色、权限管理介绍
Flink CheckPoint : Exceeded checkpoint tolerable failure threshold
Inheritance of row height
Make a simple page with the websql database of HTML5:
day5-x
Analysis of 43 cases of MATLAB neural network: Chapter 7 regression of RBF Network -- Realization of nonlinear function regression
Graphic analysis of viewbox in SVG
Building a cluster: and replacing with error
Judge whether the object is empty
[character set 6] wide string and multi byte character conversion
域名映射到指定IP
Chapter V -[bx] and loop instructions
[advanced pointer I] character array & array pointer & pointer array
Background position - mixed units
About weights exercise
Minimum transfer times
(十四)InputField逻辑分析
consul 配置相关