이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* 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 = 9e6+100, M = 2e6+10, K = 22;
int n, d, et, a[M], 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);
}
V[k].clear();
return;
}
for(auto id: V[k]) if(!removed[id]){
removed[id] = 1;
update(1, n - 1, P[id], id - 1, 1, -1, -1);
}
V[k].clear();
int m = l + r >> 1;
push(k);
rem(l, m, p, k<<1);
rem(m+1, r, p, k<<1|1);
}
void solve(){
cin >> n >> d >> et;
ans = n;
for(int i = 1; i <= n; ++i){
cin >> a[i];
a[i] -= i;
}
deque<int> q;
for(int i = 1; i <= n; ++i){
if(a[i] + i <= et){
P[i] = i;
q.pb(i);
}else{
while(!q.empty() && a[q.back()] + i > et){
q.pop_back();
}
if(q.empty()) P[i] = -1, --ans;
else P[i] = q.back();
}
}
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:73:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
73 | int m = l + r >> 1;
| ~~^~~
prison.cpp: In function 'int main()':
prison.cpp:121:15: warning: unused variable 'aa' [-Wunused-variable]
121 | int tt = 1, aa;
| ^~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |