Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
asdfgsfdhgjgkjsfdhgxfdh/* 令f[i]=[1..i]最少次数 对于每一次操作[i,j] 相当于就是找出f[i,j]之间的最小值 并用这个最小值+1去更新所有f[i..j] 如果f[k]>min+1则f[k]=min+1 (k=[i..j]) */ #include<iostream> using namespace std; #define Inf 100000000 #define maxn 500005 int n,m,now; struct Node { int cover,min_data,max_data; } tree[maxn*4]; inline void Renew(int root) { tree[root].cover=(tree[root*2].cover==tree[root*2+1].cover)?tree[root*2].cover:-1; tree[root].min_data=min(tree[root*2].min_data,tree[root*2+1].min_data); tree[root].max_data=max(tree[root*2].max_data,tree[root*2+1].max_data); } inline void Pass(int root) { tree[root*2].cover=tree[root*2].min_data=tree[root*2].max_data=tree[root].cover; tree[root*2+1].cover=tree[root*2+1].min_data=tree[root*2+1].max_data=tree[root].cover; } inline void Build(int root,int l,int r) { if (l==r) { tree[root].cover=tree[root].min_data=tree[root].max_data=Inf; return; } int m=(l+r)/2; Build(root*2,l,m); Build(root*2+1,m+1,r); Renew(root); } inline int Query(int root,int l,int r,int i,int j) { if (tree[root].cover>-1) Pass(root); if (l==i && r==j) return tree[root].min_data; int m=(l+r)/2; if (j<=m) return Query(root*2,l,m,i,j); if (m<i) return Query(root*2+1,m+1,r,i,j); return min(Query(root*2,l,m,i,m),Query(root*2+1,m+1,r,m+1,j)); } inline void Modify(int root,int l,int r,int i,int j) { if (tree[root].cover>-1) Pass(root); if (tree[root].max_data<=now) return; if (l==i && r==j && tree[root].min_data>=now) { tree[root].cover=tree[root].min_data=tree[root].max_data=now; return; } int m=(l+r)/2; if (j<=m) Modify(root*2,l,m,i,j); else if (m<i) Modify(root*2+1,m+1,r,i,j); else Modify(root*2,l,m,i,m),Modify(root*2+1,m+1,r,m+1,j); Renew(root); } int main() { int i,j; scanf("%d%d",&n,&m); Build(1,1,n); now=0,Modify(1,1,n,1,1); while (m--) { scanf("%d%d",&i,&j); now=Query(1,1,n,i,j)+1; Modify(1,1,n,i,j); } printf("%d\n",Query(1,1,n,n,n)); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator