이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
const int maxn=2000000+10;
int n,k,t,inf=1e9+5;
int all[maxn],te=0,res=0,vas[maxn],kaf=(1<<21);
pair<int,int>allq[maxn];
void fastscan(int &number)
{
register int c;
number = 0;
c = getchar();
for (; (c>47 && c<58); c=getchar())
number = number *10 + c - 48;
}
struct segment{
struct node{
int lazy;
pair<int,int>mx;
node(){
lazy=0;
mx=make_pair(0,0);
}
};
node seg[(1<<22)];
segment(){
for(int i=(1<<22)-1;i>=1;i--){
if(i>=kaf){
seg[i].mx.second=i-kaf;
}else{
seg[i].mx.second=seg[(i<<1)].mx.second;
}
}
}
inline void calc(int i){
if(i>=kaf){
seg[i].mx.first+=seg[i].lazy;
seg[i].lazy=0;
return ;
}
seg[i].mx=max(make_pair(seg[(i<<1)].lazy+seg[(i<<1)].mx.first,seg[(i<<1)].mx.second),make_pair(seg[(i<<1)^1].lazy+seg[(i<<1)^1].mx.first,seg[(i<<1)^1].mx.second));
}
inline void shift(int i){
if(i>=kaf){
return ;
}
if(seg[(i)].lazy==0){
return ;
}
seg[(i<<1)].lazy+=seg[i].lazy;
seg[(i<<1)^1].lazy+=seg[i].lazy;
seg[i].lazy=0;
return ;
}
void upd(int i,int l,int r,int tl,int tr,int w){
if(l>r||l>tr||r<tl||tl>tr){
return ;
}
if(l>=tl&&r<=tr){
seg[i].lazy+=w;
return ;
}
shift(i);
int m=(l+r)>>1;
upd((i<<1),l,m,tl,tr,w);
upd((i<<1)^1,m+1,r,tl,tr,w);
calc(i);
}
pair<int,int> pors(int i,int l,int r,int tl,int tr){
if(l>r||l>tr||r<tl||tl>tr){
return make_pair(0,-1);
}
shift(i);
calc(i);
if(l>=tl&&r<=tr){
return seg[i].mx;
}
int m=(l+r)>>1;
return max(pors((i<<1),l,m,tl,tr),pors((i<<1)^1,m+1,r,tl,tr));
}
}segmx;
void remove(int ind){
if(vas[ind]==1){
return ;
}
vas[ind]=1;
segmx.upd(1,0,kaf-1,allq[ind].first,allq[ind].second,-1);
}
struct segmentv{
vector<int>seg[(1<<22)];
char hey[(1<<22)];
void upd(int i,int l,int r,int tl,int tr,int w){
if(l>r||l>tr||r<tl||tl>tr){
return ;
}
if(l>=tl&&r<=tr){
seg[i].push_back(w);
return ;
}
int m=(l+r)>>1;
upd((i<<1),l,m,tl,tr,w);
upd((i<<1)^1,m+1,r,tl,tr,w);
return ;
}
void del(int i){
i+=kaf;
while(i>0){
if(hey[i]==0){
for(auto x:seg[i]){
remove(x);
}
hey[i]=1;
}
i>>=1;
}
}
}segv;
void vorod(){
//cin>>n>>k>>t;
fastscan(n);
fastscan(k);
fastscan(t);
for(int i=1;i<=n;i++){
//cin>>all[i];
fastscan(all[i]);
}
}
void calbaz(){
all[0]=inf;
vector<int>v;
v.push_back(0);
for(int i=1;i<=n;i++){
while((int)v.size()>0&&all[v.back()]+(i-v.back())>=all[i]){
v.pop_back();
}
while((int)v.size()>0&&all[v.back()]+(i-v.back())>t){
v.pop_back();
}
if(all[i]>t){
if((int)v.size()==0){
res++;
}else{
allq[te]=(make_pair(v.back(),i-1));
te++;
}
}
v.push_back(i);
}
}
void aval(){
for(int i=0;i<te;i++){
segmx.upd(1,0,kaf-1,allq[i].first,allq[i].second,1);
segv.upd(1,0,kaf-1,allq[i].first,allq[i].second,i);
}
}
void pre(){
calbaz();
aval();
}
void khor(){
res=n-res;
cout<<res<<"\n";
}
void cal(){
// int ind=getmx();
pair<int,int>gm=segmx.pors(1,0,kaf-1,0,n+1);
if(gm.first==0){
khor();
exit(0);
return ;
}
res+=gm.first;
segv.del(gm.second);
}
void solve(){
for(int i=0;i<k;i++){
cal();
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("inp.txt","r",stdin);
vorod();
pre();
solve();
khor();
}
컴파일 시 표준 에러 (stderr) 메시지
prison.cpp: In function 'void fastscan(int&)':
prison.cpp:12:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
12 | register int c;
| ^
# | 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... |