This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define iter(v) v.begin(), v.end()
#define pb emplace_back
#define ff first
#define ss second
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef zisk
void debug() { cerr << "\n"; }
template<class T, class ... U>
void debug(T a, U... b) {
cerr << a << " ", debug(b...);
}
template<class T>
void pary(T l, T r){
while (l != r) cerr << *l << " ", l++;
cerr << "\n";
}
#else
#define debug(...) void()
#define pary(...) void()
#endif
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> r(n + 1);
vector<bool> back(n + 1);
int cur = 0;
auto is_back = [&](int x) {
return r[x] == cur && back[x];
};
int q;
cin >> q;
while (q--) {
int x;
cin >> x;
if (x > 0) {
if (is_back(x)) cur++;
r[x] = cur;
back[x] = true;
}
else {
back[-x] = false;
}
}
cout << cur << "\n";
}
# | 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... |