I_AK_IOI_6648 @ 2024-08-17 17:57:39
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t[400005],w[400005],a[400005];
void pushup(int u)
{
w[u]=w[u*2]+w[u*2+1];
}
void build(int l,int r,int x)
{
if(l==r)
{
w[x]=a[l];
return;
}
int mid=(l+r)/2;
build(l,mid,x*2);
build(mid+1,r,x*2+1);
pushup(x);
}
void maketag(int u,int s,int x)
{
t[u]+=x;
w[u]+=s*x;
}
void pushdown(int u,int l,int r)
{
int mid=(l+r)/2;
maketag(u*2,mid-l+1,t[u]);
maketag(u*2+1,r-mid,t[u]);
t[u]=0;
}
int query(int u,int x,int y,int l,int r)
{
if(l<=x&&y<=r)
{
return w[u];
}
else if(l>y||r<x)
{
return 0;
}
int mid=(x+y)/2;
pushdown(u,x,y);
return query(u*2,x,mid,l,r)+query(u*2+1,mid+1,y,l,r);
}
void update(int u,int x,int y,int l,int r,int k)
{
if(l<=x&&r>=y)
{
maketag(u,y-x+1,k);
return;
}
else if(l>y||r<x)
{
return;
}
int mid=(x+y)/2;
pushdown(u,x,y);
update(u*2,x,mid,l,r,k);
update(u*2+1,mid+1,y,l,r,k);
pushup(u);
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m,opt,x,y,k;
cin>>a[1]>>a[2];
build(1,n,1);
cout<<query(1,1,n,1,2);
return 0;
}
by DAMDAM @ 2024-08-17 18:53:45
@I_AK_IOI_6648 n = 2;
by I_AK_IOI_6648 @ 2024-08-17 20:02:23
@DAMDAM thx
by wuyuyaostxq @ 2024-08-18 10:44:50
1
by L_like_C @ 2024-08-19 19:11:36
我们做的是同一题吗
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b;
return 0;
}
by NC20061226 @ 2024-08-23 18:12:46
@L_like_C 这题也能用线段树做