#include<bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define int long long
const int N = 2e5+5;
const int mod = 1e9 + 7;
const int mod1 = 998244353;
const int LG = 20;
// #define s(i) (*s.find_by_order(i)) // Warning : Read this line.
int power(int b,int e){
if(e<=0)return 1;
int o = power(b,e>>1);
o *= o, o %= mod1;
if(e % 2)o *= b, o %= mod1;
return o;
}
void solve(){
int n;cin >> n;
int q;cin >> q;
vector<int> ev(q + 1);
for(int i= 1 ; i <= q ; i ++)cin >> ev[i];
set<int> s;
int ans = 0;
int len = 0;
for(int i = 1 ; i <= q ; i ++){
if(ev[i] < 0){
if(s.find(-ev[i]) != s.end()){
s.erase(-ev[i]);
len --;
}
}
else{
if(s.find(ev[i])!=s.end()){
ans ++;
s.clear();
len = 1;s.insert(ev[i]);
}
else{
s.insert(ev[i]);
len ++;
}
}
}
cout << ans << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int t = 1;
// cin >> t;
while(t --){
solve();
}
}
# | 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... |