传送门
【题目分析】
博主本着先给自己套个log的态度写了线段树。。。。。
其实可以做到O(n),甚至nm都是可以的因为不超过300。。。
讲讲线段树做法,因为可以将自己的笔给别人用,所以直接按题意区间加最后取个全局最大值就行了。
【代码~】
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e3+10;
int n;
struct Tree{
int l,r;
int maxx;
int add;
}tr[MAXN<<2];
int Read(){
int i=0,f=1;
char c;
for(c=getchar();(c>'9'||c<'0')&&c!='-';c=getchar());
if(c=='-')
f=-1,c=getchar();
for(;c>='0'&&c<='9';c=getchar())
i=(i<<3)+(i<<1)+c-'0';
return i*f;
}
void push_up(int root){
tr[root].maxx=max(tr[root<<1].maxx,tr[root<<1|1].maxx);
}
void push_now(int root,int key){
tr[root].add+=key;
tr[root].maxx+=key;
}
void push_down(int root){
if(tr[root].add){
push_now(root<<1,tr[root].add);
push_now(root<<1|1,tr[root].add);
tr[root].add=0;
}
}
void update(int root,int l,int r,int L,int R,int key){
if(l>R||r<L)
return ;
if(L<=l&&r<=R){
push_now(root,key);
return ;
}
push_down(root);
int mid=l+r>>1;
if(R<=mid)
update(root<<1,l,mid,L,R,key);
else{
if(L>mid)
update(root<<1|1,mid+1,r,L,R,key);
else
update(root<<1,l,mid,L,mid,key),update(root<<1|1,mid+1,r,mid+1,R,key);
}
push_up(root);
}
int main(){
n=Read();
for(int i=1;i<=n;++i){
int x=Read(),y=Read(),z=Read();
update(1,1,1000,x,y,z);
}
cout<<tr[1].maxx;
return 0;
}