Submission #1227268

#TimeUsernameProblemLanguageResultExecution timeMemory
1227268acoatoitgsInfinite Race (EGOI24_infiniterace2)C++20
100 / 100
12 ms2496 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

#define ll long long
#define pb push_back
#define m_pi 2 * acos(0.0)
#define all(a) (a).begin(), (a).end()
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
void solve();

constexpr bool isTc = 0;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    if (isTc)
    {
        int T;
        cin >> T;
        while (T--)
        {
            solve();
        }
    }
    else
        solve();
    return 0;
}

/*######################################*/

void solve()
{
    ll N, Q;
    cin >> N >> Q;  

    bitset<200005> ret;
    vector<ll> r;

    ll ans = 0;
    while(Q--)
    {
        ll x;
        cin >> x;
        if(x > 0)
        {
            if(!ret[x])
            {
                ret[x] = 1;
                r.push_back(x);
            }
            else
            {
                ans++;
                for(auto e : r) 
                {
                    if(e == x) continue;
                    ret[e] = 0;
                }
                r.clear();
                r.push_back(x);
            }
        }
        else
        {
            ret[-x] = 0;
        }

    }

    cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...