In 2222 A.D., a war took place in L country. Small Y is responsible for leading the workers to transport supplies. There is a transport plan for M materials, each of which is shaped like a li,ri. Indicates that there is a shipment of goods from Li to RI. There are n cities, and the first city is connected to the I+1 city (where City 1th and N are not connected), and it takes 1 minutes to get from city I to i+1 or from i+1 to I. Because of the high-tech presence, small y thought of a time-saving good plan. To set up a transfer station between the city of X and the Y city, so long as it does not take time to get to City y in the city of X, it does not take time to go from City y to City X. But in order to prevent chaos, only such a transmission station can be established. Now these transport options are at the same time, and Little y wants to get the shortest possible transport plan for the final destination. In the example, there are two transport schemes, namely, 1th cities to 3rd and 2nd to 4th, then we set up a transmission station in City 2nd and 3rd, so that the longest transport plan will take only 1 hours. Input
The first row of two integers n,m (1<=n,m<=500000). Next m line, two integers per line Li,ri (1<=li,ri<=n). (If Li=ri, it does not take any time)
Output
A number represents the answer.
Input example
5 21 32 4
Output example
1
Code
#pragma COMMENT (linker, "/stack:1024000000,1024000000")
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace Std;
typedef __int64 LL;
const int low (int x) {return x&-x;}
const int INF = 0x7FFFFFFF;
const INT mod = 1e9 + 7;
const int MAXN = 1e6 + 10;
int n, L[MAXN], R[MAXN], m;
BOOL Check (int d)
{
int l=-2*n,ll=-2*n;
int r=3*n,rr=3*n;
for (int i=1;i<=m;i++)
{
if (R[i]-l[i]<=d) continue;
L=max (l,l[i]+r[i]-d);
R=min (R,L[I]+R[I]+D);
Ll=max (ll,l[i]-r[i]-d);
Rr=min (RR,L[I]-R[I]+D);
}
Return l==r&&ll==rr?! (l+ll&1):l<=r&&ll<=rr;
}
int main ()
{
while (scanf ("%d%d", &n,&m)!=eof)
{
for (int i=1;i<=m;i++)
{
scanf ("%d%d", &l[i],&r[i]);
if (L[i]>r[i]) swap (l[i],r[i]);
}
int q=0, h=n;
while (Q<=H)
{
int mid=q+h>>1;
if (check (mid)) H=mid-1;else q=mid+1;
}
printf ("%d\n", Q);
}
return 0;
}
51nod ——— Cargo Transportation Problem Solving report