제출 #854316

#제출 시각아이디문제언어결과실행 시간메모리
854316mychecksedadThe short shank; Redemption (BOI21_prison)C++17
80 / 100
1877 ms524288 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' const int N = 8e6+100, M = 2e6+10, K = 22; int n, d, et, a[M], mn[N][K], P[M], ans = 0, T[N], lazy[N]; vector<int> V[N]; vector<bool> removed(M); void build(int l, int r, int k){ if(l == r){ T[k] = lazy[k] = 0; return; } int m = l+r>>1; build(l, m, k<<1); build(m+1, r, k<<1|1); T[k] = lazy[k] = 0; } void push(int k){ if(lazy[k] != 0){ lazy[k<<1] += lazy[k]; lazy[k<<1|1] += lazy[k]; T[k<<1] += lazy[k]; T[k<<1|1] += lazy[k]; lazy[k] = 0; } } void update(int l, int r, int ql, int qr, int k, int val, int pushed){ if(ql > r || l > qr) return; if(ql <= l && r <= qr){ T[k] += val; lazy[k] += val; if(pushed != -1) V[k].pb(pushed); return; } push(k); int m = l+r>>1; update(l, m, ql, qr, k<<1, val, pushed); update(m+1, r, ql, qr, k<<1|1, val, pushed); T[k] = max(T[k<<1], T[k<<1|1]); } pair<int, int> get_max(int l, int r, int k){ if(l == r) return {l, T[k]}; int m = l + r >> 1; push(k); if(T[k<<1] > T[k<<1|1]) return get_max(l, m, k<<1); return get_max(m + 1, r, k<<1|1); } void rem(int l, int r, int p, int k){ if(l > p || r < p) return; if(l == r){ for(auto id: V[k]) if(!removed[id]){ removed[id] = 1; update(1, n - 1, P[id], id - 1, 1, -1, -1); } return; } for(auto id: V[k]) if(!removed[id]){ removed[id] = 1; update(1, n - 1, P[id], id - 1, 1, -1, -1); } int m = l + r >> 1; push(k); rem(l, m, p, k<<1); rem(m+1, r, p, k<<1|1); } int get(int l, int r){ int k = int(log2(r-l+1)); return (a[mn[l][k]] < a[mn[r - (1<<k) + 1][k]] ? mn[l][k] : mn[r - (1 << k) + 1][k]); } void solve(){ cin >> n >> d >> et; ans = n; for(int i = 1; i <= n; ++i){ cin >> a[i]; a[i] -= i; } for(int i = 1; i <= n; ++i) mn[i][0] = i; for(int j = 1; j < K; ++j){ for(int i = 1; i + (1<<j) <= n + 1; ++i){ if(a[mn[i][j - 1]] < a[mn[i + (1<<(j - 1))][j - 1]]) mn[i][j] = mn[i][j - 1]; else mn[i][j] = mn[i + (1<<(j - 1))][j - 1]; } } for(int i = 1; i <= n; ++i){ if(a[i] + i <= et) P[i] = i; else{ int l = 1, r = i - 1; P[i] = -1; while(l <= r){ int m = l+r>>1; if(a[get(m, r)] + i <= et){ P[i] = m; l = m + 1; }else{ r = m - 1; } } // cout << i << ' ' << P[i] << '\n'; if(P[i] == -1) --ans; } } build(1, n - 1, 1); for(int i = 1; i <= n; ++i){ if(P[i] != i && P[i] != -1){ int l = P[i], r = i - 1; update(1, n - 1, l, r, 1, 1, i); } } while(d--){ pair<int, int> pos = get_max(1, n - 1, 1); ans -= pos.second; rem(1, n - 1, pos.first, 1); } cout << ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(tt--){ solve(); } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n"; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

prison.cpp: In function 'void build(int, int, int)':
prison.cpp:21:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |   int m = l+r>>1;
      |           ~^~
prison.cpp: In function 'void update(int, int, int, int, int, int, int)':
prison.cpp:44:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |   int m = l+r>>1;
      |           ~^~
prison.cpp: In function 'std::pair<int, int> get_max(int, int, int)':
prison.cpp:51:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |   int m = l + r >> 1;
      |           ~~^~~
prison.cpp: In function 'void rem(int, int, int, int)':
prison.cpp:71:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   71 |   int m = l + r >> 1;
      |           ~~^~~
prison.cpp: In function 'void solve()':
prison.cpp:103:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  103 |         int m = l+r>>1;
      |                 ~^~
prison.cpp: In function 'int main()':
prison.cpp:137:15: warning: unused variable 'aa' [-Wunused-variable]
  137 |   int tt = 1, aa;
      |               ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...