比赛 |
不平凡的世界 |
评测结果 |
AAAAAAAAAA |
题目名称 |
不平凡的boss |
最终得分 |
100 |
用户昵称 |
mildark |
运行时间 |
2.454 s |
代码语言 |
C++ |
内存使用 |
1.84 MiB |
提交时间 |
2015-11-05 11:48:38 |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
const int SIZEN=100010;
const int INF=0x7fffffff/2;
#define Nil NULL
int bval[SIZEN];
class Node{
public:
int l,r;
int lazy;
int ymn,smn;
Node *lc,*rc;
void set(int t){
lazy=t;
ymn=t;
smn=t+bval[l];
}
void push_down(void){
if(!lc||!lazy) return;
lc->set(lazy);
rc->set(lazy);
lazy=0;
}
void push_up(void){
if(!lc) return;
ymn=min(lc->ymn,rc->ymn);
smn=min(lc->smn,rc->smn);
}
int find_pos(int t){//碟???<t?????
push_down();
if(l==r) return l;
if(lc->ymn<t) return lc->find_pos(t);
else return rc->find_pos(t);
}
void modify(int x,int y,int t){
push_down();
if(x>r||y<l) return;
if(x<=l&&r<=y) set(t);
else{
lc->modify(x,y,t);
rc->modify(x,y,t);
push_up();
}
}
};
Node *build(int x,int y){
Node *p=new Node;
p->l=x,p->r=y;
p->set(0);
if(x==y) p->lc=p->rc=Nil;
else{
int mid=(x+y)/2;
p->lc=build(x,mid);
p->rc=build(mid+1,y);
p->push_up();
}
return p;
}
class Bucket{
public:
int a,b,c;
};
bool operator < (const Bucket &s,const Bucket &t){
return s.a<t.a;
}
Node *root;
int N;
Bucket S[SIZEN];
void add(int p,int t){
int k=root->find_pos(t);
root->modify(k,p,t);
}
void work(void){
int ans=INF;
for(int i=N;i>=0;i--){
ans=min(ans,S[i].a+root->smn);
if(i>0) add(S[i].b-1,S[i].c);
}
printf("%d\n",ans);
}
void init(void){
scanf("%d",&N);
for(int i=1;i<=N;i++){
scanf("%d%d%d",&S[i].a,&S[i].b,&S[i].c);
bval[i]=S[i].b;
}
sort(S+1,S+1+N);
sort(bval+1,bval+1+N);
for(int i=1;i<=N;i++)
S[i].b=lower_bound(bval+1,bval+1+N,S[i].b)-bval;
root=build(0,N);
}
int main(void){
freopen("playwithboss.in","r",stdin);
freopen("playwithboss.out","w",stdout);
init();
work();
return 0;
}