#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define ld long double
#define pb push_back
#define pf push_front
#define mod 10000007
#define se second
#define fi first
#define all(ls) (ls).begin(),(ls).end()
#define int long long
using namespace std;
using namespace __gnu_pbds;
template<typename type>using ordered_set=tree<type,null_type,less<type>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename type>using ordered_multiset=tree<type,null_type,less_equal<type>,rb_tree_tag,tree_order_statistics_node_update>;
int n,q,t=1;
const int N=2e5+10;
int x[N];
void solve(){
cin>>n>>q;
for(int i=0;i<q;i++)
cin>>x[i];
int cnt=0;
map<int,int>trk;
//trk[x[i]]=whether we are ahead of x[i] or behind
for(int i=0;i<q;i++){
if(x[i]>0 and trk[x[i]]==1){
cnt++;
trk.clear();
}
if(x[i]>0)
trk[x[i]]=1;
else
trk[-x[i]]=0;
}
cout<<cnt<<endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// cin>>t;
for(int i=1;i<=t;i++){
// cout<<"Scenario #"<<i<<":"<<" ";
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... |