记录详情
#include<bits/stdc++.h>
using namespace std;
stack<long long>s1,s2,s3,s4,s5,s6;
int main()
{
int n,p;
cin>>n>>p;
long long ans=0;
s1.push(0);s2.push(0);s3.push(0);s4.push(0);s5.push(0);s6.push(0);
for(int i=1;i<=n;i++)
{
int a,b;
cin>>a>>b;
if(a==1)
{
while(s1.top()>b)
{
s1.pop();
ans++;
}
if(s1.top()<b)
{
s1.push(b);
ans++;
}
continue;
}
else if(a==2)
{
while(s2.top()>b)
{
s1.pop();
ans++;
}
if(s2.top()<b)
{
s2.push(b);
ans++;
}
continue;
}
else if(a==3)
{
while(s3.top()>b)
{
s3.pop();
ans++;
}
if(s3.top()<b)
{
s3.push(b);
ans++;
}
continue;
}
else if(a==4)
{
while(s4.top()>b)
{
s4.pop();
ans++;
}
if(s4.top()<b)
{
s4.push(b);
ans++;
}
continue;
}
else if(a==5)
{
while(s5.top()>b)
{
s5.pop();
ans++;
}
if(s5.top()<b)
{
s5.push(b);
ans++;
}
continue;
}
else if(a==6)
{
while(s6.top()>b)
{
s6.pop();
ans++;
}
if(s6.top()<b)
{
s6.push(b);
ans++;
}
}
}
cout<<ans;
return 0;
}