Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

asddfasdfasd

Posted by phython at 2017-03-07 23:26:56 on Problem 1769
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
#define int long long
const int MAX = 500050;
const int INF = 1e18;
int n,m;
int L[MAX],R[MAX];
int dp[50050];
const int stsize = 50050<<2;
int stmin[stsize];
int querymin(int v,int a,int b,int l,int r)
{
	if(l <= a && r >= b) return stmin[v];
	else if(!(l >= b || a >= r))
	{
		return min(querymin(2*v+1,a,(a+b)/2,l,r),querymin(2*v+2,(a+b)/2,b,l,r));
	}
	return INF;
}
void update(int v,int a,int b,int pos,int x)
{

	if(b - a == 1) {
		//cout<<'v'<<' '<<v<<' '<<a<<' '<<b<<endl;
		stmin[v] = x; return ;
	}
	int mid = (a+b)/2;
	if(pos >= mid) update(2*v+2,mid,b,pos,x);
	else update(2*v+1,a,mid,pos,x);
	stmin[v] = min(stmin[2*v+1],stmin[2*v+2]);
}
main()
{
	fill(stmin,stmin+stsize,INF);
	scanf("%lld%lld",&n,&m);
	for(int i = 0;i < m;i++) scanf("%lld%lld",&L[i],&R[i]);
	fill(dp,dp+50050,INF);dp[1] = 0;update(0,1,n+1,1,0);
	for(int i = 0;i < m;i++)
	{
		dp[R[i]] = min(dp[R[i]],querymin(0,1,n+1,L[i],R[i]+1) + 1);
		//cout<<R[i]<<dp[R[i]]<<endl;
		update(0,1,n+1,R[i],dp[R[i]]);
	}
	cout<<dp[n]<<endl;
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator