#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
set<int> behind;
int cnt = 0;
for (int i = 0; i < q; ++i) {
int x;
cin >> x;
int id = abs(x);
if (x > 0) {
// Anika overtakes id
if (behind.count(id)) {
// Already behind → must be a lap
cnt++;
} else {
// First time putting this guy behind
behind.insert(id);
}
} else {
// Someone overtakes Anika → they are ahead now
behind.erase(id);
}
}
cout << cnt << '\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... |