Bytetown City to run for mayor, all voters can speak freely to the candidate who is running for mayor. For the sake of unified management, the city Council prepared a electoral wall for voters to post posters.
The posting rules are as follows:
1. Electoral wall is a rectangular length of n units, each unit is recorded as a lattice;
2. The height of all posters must be the same as the height of the electoral wall;
3. Each poster is indicated by "a B", that is, a poster is posted from the first lattice to the B-grid;
4. The post poster can cover the poster or part of the poster that was previously posted.
Now, please judge how many posters you can see on the electoral wall after all the posters have been posted.
1 0<= N <= 10000000 1<=m<=1000 1<= Ai <= Bi <=10000000
All the data are integers. There is a space between the data
Puzzle: discrete;
This may occur, the two adjacent segments just cover the ends of a line segment, and the ends of the line segment are separated in the adjacent position, there will be a middle place and not covered points, but the calculation can not be counted in;
In this case, I'm using a T-array, t[i] to represent the color of the void between the discrete array c[i] and c[i+1];
If only the above processing will still hang, when we finally statistical answers need to determine whether c[i] and c[i+1] There is no gap between (if (c[i+1]-c[i]==1) continue;)
The problem of discretization is not how to do, a little water problem has so many pits, it is better to pay a double cycle;
( clams all Crazy spit Groove: This problem nm can be over!) a B of data water! )
#include <iostream>#include<cstring>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<ctime>using namespacestd;#defineUp (I,j,n) for (int i=j;i<=n;i++)#defineLL Long Long#definePII pair<int,int>#defineFILE "Dealing"inlineBOOLChkmin (int&x,intY) {returnX>y? (X=y,true):false;} InlineBOOLChkmax (int&x,intY) {returnX<y? (X=y,true):false;}namespaceio{Charbuf[1<< the],*fs,*ft; intGC () {return(fs==ft&& (ft= (fs=buf) +fread (buf,1,1<< the, stdin)), fs==ft))?0:* fs++;} intRead () {intx=0, CH=GC (), d=0; while(ch<'0'|| Ch>'9'){if(ch=='-') d=1; ch=GC ();} while(ch>='0'&&ch<='9') {x= (x<<1) + (x<<3) +ch-'0'; ch=GC ();} returnd?-x:x; }}using namespaceIO;namespaceoi{Const intMAXN (4010); intx[maxn],y[maxn],n,m,q[maxn<<2],tail=0; intb[20000010],F[MAXN]; BOOLb[20000010]; intC[MAXN],T[MAXN]; intans=0; voidSlove () {m=read (), n=read (); Up (I,1, N) {X[i]=read (), y[i]=read (); if(! B[x[i]]) q[++tail]=x[i],b[x[i]]=1; if(! B[y[i]]) q[++tail]=y[i],b[y[i]]=1; } sort (Q+1, q+tail+1); for(intI=1; i<=tail;i++) b[q[i]]=i; Up (I,1, N) {Up (J,b[x[i]],b[y[i]]) c[j]=i; Up (J,b[x[i]], (B[y[i]]-1)) t[j]=i; } for(intI=1; i<=tail;i++)if(!f[c[i]]&&c[i]) ans++,f[c[i]]=1; for(intI=1; i<tail;i++)if(!f[t[i]]&&t[i]&&q[i+1]-q[i]>1) ans++,f[t[i]]=1; printf ("%d\n", ans); }}intMain () {//freopen (FILE ". In", "R", stdin); //freopen (FILE ". Out", "w", stdout); using namespaceOI; Slove (); return 0;}
[haoi2014] Stickers Poster