比赛 |
2025.3.6 |
评测结果 |
AAAAAAAAAA |
题目名称 |
WHZ 的序列 |
最终得分 |
100 |
用户昵称 |
李奇文 |
运行时间 |
3.534 s |
代码语言 |
C++ |
内存使用 |
26.14 MiB |
提交时间 |
2025-03-06 20:48:13 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=2e5;
ll a[Maxn*2][3];
struct tree {
ll l,r,tb,lazy;
} f[Maxn*4][2];
ll n,q;
void build(ll p,ll l,ll r,ll v) {
f[p][v].l=l,f[p][v].r=r;
if(l==r) {
f[p][v].tb=a[l][v];
return;
}
ll mid=(l+r)/2;
build(p*2,l,mid,v);
build(p*2+1,mid+1,r,v);
f[p][v].tb=f[p*2][v].tb+f[p*2+1][v].tb;
return;
}
void pushlazy(ll p,ll v){
if(!f[p][v].lazy){
return;
}else{
ll lp=p*2,rp=p*2+1;
f[lp][v].lazy+=f[p][v].lazy;
f[rp][v].lazy+=f[p][v].lazy;
ll mid=(f[p][v].l+f[p][v].r)>>1;
f[lp][v].tb+=(mid-f[p][v].l+1)*f[p][v].lazy;
f[rp][v].tb+=(f[p][v].r-mid)*f[p][v].lazy;
f[p][v].lazy=0;
}
return;
}
ll qjh(ll p,ll x,ll y,ll v) {
if(x<=f[p][v].l&&f[p][v].r<=y) {
return f[p][v].tb;
}
pushlazy(p,v);
ll mid=(f[p][v].l+f[p][v].r)/2,sum=0;
if(x<=mid) {
sum+=qjh(p*2,x,y,v);
}
if(mid<y) {
sum+=qjh(p*2+1,x,y,v);
}
return sum;
}
void change(ll p,ll l,ll r,ll k,ll v){
if(l<=f[p][v].l&&f[p][v].r<=r){
f[p][v].lazy+=k;
f[p][v].tb+=(f[p][v].r-f[p][v].l+1)*k;
return;
}else{
pushlazy(p,v);
ll mid=(f[p][v].l+f[p][v].r)/2;
if(l<=mid) change(p*2,l,r,k,v);
if(mid<r) change(p*2+1,l,r,k,v);
f[p][v].tb=f[p*2][v].tb+f[p*2+1][v].tb;
}
return;
}
int main() {
freopen("whz_sequence.in","r",stdin);
freopen("whz_sequence.out","w",stdout);
std::cin>>n;
ll xc=1,yc=1;
for(ll i=1; i<=n; i++) {
std::cin>>a[i][2];
if(i%2==1){
a[i/2+1][0]=a[i][2];
}else{
a[i/2][1]=a[i][2];
}
}
std::cin>>q;
build(1,1,n,0);
build(1,1,n,1);
for(ll i=1; i<=q; i++) {
ll opt,x,y;
std::cin>>opt>>x>>y;
if(opt==1){
ll d;
std::cin>>d;
change(1,x/2+1,(y+1)/2,d,0);
change(1,(x+1)/2,y/2,d,1);
}else{
if(x%2==1){
std::cout<<qjh(1,x/2+1,(y+1)/2,0)-qjh(1,(x+1)/2,y/2,1)<<endl;
}else{
std::cout<<qjh(1,(x+1)/2,y/2,1)-qjh(1,x/2+1,(y+1)/2,0)<<endl;
}
}
}
return 0;
}