# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1136197 | monaxia | Po (COCI21_po) | C++20 | 6 ms | 840 KiB |
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fr first
#define sc second
#define all(v) v.begin(), v.end()
#define mod (long long)(1e9 + 7)
#define eps (long long)(1e-9)
#define vektor vector
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ull Mod = 1e9 + 7;
const ll LIMIT = 2e5;
void solve(){
int n, ans = 0;
cin >> n;
stack <int> s;
vector <int> a(n + 1);
for(int i = 1; i <= n; i ++) cin >> a[i];
for(int i = 1; i <= n; i ++){
if(!a[i]) {
ans += s.size();
while(!s.empty()) s.pop();
continue;
}
if(i > 1 && a[i] == a[i - 1]) continue;
while(!s.empty() && s.top() > a[i]){
ans ++;
s.pop();
}
if(!s.empty() && s.top() == a[i]){
ans ++;
s.pop();
}
else s.push(a[i]);
}
ans += s.size();
cout << ans;
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
// if(fopen("nameholder.inp", "r")){
// freopen("nameholder.inp", "r", stdin);
// freopen("nameholder.out", "w", stdout);
// }
// cout << 1; return 0;
ll n = 1;
// cin >> n;
while(n) {
solve();
n --;
cout << "\n";
}
// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
return 0;
}
// ++++
// ++++-::......:--:::-=+++
// ++++=:............---.....--:..:=++++++
// +++++++::......................::=+++++
// @@ ++++++++++:+++++++++
// @% @*
// %%@@ *****#*@@
// %%%%% @##**##***%
// @@@@@@+-*#*@ #####%+*##*@
// %#+@%%@@@ ##-%:::-#*###@@
// =====:*::: ###-:==::=#*%*
// -====:::::+@@%@@%@#*--=*#%%#@%@ @%@
// @=====%=-@%=:::.:+-::::+::::::::::::%-----%% @@@@@
// @@%#*@++%===+::-================@%@@@@+++++++@@@%%%@#%###%
// @#***#@@ @##=%@===+--:+==+===+%*##@%%%@@@@@@@@@@:= @%@%%%@#%%
// -@ @*#@ #####%:::-====+:::==---**%#@ *%%%%@@@@@@-:
// -=-*% # #***--%%::::::::+=-+#-----=**@*# #+**#@#
// ----=----#+****=----=*#@=::::::=#-----------***%*%
// ------------%*****##=@==::::::+%-----------***%**
// +-----------------*@++%::::::::-----------****@*#
// =------------% @%=+%#+:::::::* #-----*--**** **
// ----%--% *==+++++=+=##*:% ---=--**** **
// %@@@@@@@@@==@+%%%%@ ----**** *#
// @=*+%@@@%@@=++=:%:::% #***@@#
// #+++++++++#==++-:::::: @**** *#
// =+++++++++++==+++::::::: ####@ #%
// +++++++++++=@ @++++::::::@ @#
// @+++++++++=@ =*++=:::::@
// ++++++++@ @++++:::::
// ++++++= =++++:::
// =+++++@ =+++::::
// ++++++-@ =+++:+::
// @::+::::@ =++::-:::
// +::=::::: @+*+:-+++-:
// @::+-:::::# +++::::::@
// ::%=:::::::%@ @%++::::***
// @:+@*:::::::****@ +@+++:-=*:*@
// *:@@%::::::::=**** @%@+++:::#**@
// *%@@@-:::::::%=+==*@ +@%+++:***+*
// #%@@%%::::::::#+=-=# =+@+++++:::*+
// @####+::::::::%+=@#%#=@ @**@@%=++::::@
// @ +:::::::::***#*@ @@###+=+=%@ +**#+=+*+:::-
// =-:::::::%%%%@@ @#=*########%#+*%%+--@*+::%
// +---%@ @@ =-:-**:#
// %%%%% @+--*@
// @%%%%@ @%%%%%
// @%%@@
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |