AndyPomeloMars @ 2023-01-12 19:31:35
rt,样例都过,错的五个都说
read 0,expect -
求调,代码如下:
#include <iostream>
#define MAXN 1000010
#define INF -1e18
#define ll long long
using namespace std;
ll Seq[MAXN],SegTree[MAXN*4],Lzy_add[MAXN*4],Lzy_set[MAXN*4];
inline ll read(){
ll f=1,k=0;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
k=k*10+c-'0';
c=getchar();
}
return f*k;
}
inline void pushup(const int u){
SegTree[u] = max(SegTree[u<<1],SegTree[u<<1|1]);
}
inline void maketag(int u,ll val,int type){
if (type==1){
Lzy_add[u] = 0;
Lzy_set[u] = val;
SegTree[u] = val;
}
else{
if (Lzy_set[u]==INF) Lzy_add[u] += val;
else Lzy_set[u] += val;
SegTree[u] += val;
}
}
inline void pushdown(const int u){
if (Lzy_set[u]==INF){
maketag(u<<1,Lzy_add[u],2);
maketag(u<<1|1,Lzy_add[u],2);
Lzy_add[u] = 0;
}
else{
maketag(u<<1,Lzy_set[u],1);
maketag(u<<1|1,Lzy_set[u],1);
Lzy_set[u] = INF;
}
}
inline void build(int u,int L,int R){
Lzy_set[u] = INF;
if (L==R){
SegTree[u] = Seq[L];
return;
}
int M = (L+R) >> 1;
build(u<<1,L,M),build(u<<1|1,M+1,R);
pushup(u);
}
inline long long sectionquery(int u,int L,int R,int l,int r){
if ((l<=L) && (R<=r)) return SegTree[u];
else if (!((L>r) || (R<l))){
int M = (L+R) >> 1;
pushdown(u);
return max(sectionquery(u<<1,L,M,l,r),sectionquery(u<<1|1,M+1,R,l,r));
}
else return 0;
}
void sectionupdate(int u,int L,int R,int l,int r,ll val,int type){
if ((l<=L) && (R<=r)) maketag(u,val,type);
else if (!((L>r) || (R<l))){
int M = (L+R) >> 1;
pushdown(u);
sectionupdate(u<<1,L,M,l,r,val,type);
sectionupdate(u<<1|1,M+1,R,l,r,val,type);
pushup(u);
}
}
int main(){
int N = read(),Q = read();
for (int i=1;i<=N;++i) Seq[i] = read();
build(1,1,N);
while (Q--){
int op = read();
if (op==1){
int l=read(),r=read();
ll x = read();
sectionupdate(1,1,N,l,r,x,1);
}
else if (op==2){
int l=read(),r=read();
ll x = read();
sectionupdate(1,1,N,l,r,x,2);
}
else{
int l=read(),r=read();
cout << sectionquery(1,1,N,l,r) << endl;
}
}
return 0;
}
by 聊机 @ 2023-01-12 20:08:16
我感觉你有点天才
by 聊机 @ 2023-01-12 20:08:49
@AndyPomeloMars 建议好好看看你的查询
by AndyPomeloMars @ 2023-01-12 20:09:34
@聊机 呵呵,确实,已经找到错误了...
by AndyPomeloMars @ 2023-01-12 20:09:59
此贴终