Purple_meteor @ 2024-09-15 11:42:35
第三个点的输出是0,我的输出也是0,然后提示我(Too short on line 1)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll read()
{
char c='0';
ll rev=0,f=1;
do
{
rev=rev*10+c-'0';
c=getchar();
if(c=='-') f=-1,c=getchar();
}while('0'<=c&&c<='9');
return rev*f;
}
void write(ll x)
{
if(x<0)
{
putchar('-');
write(-x);
return ;
}
if(x>=10) write(x/10);
putchar(x%10+'0');
}
class Segment_tree
{
private:
struct tree
{
ll v,sum_tag,fix_tag;
bool fix;
}t[4000005];
void push_down(int p,int l,int r)
{
if(t[p].fix)
{
t[p<<1].fix_tag=t[p].fix_tag;
t[p<<1].fix=1;
t[p<<1].sum_tag=0;
t[p<<1].v=t[p].fix_tag;
t[p<<1|1].fix_tag=t[p].fix_tag;
t[p<<1|1].fix=1;
t[p<<1|1].sum_tag=0;
t[p<<1|1].v=t[p].fix_tag;
t[p].fix=0;
}
t[p<<1].sum_tag+=t[p].sum_tag;
t[p<<1].v+=t[p].sum_tag;
t[p<<1|1].sum_tag+=t[p].sum_tag;
t[p<<1|1].v+=t[p].sum_tag;
t[p].sum_tag=0;
}
void push_up(int p)
{
t[p].v=max(t[p<<1].v,t[p<<1|1].v);
}
void build(int p,int l,int r)
{
if(l==r)
{
t[p].v=num[l];
return ;
}
int mid=(l+r)/2;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
push_up(p);
}
void add(int p,int l,int r,int nl,int nr,int k)
{
if(nl<=l&&r<=nr)
{
t[p].sum_tag+=k;
t[p].v+=k;
return ;
}
int mid=(l+r)>>1;
push_down(p,l,r);
if(nl<=mid) add(p<<1,l,mid,nl,nr,k);
if(mid<nr) add(p<<1|1,mid+1,r,nl,nr,k);
push_up(p);
}
void fix(int p,int l,int r,int nl,int nr,int k)
{
if(nl<=l&&r<=nr)
{
t[p].sum_tag=0;
t[p].fix=1;
t[p].fix_tag=k;
t[p].v=k;
return ;
}
int mid=(l+r)>>1;
push_down(p,l,r);
if(nl<=mid) fix(p<<1,l,mid,nl,nr,k);
if(mid<nr) fix(p<<1|1,mid+1,r,nl,nr,k);
push_up(p);
}
ll query(int p,int l,int r,int nl,int nr)
{
if(nl<=l&&r<=nr)
{
return t[p].v;
}
ll ans=LONG_LONG_MIN;
int mid=(l+r)>>1;
push_down(p,l,r);
if(nl<=mid) ans=max(ans,query(p<<1,l,mid,nl,nr));
if(mid<nr) ans=max(ans,query(p<<1|1,mid+1,r,nl,nr));
push_up(p);
return ans;
}
public:
ll length,num[1000001];
void Input()
{
for(int i=1;i<=length;i++)
num[i]=read();
build(1,1,length);
}
void Add(int l,int r,int k)
{
add(1,1,length,l,r,k);
}
void Fix(int l,int r,int k)
{
fix(1,1,length,l,r,k);
}
ll Query(int l,int r)
{
return query(1,1,length,l,r);
}
}Tree;
ll q;
int main()
{
Tree.length=read();
q=read();
Tree.Input();
while(q--)
{
int op,l,r,k;
op=read();
l=read();
r=read();
switch(op)
{
case 1:
{
k=read();
Tree.Fix(l,r,k);
break;
}
case 2:
{
k=read();
Tree.Add(l,r,k);
break;
}
case 3:
{
write(Tree.Query(l,r));
putchar('\n');
break;
}
}
}
return 0;
}
by fogflea @ 2024-09-16 13:49:42
@Purple_meteor 快读的锅,这种写法不对,我换成我的就过了
inline ll read(){
ll x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')f=-1;
c=getchar();
}
while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
return x*f;
}
by Purple_meteor @ 2024-09-16 21:49:36
@fogflea 谢谢!已AC