#include <bits/stdc++.h>
#define f0r(i,n) for(int i=0;i<n;i++)
typedef long long int ll;
using namespace std;
int main() {
int n, q; cin >> n >> q;
map<int,int> idx; int mx = 0;
vector<int> cnt(n, -1), cur(n);
while (q--) {
int a; cin >> a;
if (cur[abs(a)] == 0) {
if (a > 0) cur[abs(a)] = 1;
else cur[abs(a)] = -1;
cnt[abs(a)] = max(mx, cnt[abs(a)]+1);
mx = cnt[abs(a)];
continue;
}
if (cur[abs(a)] == 1 && a > 0) {
cnt[a] = max(mx, cnt[abs(a)]+1);
mx = cnt[abs(a)];
}
if (a > 0) cur[abs(a)] = 1;
else cur[abs(a)] = -1;
}
cout << mx;
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... |