题意:链接略
方法:单调栈。
解析:
好久之前做的了,不过貌似是个单调栈水题?
以前的码风比现在都不忍直视。
代码:
#include <stdio.h>
int a[1000010] ;
int z[1000010] ;
int top ;
int main()
{
int n ;
scanf("%d" , &n) ;
for(int i = 1 ; i <= n ; i++)
{
int useless ;
scanf("%d%d" , &useless , &a[i]) ;
}
int cnt = 0 ;
a[0] = 0 ;
for(int i = 1 ; i <= n+1 ; i++)
{
while(a[i] < z[top] && top > 0)
{
cnt ++ ;
top -- ;
}
while(a[i] == z[top] && top > 0)
{
top -- ;
}
z[++top] = a[i] ;
}
printf("%d\n" , cnt) ;
}