https://ac.nowcoder.com/acm/contest/57358/L
模拟题
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct node{
int num;
int k;
};
int book[2000005];
int main(){
ll n,m,q;
cin>>n>>m>>q;
stack<node> st1,st2;
ll ans=0;
while(q--){
string s1,s2;
int x;
cin>>s1>>x>>s2;
if(s1=="row"){
if(s2=="on"){
node temp;
temp.num=x;
temp.k=1;
st1.push(temp);
}
else{
node temp;
temp.num=x;
temp.k=0;
st1.push(temp);
}
}
else{
if(s2=="on"){
node temp;
temp.num=x+1000000;
temp.k=1;
st1.push(temp);
}
else{
node temp;
temp.num=x+1000000;
temp.k=0;
st1.push(temp);
}
}
}
while(!st1.empty()){
if(book[st1.top().num]==0){
st2.push(st1.top());
book[st1.top().num]=1;
}
st1.pop();
}
ll r=0,c=0;
while(!st2.empty()){
node mid=st2.top();
if(mid.k==1){
if(mid.num<=1000000){
ans=ans+(m-c);
r++;
}else{
ans=ans+(n-r);
c++;
}
}else{
if(mid.num<=1000000){
if(c>0){
ans=ans-c;
}
}else{
if(r>0){
ans=ans-r;
}
}
}
st2.pop();
}
cout<<ans<<endl;
}