-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox.cpp
More file actions
34 lines (34 loc) · 796 Bytes
/
box.cpp
File metadata and controls
34 lines (34 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<bits/stdc++.h>
using namespace std;
int mark[100005];
stack<int> st;
int main(){
int n;
scanf("%d", &n);
n *= 2;
int ans = 0;
int cur = 0;
int cont = 0;
for (int i = 0; i < n; i++) {
char rem[50];
scanf("%s", &rem);
if (rem[0] == 'a'){ //klo add
int a;
scanf("%d", &a);
st.push(a);
cont = 0; //klo add kita gabisa terus asumsi bahwa sudah sorted
}
else{
cur++;
if (!cont && st.top() != cur){ //klo ga sesuai Wengki
cont = 1; //asumsi kita sort semuanya sesuai
ans++;
}
mark[cur] = 1; //tandain dibuang
}
while(!st.empty() && mark[st.top()] == 1){ //yg ditanda dibuang beneran dibuang supaya gak ngacauin checking
st.pop(); // !st.empty() berarti stack not empty, klo kita akses stack kosong bisa RTE
}
}
printf("%d\n", ans);
}