#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);bool f = false;
for(int i = 1 ; i <= q ; i ++)cin >> ev[i], f|=(ev[i] < 0);
if(!f){
int l = 0;
set<int> s;
int e = 0;
for(int i = 1 ; i <= q ; i ++){
s.insert(ev[i]);
if(i-l>s.size()){
e ++;
l = i-1;
s.clear();
s.insert(ev[i]);
}
}
cout << e << '\n';return;
}
vector<int> pr(n + 1);
vector<int> Ans(n + 1);
for(int i = 1 ; i < n ; i ++)pr[i] = 1;
for(int i = 1 ; i <= q ; i ++){
int o = ev[i];
if(o < 0){
pr[-o] = 1;
}
else{
if(!pr[o])
Ans[o] ++;
pr[o]=0;
}
}
int ans = 0;
for(int i = 0 ; i < n ; i ++)ans=max(ans,Ans[i]);
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... |