求助,28分stack
查看原帖
求助,28分stack
567642
waioi_lin楼主2022/9/25 23:59
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>
#include <iomanip>
#include <vector>
#include <stack>
#include <map>
#define ll long long
#define retrun return
#define ull unsigned long long
#define itn int
using namespace std;

int in(){
	char c=getchar();
	int x=0,f=1;
	for(;c<'0' || c>'9';c=getchar())
		if(c=='-') f=-1;
	for(;c>='0' && c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}

stack<int> s[7];

int main(void){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n=in(), p=in(), x, y;
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		x=in(), y=in();
		if(s[x].empty())
		{
			ans++,s[x].push(y);
			continue;
		}
		if(x==s[x].top())
			continue;
		while(!s[x].empty() && y<s[x].top())
			ans++, s[x].pop();
		if(s[x].empty())
		{
			ans++,s[x].push(y);
			continue;	
		}
		if(!s[x].empty() && y==s[x].top())
			continue;	
		if(!s[x].empty() && y>s[x].top())
			ans++, s[x].push(y);
	}
	printf("%lld\n", ans);
	return (0);
}
 
2022/9/25 23:59
加载中...