Submission #1317489

#TimeUsernameProblemLanguageResultExecution timeMemory
1317489haithamcoderInfinite Race (EGOI24_infiniterace2)C++20
100 / 100
16 ms3528 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll LOG = 31;
const ll MOD = 1000000007;
const ll inf = 1e17;
const ll B = 2305843009213693951;


#define db(x) cerr << #x << " = " << x << " | "
#define dbg(x) cerr << #x << " = " << x << "\n"

#define Algerian ios::sync_with_stdio(0);
#define OI cin.tie(NULL);


int main() {
    Algerian OI

    ll n, q;
    cin >> n >> q;
    vector<ll> a(q);
    for (ll& x : a) cin >> x;

    ll r = 0, reset = 0;
    vector<ll> last(n, -2);
    for (ll i = 0; i < q; i++) {
        if (a[i] < 0) {
            last[-a[i]] = -1;
        } else {
            if (last[a[i]] >= reset) {
                r++;
                reset = i;
                last[a[i]] = i;
            } else {
                last[a[i]] = i;
            }
        }
    }

    cout << r << "\n";
    
    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...