#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
using namespace std;
int main() {
int n, q; cin >> n >> q;
int query, ans = 0;
unordered_set<int> behind, infront;
for (int i=1;i<n;i++) {
infront.insert(i);
}
for (int i=0;i<q;i++) {
cin >> query;
if (query < 0) {
query = -query;
if (behind.find(query) != behind.end()) {
behind.erase(query);
infront.insert(query);
}
} else {
if (behind.find(query) != behind.end()) {
for (int j: behind) {
if (j == query) continue;
infront.insert(j);
}
behind.clear();
behind.insert(query);
ans += 1;
} else {
infront.erase(query);
behind.insert(query);
}
}
}
cout << ans;
}
# | 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... |