Submission #1342713

#TimeUsernameProblemLanguageResultExecution timeMemory
1342713iamhereforfunMoney (IZhO17_money)C++20
100 / 100
750 ms63064 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))

const int N = 1e6 + 5;
const int M = 1e6 + 5;
const int K = 20;
const int LG = 20;
const long long INF = 1e18 + 5;
const int C = 26;
const int B = 1000;
const int MOD = 998244353;

int n, a[N], b[N], cnt[N], cur[N], ans, pos, nxt[N];
set<int> st;

inline void solve()
{
    cin >> n;
    ans = 0;
    pos = 0;
    for (int x = 1; x <= n; x++)
    {
        cin >> a[x];
        b[x] = a[x];
    }
    sort(b + 1, b + 1 + n);
    for (int x = 2; x <= n; x++)
    {
        if (b[x] != b[x - 1])
        {
            nxt[b[x - 1]] = b[x];
        }
    }
    while (pos < n)
    {
        int last = 0, c = 0;
        vector<int> v;
        for (int z = pos + 1; z <= n; z++)
        {
            if (last == a[z])
            {
                v.push_back(a[z]);
            }
            else if (last > a[z])
            {
                break;
            }
            else
            {
                c++;
                if (c > 1)
                {
                    if (st.upper_bound(last) != st.end() && *st.upper_bound(last) < a[z])
                        break;
                }
                if (c > 2)
                {
                    if (cnt[last] && last != 0) // yea
                        break;
                }
                v.push_back(a[z]);
            }
            pos = z;
            last = a[z];
        }
        for (int i : v)
        {
            st.insert(i);
            cnt[i]++;
        }
        ans++;
    }
    cout << ans << "\n";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...