1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 #defineMAXN 2500057 using namespacestd;8 9 intN,top,stack[maxn],ans;Ten One intMain () { A intu,v; -scanf"%d",&n); -top=ans=0, memset (Stack,0,sizeof(stack)); the for(intI=1; i<=n;i++){ -scanf"%d%d",&u,&v); - while(TOP&&STACK[TOP]>V) top--; -stack[++top]=v; + if(stack[top]!=stack[top-1]) ans++; - } +printf"%d\n", ans); A return 0; at}
View Code
Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=1113
The main topic: n rectangles, lined up in a row. Now you want to cover them with as few rectangular posters as possible.
Practice: The question, the problem is obviously only related to the high, if there are two matrices of high equality, and the matrix between them is not less than their height, so that their two matrices only need to use a poster to cover.
So we can use the efficient monotone stack to maintain.
bzoj1113: [Poi2008] Poster pla