// #include<bits/allocator.h>
// #pragma GCC optimize("Ofast,unroll-loops")
// #ifdef ONLINE_JUDGE
// #pragma GCC target("avx2,fma,bmi,bmi2,popcnt,lzcnt,tune=native")
// #endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
// VVI
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define ll long long
#define SZ(a) (ll)a.size()
#define UNIQUE(a) (a).erase(unique(all(a)), (a).end())
#define mp make_pair
#define mem(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
//Printings & debugging
#define nn '\n'
#define Setpre(n) cout << fixed << setprecision(n)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define debug printf("I am here\n")
// CONSTANTS
#define md 10000007
#define PI acos(-1)
const long double EPS = 1e-9;
const ll N = 2e5 + 10;
const ll M = 1e9 + 7;
/// INLINE FUNCTIONS
inline ll GCD(ll a, ll b) { return b == 0 ? a : GCD(b, a % b); }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline long double logb(ll base, ll num) { return ( long double )log(num) / ( long double )log(base); }
/// Data structures
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using QP = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename R>
using ordered_map = tree<T, R, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename R>
using ordered_multimap = tree<T, R, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
namespace io{
template<typename First, typename Second> ostream& operator << ( ostream &os, const pair<First, Second> &p ) { return os << p.first << " " << p.second; }
template<typename First, typename Second> ostream& operator << ( ostream &os, const map<First, Second> &mp ) { for( auto it : mp ) { os << it << endl; } return os; }
template<typename First> ostream& operator << ( ostream &os, const vector<First> &v ) { bool space = false; for( First x : v ) { if( space ) os << " "; space = true; os << x; } return os; }
template<typename First> ostream& operator << ( ostream &os, const set<First> &st ) { bool space = false; for( First x : st ) { if( space ) os << " "; space = true; os << x; } return os; }
template<typename First> ostream& operator << ( ostream &os, const multiset<First> &st ) { bool space = false; for( First x : st ) { if( space ) os << " "; space = true; os << x; } return os; }
template<typename First, typename Second> istream& operator >> ( istream &is, pair<First, Second> &p ) { return is >> p.first >> p.second; }
template<typename First> istream& operator >> ( istream &is, vector<First> &v ) { for( First &x : v ) { is >> x; } return is; }
long long fastread(){ char c; long long d = 1, x = 0; do c = getchar(); while( c == ' ' || c == '\n' ); if( c == '-' ) c = getchar(), d = -1; while( isdigit( c ) ){ x = x * 10 + c - '0'; c = getchar(); } return d * x; }
static bool sep = false;
using std::to_string;
string to_string( bool x ){ return ( x ? "true" : "false" ); }
string to_string( const string & s ){ return "\"" + s + "\""; }
string to_string( const char * s ){ return "\"" + string( s ) + "\""; }
string to_string ( const char & c ) { string s; s += c; return "\'" + s + "\'"; }
template<typename Type> string to_string( vector<Type> );
template<typename First, typename Second> string to_string( pair<First, Second> );
template<typename Collection> string to_string( Collection );
template<typename First, typename Second> string to_string( pair<First, Second> p ){ return "{" + to_string( p.first ) + ", " + to_string( p.second ) + "}"; }
template<typename Type> string to_string( vector<Type> v ) { bool sep = false; string s = "["; for( Type x: v ){ if( sep ) s += ", "; sep = true; s += to_string( x ); } s += "]"; return s; }
template<typename Collection> string to_string( Collection collection ) { bool sep = false; string s = "{"; for( auto x: collection ){ if( sep ) s += ", "; sep = true; s += to_string( x ); } s += "}"; return s; }
void print() { cerr << endl; sep = false; }
template <typename First, typename... Other> void print( First first, Other... other ) { if( sep ) cerr << " | "; sep = true; cerr << to_string( first ); print( other... ); }
} using namespace io;
const ll INF=1e15+500;
// ll mul(ll x) {return x==0 ? 1 : mul(x-1)*10;}
const ll MAXN=3e5+100;
const ll MOD=1e9+7;
#define p(i,n) for(ll i=0; i<n; i++)
#define rp(i,n) for(ll i=n-1; i>=0; i--)
#define grid_ll vector<vector<ll>>
#define grid_char vector<vector<char>>
void ADD(ll& c,ll a, ll b, ll m) {c = ((a % m) + (b % m)) % m;return;}
void MUL(ll& c,ll a, ll b, ll m) {c = ((a % m) * (b % m)) % m;}
void SUB(ll& c,ll a, ll b, ll m) {c = ((a % m) - (b % m) + m) % m;}
void MIN(ll& a, ll b) {a = min(a, b);}
void MAX(ll& a, ll b) {a = max(a, b);}
ll gcdExtended(ll a, ll b, ll *x, ll *y);
ll modInverse(ll b, ll m){ll x,y;ll g = gcdExtended(b, m, &x, &y);if (g != 1)return -1;return (x%m + m) % m;}
ll modDivide(ll a, ll b, ll m){a = a % m;ll inv = modInverse(b, m);return (inv * a) % m;}
ll gcdExtended(ll a, ll b, ll *x, ll *y){if (a == 0){*x = 0, *y = 1;return b;}ll x1, y1;ll gcd = gcdExtended(b%a, a, &x1, &y1);*x = y1 - (b/a) * x1;*y = x1;return gcd;}
#define f first
#define s second
// struct segtree{
// vector<pll> tree;
// ll n;
// segtree(ll t){
// n=t;
// tree.resize(4*t,mp(-INF,-1));
// build(1,0,n-1);
// }
// void build (ll node, ll lo, ll hi){
// if( lo==hi) {
// tree[node]=mp(v[lo],lo);
// return;
// }
// ll mid=(lo+hi)/2;
// build(2*node,lo,mid); build(2*node+1,mid+1,hi);
// if (tree[2*node].f>=tree[2*node+1].f) tree[node]=tree[2*node];
// else tree[node]=tree[2*node+1];
// }
// void update(ll node, ll lo, ll hi, ll idx, ll val){
// if (lo==hi){
// tree[node].f=val;
// v[lo]=val; return;
// }
// ll mid=(lo+hi)/2;
// if (idx<=mid) update(2*node,lo,mid,idx,val);
// else update(2*node+1,mid+1,hi,idx,val);
// if (tree[2*node].f>=tree[2*node+1].f) tree[node]=tree[2*node];
// else tree[node]=tree[2*node+1];
// }
// ll query(ll node, ll lo,ll hi, ll l,ll r){
// if (lo>r or l>hi) return -INF;
// if (lo>=l and hi<=r) return tree[node].f;
// ll mid=(lo+hi)/2;
// ll a=query(2*node,lo,mid,l,r);
// ll b=query(2*node+1,mid+1,hi,l,r);
// return max(a,b);
// }
// ll show(){return tree[1].f;}
// void dbg(){cout<<tree<<nn;}
// };
// struct segtree{
// vector<pll> tree;
// ll n;
// segtree(ll t){
// n=t;
// tree.resize(4*t,mp(-INF,-1));
// build(1,0,n-1);
// }
// void build (ll node, ll lo, ll hi){
// if( lo==hi) {
// if (v[lo]==1) tree[node]=mp(1,0);
// else tree[node]=mp(0,1);
// return;
// }
// ll mid=(lo+hi)/2;
// build(2*node,lo,mid); build(2*node+1,mid+1,hi);
// tree[node].f=tree[2*node].f+max(0LL,tree[2*node+1].f-tree[2*node].s);
// tree[node].s=tree[2*node+1].s+max(0LL,tree[2*node].s-tree[2*node+1].f);
// }
// void update(ll node, ll lo, ll hi, ll idx, ll val){
// if (lo==hi){
// tree[node].f+=1;
// tree[node].s+=1;
// tree[node].f%=2;
// tree[node].s%=2;
// return;
// }
// ll mid=(lo+hi)/2;
// if (idx<=mid) update(2*node,lo,mid,idx,val);
// else update(2*node+1,mid+1,hi,idx,val);
// tree[node].f=tree[2*node].f+max(0LL,tree[2*node+1].f-tree[2*node].s);
// tree[node].s=tree[2*node+1].s+max(0LL,tree[2*node].s-tree[2*node+1].f);
// }
// pll query(ll node, ll lo,ll hi, ll l,ll r){
// if (lo>r or l>hi) return {0,0};
// if (lo>=l and hi<=r) return tree[node];
// ll mid=(lo+hi)/2;
// pll a=query(2*node,lo,mid,l,r);
// pll b=query(2*node+1,mid+1,hi,l,r);
// return mp(a.f+max(0LL,b.f-a.s),b.s+max(0LL,a.s-b.f));
// }
// ll show(){return tree[1].f;}
// void dbg(){cout<<tree<<nn;}
// };
// struct segtree {
// vector<ll> tree;
// ll n;
// segtree(ll t) {
// n = t;
// tree.resize(4 * t, 0);
// build(1, 0, n - 1);
// }
// void build(ll node, ll lo, ll hi) {
// if (lo == hi) {
// tree[node] = v[lo];
// return;
// }
// ll mid = (lo + hi) / 2;
// build(2 * node, lo, mid);
// build(2 * node + 1, mid + 1, hi);
// tree[node] = tree[2 * node] + tree[2 * node + 1];
// }
// void update(ll node, ll lo, ll hi, ll idx, ll val) {
// if (lo == hi) {
// tree[node] = val;
// return;
// }
// ll mid = (lo + hi) / 2;
// if (idx <= mid) {
// update(2 * node, lo, mid, idx, val);
// } else {
// update(2 * node + 1, mid + 1, hi, idx, val);
// }
// tree[node] = tree[2 * node] + tree[2 * node + 1];
// }
// ll query(ll node, ll lo, ll hi, ll l, ll r) {
// if (lo > r || hi < l) return 0;
// if (lo >= l && hi <= r) return tree[node];
// ll mid = (lo + hi) / 2;
// ll left_sum = query(2 * node, lo, mid, l, r);
// ll right_sum = query(2 * node + 1, mid + 1, hi, l, r);
// return left_sum + right_sum;
// }
// ll show() { return tree[1]; }
// void dbg() {
// for (ll i = 1; i < 4 * n; ++i) {
// cout << "Node " << i << ": " << tree[i] << "\n";
// }
// }
// };
// struct dsu{
// vector<ll> par;
// ll n;
// dsu (ll t){par.resize(t);n=t;}
// void build(){
// for(ll i=0; i<n; i++) par[i]=i;
// }
// ll find(ll node){
// if (par[node]!=node) par[node]=find(par[node]);
// return par[node];
// }
// void unite(ll node, ll node2){
// ll r1=find(node); ll r2=find(node2);
// if (rand()%2){
// par[r1]=r2;
// }
// else par[r2]=r1;
// }
// };
int lim;
inline bool mo_cmp(const pair< pair<ll, ll>, ll> &x,
const pair< pair<ll, ll>, ll> &y)
{
ll block_x = x.first.first / lim;
ll block_y = y.first.first / lim;
if(block_x != block_y)
return block_x < block_y;
return x.first.second < y.first.second;
}
vector<vector<int >> dp; vector<int> v;
void solve_small(int a, int l , int d, int n){
dp[a][d]++;
if (a+l*d<=n) dp[a+l*d][d]--;
}
void solve_large(int a,int l,int d, int n){
for(int i=a; i<=a+(l-1)*d; i+=d){
v[i-1]++;
}
}
void get_ans(int n){
for(int i=1; i<lim; i++){
for(int j=1; j<=n; j++){
if(j-i<0) {
v[j-1]+=dp[j][i]; continue;
}
dp[j][i]+=dp[j-i][i];
v[j-1]+=dp[j][i];
}
}
cout<<v<<nn;
}
signed main(){
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt" , "w" , stdout);
// #endif
fast
ll n,q; cin>>n>>q;
vector<ll> v(n,0LL);
ll mx=0LL;
ll ans=0; vector<ll> flag(n,0LL); vector<ll> overtakes(n,0LL);
ll last=1;
for(ll i=0; i<q; i++){
ll a; cin>>a;
if (a>0){
if (v[a]>=last){
ans++; last=i+1;
}
v[a]=i+1;
}
else{
v[-a]=0;
}
}
cout<<ans<<nn;
}
# | 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... |