ULGANOY @ 2022-11-04 17:38:52
线段树最后一个点MLE 怎么办?
by UnyieldingTrilobite @ 2022-11-04 17:41:09
建议发代码,不然空谈么
by ULGANOY @ 2022-11-04 17:42:14
#include<bits/stdc++.h>
using namespace std;
int n,p;
int a;
struct tree{
int l,r,minn,add;
}tr[5000005*4];
inline void pushup(int p)
{
tr[p].minn=min(tr[p<<1].minn,tr[p<<1|1].minn);
}
void build(int p,int l,int r)
{
tr[p].l=l,tr[p].r=r;
if(l==r)
{
cin>>a;
tr[p].minn=a;
//cout<<"F**K CCF"<<endl;
return ;
}
int mid=(l+r)>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
pushup(p);
}
inline void pushdown(int p)
{
tr[p<<1].add+=tr[p].add;
tr[p<<1|1].add+=tr[p].add;
tr[p<<1].minn+=tr[p].add;
tr[p<<1|1].minn+=tr[p].add;
tr[p].add=0;
}
inline void modify(int p,int l,int r,int x)
{
if(l<=tr[p].l&&tr[p].r<=r)
{
tr[p].add+=x;
tr[p].minn+=x;
return ;
}
pushdown(p);
int mid=(tr[p].l+tr[p].r)>>1;
if(l<=mid)modify(p<<1,l,r,x);
if(r>mid)modify(p<<1|1,l,r,x);
pushup(p);
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>p;
build(1,1,n);
int x,y,z;
while(p--)
{
cin>>x>>y>>z;
modify(1,x,y,z);
}
cout<<tr[1].minn<<endl;
return 0;
}
by hy233 @ 2022-11-04 17:44:34
8e7个int需要约280M,无法通过
srds,这不应该是差分模板题嘛
by hy233 @ 2022-11-04 17:44:43
@D2019ly
by ULGANOY @ 2022-11-04 17:48:05
@hy233 是的 已经用差分过了 只是想打一下线段树 qaq
by hy233 @ 2022-11-04 17:49:24
@D2019ly srds,2e6的限制一个合格的造数据人肯定会吧线段树卡掉的吧
by ULGANOY @ 2022-11-04 17:50:25
@hy233 所以线段树最多到1e6左右吗?
by UnyieldingTrilobite @ 2022-11-04 17:53:28
@D2019ly 你这个代码的线段树需要四倍空间,优化到两倍就可以过了
by UnyieldingTrilobite @ 2022-11-04 17:53:53
至于优化的方法见 https://www.cnblogs.com/chy-2003/p/11815396.html
代码我已经帮你改好了,过了,需要的话可以再叫我
by hy233 @ 2022-11-04 17:54:10
@D2019ly 看具体实现吧,个人经验是一般超过5e5的题过不了