https://www.luogu.com.cn/problem/P3368
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define lowbit(x) x&(-x)
using ll = long long;
using pii = pair<int, int>;
const double PI = acos(-1);
const int N = 5e5 + 10;
const int mod = 1e9 + 7;
ll c[N],a[N];
int n,m;
void updata(int x,int k){
for(int i=x;i<=n;i+=lowbit(i))
c[i]+=k;
}
ll query(int x){
ll sum=0;
for(int i=x;i;i-=lowbit((i))){
sum+=c[i];
}
return sum;
}
void solve() {
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++)
{
int x=a[i]-a[i-1];
updata(i,x);
}
while(m--){
int ch;cin>>ch;
if(ch==1){
int x,y,k;cin>>x>>y>>k;
updata(x,k);
updata(y+1,-k);
}
else{
int x;cin>>x;
cout<<query(x)<<endl;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
//cin>>T;
while (T--) {
solve();
}
return 0;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 【.NET】调用本地 Deepseek 模型
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库