RT.
现在的:
#include<bits/stdc++.h>
using namespace std;
int maxx;
unsigned read(){
unsigned x=0;
char c=getchar();
while(~c&&c>=48){
x=(x<<1)+(x<<3)+(c^48);
c=getchar();
}
return x;
}
unsigned Max(const unsigned&x,const unsigned&y){
if(x>y)return x;
return y;
}
struct Tree{
struct node{
unsigned l,r,Lazy,sum;
}t[4005];
void build(const unsigned&l,const unsigned&r,const unsigned&p){
t[p].l=l;
t[p].r=r;
unsigned m=(l+r)>>1;
if(l==r)return;
build(l,m,p<<1);
build(m+1,r,p<<1|1);
}
unsigned getsum(const unsigned&l,const unsigned&r,const unsigned&p){
if(t[p].sum<=maxx)return 0;
unsigned L=t[p].l,R=t[p].r;
if(L>=l&&R<=r)return t[p].sum;
if(R<l||L>r)return 0;
if(t[p].Lazy){
t[p<<1|1].Lazy=t[p<<1].Lazy=t[p<<1].sum=t[p<<1|1].sum=t[p].Lazy;
t[p].Lazy=0;
}
return Max(getsum(l,r,p<<1),getsum(l,r,p<<1|1));
}
void update(const unsigned&l,const unsigned&r,const unsigned&p,const unsigned&c){
unsigned L=t[p].l,R=t[p].r;
if(L>=l&&R<=r){t[p].sum=c;t[p].Lazy=c;return;}
if(R<l||L>r)return;
if(t[p].Lazy){
t[p<<1|1].Lazy=t[p<<1].Lazy=t[p<<1].sum=t[p<<1|1].sum=t[p].Lazy;
t[p].Lazy=0;
}
update(l,r,p<<1,c);
update(l,r,p<<1|1,c);
t[p].sum=Max(t[p<<1].sum,t[p<<1|1].sum);
}
}T[1005];
thread thr[1005];
unsigned h,w,m,ans;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
h=read();w=read();m=read();
if(h>w){
for(unsigned i(0);i<=w;i++){
T[i].build(0,h,1);
}
while(m--){
unsigned x,y,s,d,w;
maxx=0;
d=read();s=read();w=read();x=read();y=read();
--d;
for(unsigned Y(y);Y<y+s;++Y){
maxx=Max(maxx,T[Y].getsum(x,x+d,1));
}
maxx+=w;
if(maxx>ans)ans=maxx;
for(unsigned Y(y);Y<y+s;++Y){
T[Y].update(x,x+d,1,maxx);
}
}
cout<<ans;
}else{
for(unsigned i(0);i<=h;i++){
T[i].build(0,w,1);
}
while(m--){
unsigned x,y,s,d,w;
maxx=0;
d=read();s=read();w=read();x=read();y=read();
--s;
for(unsigned X(x);X<x+d;++X){
maxx=Max(maxx,T[X].getsum(y,y+s,1));
}
maxx+=w;
if(maxx>ans)ans=maxx;
for(unsigned X(x);X<x+d;++X){
T[X].update(y,y+s,1,maxx);
}
}
cout<<(int)ans;
}
return 0;
}
学校 69,洛谷 48
远古的:
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct Tree{
struct node{
int l,r,sum,Lazy;
}t[4005];
void build(int l,int r,int p){
t[p].l=l;
t[p].r=r;
t[p].Lazy=0;
int m=(l+r)>>1;
if(l==r){
t[p].sum=0;
return;
}
build(l,m,p*2);
build(m+1,r,p*2+1);
t[p].sum=max(t[p*2].sum,t[p*2+1].sum);
}
int getsum(int l,int r,int p){
int L=t[p].l,R=t[p].r;
if(L>=l&&R<=r)return t[p].sum;
if(R<l||L>r)return 0;
int m=(L+R)>>1;
if(t[p].Lazy&&L!=R){
t[p*2].sum=t[p].Lazy;
t[p*2+1].sum=t[p].Lazy;
t[p*2].Lazy=t[p].Lazy;
t[p*2+1].Lazy=t[p].Lazy;
t[p].Lazy=0;
}
return max(getsum(l,r,p*2),getsum(l,r,p*2+1));
}
void update(int l,int r,int p,int c){
int L=t[p].l,R=t[p].r;
if(L>=l&&R<=r){t[p].sum=c;t[p].Lazy=c;return;}
if(R<l||L>r)return;
int m=(L+R)>>1;
if(t[p].Lazy&&L!=R){
t[p*2].sum=t[p].Lazy;
t[p*2+1].sum=t[p].Lazy;
t[p*2].Lazy=t[p].Lazy;
t[p*2+1].Lazy=t[p].Lazy;
t[p].Lazy=0;
}
update(l,r,p*2,c);
update(l,r,p*2+1,c);
t[p].sum=max(t[p*2].sum,t[p*2+1].sum);
}
}T[1005];
int h,w,m,ans;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>h>>w>>m;
for(int i=0;i<=1000;i++){
T[i].build(0,1000,1);
}
while(m--){
int x,y,s,d,w,maxx=0;
cin>>d>>s>>w>>x>>y;
for(int X=x;X<x+d;X++){
maxx=max(maxx,T[X].getsum(y,y+s-1,1));
}
maxx+=w;
ans=max(ans,maxx);
for(int X=x;X<x+d;X++){
T[X].update(y,y+s-1,1,maxx);
}
}
cout<<ans<<"\n";
return 0;
}
学校 69,洛谷 68