#include <iostream>
#include <vector>
#include <cstdlib> // abs
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, Q;
if (!(cin >> N >> Q)) return 0;
vector<long long> lastOver(N, -1); // epoch of last "+p"
long long laps = 0; // also the current epoch id
while (Q--) {
int x; cin >> x;
int p = std::abs(x); // 1 … N-1
if (x > 0) { // "+p" – Anika overtakes p
if (lastOver[p] == laps) { // already did that this epoch → need lap
++laps; // new epoch starts *before* this event
}
lastOver[p] = laps; // mark that p has been passed in epoch
}
else { // "-p" – p overtakes Anika
lastOver[p] = -1; // reset: p is in front again
}
}
cout << laps << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |