제출 #1297670

#제출 시각아이디문제언어결과실행 시간메모리
1297670rana_azkaInfinite Race (EGOI24_infiniterace2)C++20
100 / 100
101 ms5064 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 1e18; const int MOD = 1e9+7; const int MAXN = 2e5; #define md ((lf+rg)/2) #define lc (pos*2) #define rc (pos*2+1) int n, m; bool segtree[4*MAXN+5]; int lazy[4*MAXN+5]; void mulaidarinol(){} void propagate(int lf, int rg, int pos){ if(lf > rg) return ; if(lazy[pos] == -1) return ; segtree[pos] = lazy[pos]; if(lf < rg){ lazy[lc] = lazy[rc] = lazy[pos]; } lazy[pos] = -1; } void build(int lf, int rg, int pos){ lazy[pos] = -1; if(lf == rg){ segtree[pos] = 1; return ; } build(lf, md, lc); build(md + 1, rg, rc); segtree[pos] = (segtree[lc] | segtree[rc]); } void update(int ul, int ur, bool val, int lf, int rg, int pos){ propagate(lf, rg, pos); if(rg < ul || ur < lf) return ; if(ul <= lf && rg <= ur){ lazy[pos] = val; propagate(lf, rg, pos); return ; } update(ul, ur, val, lf, md, lc); update(ul, ur, val, md + 1, rg, rc); segtree[pos] = (segtree[lc] | segtree[rc]); } bool query(int ql, int qr, int lf, int rg, int pos){ propagate(lf, rg, pos); if(rg < ql || qr < lf) return 0; if(ql <= lf && rg <= qr) return segtree[pos]; bool ret = (query(ql, qr, lf, md, lc) | query(ql, qr, md + 1, rg, rc)); return ret; } void solve(){ cin >> n; n--; build(1, n, 1); int ans = 0; cin >> m; while(m--){ int evnt; cin >> evnt; if(evnt > 0){ bool res = query(evnt, evnt, 1, n, 1); if(res == 0){ ans++; update(1, n, 1, 1, n, 1); update(evnt, evnt, 0, 1, n, 1); }else{ update(evnt, evnt, 0, 1, n, 1); } }else{ evnt = -evnt; bool res = query(evnt, evnt, 1, n, 1); if(res == 0){ update(evnt, evnt, 1, 1, n, 1); } } } cout << ans << endl; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; while(tc--){ // mulaidarinol(); solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...