提出 #75916184
ソースコード 拡げる
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define VI vector<int>
#define VII vector<pii>
#define VL vector<ll>
#define VLL vector<pll>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
#define LOCAL true
using namespace std;
bool st;
const bool MUL=true;
const int MAXN=1e7+10,N=3e5+10;
struct nd{int ls,rs,c;ll s;}tr[MAXN];
int n_c,rt;
ll n,m,k,a[N],ans[N];
void clr(){rep(i,0,n_c)tr[i]={0,0,0,0};n_c=rt=0;return;}
void upd(int&p,int l,int r,int v,int d){
if(!p)p=++n_c;
tr[p].c+=d,tr[p].s+=1ll*v*d;
if(l==r)return;
int mid=(l+r)>>1;
if(v<=mid)upd(tr[p].ls,l,mid,v,d);
else upd(tr[p].rs,mid+1,r,v,d);
return;
}
int get_mn(int p,int l,int r){
if(l==r)return l;
int mid=(l+r)>>1;
if(tr[tr[p].ls].c>0)return get_mn(tr[p].ls,l,mid);
return get_mn(tr[p].rs,mid+1,r);
}
int pop_mn(int p,int l,int r){
tr[p].c--;
if(l==r){tr[p].s-=l;return l;}
int mid=(l+r)>>1,res;
if(tr[tr[p].ls].c>0)res=pop_mn(tr[p].ls,l,mid);
else res=pop_mn(tr[p].rs,mid+1,r);
tr[p].s-=res;
return res;
}
void qry(int p,int l,int r,ll rem,ll&km,ll&sm){
if(!p||rem<=0)return;
if(tr[p].s<=rem){km+=tr[p].c,sm+=tr[p].s;return;}
if(l==r){
ll tk=min((ll)tr[p].c,rem/l);
km+=tk,sm+=tk*l;
return;
}
int mid=(l+r)>>1;
if(tr[tr[p].ls].s<=rem){
ll lc=tr[tr[p].ls].c,ls=tr[tr[p].ls].s;
km+=lc,sm+=ls;
qry(tr[p].rs,mid+1,r,rem-ls,km,sm);
}else qry(tr[p].ls,l,mid,rem,km,sm);
return;
}
void solve(){
cin>>n>>m>>k;
rep(i,1,n)cin>>a[i];
ll f0=0,sd=0,cd=0,vp=0;
rep(i,1,n){
ll rem=max(0ll,k-f0),um=0;
if(sd<=rem)um=k+vp-f0+cd*m-sd;
else{
ll km=0,sm=0;
qry(rt,1,m,rem,km,sm);
um=k+vp-f0+km*m-sm;
}
ll ta=um>=m-a[i]?0:a[i];
ans[i]=ta;
ll vi=(ta-a[i])%m;
if(vi<0)vi+=m;
ll du=(vi-vp)%m;
if(du<0)du+=m;
if(du){
if(vi<vp)upd(rt,1,m,du,1),sd+=du,cd++;
else{
ll md=m;
if(cd>0)md=get_mn(rt,1,m);
if(du<=md)f0+=du;
else{
if(cd>0)pop_mn(rt,1,m),sd-=md,cd--;
f0+=md,upd(rt,1,m,du,1),sd+=du,cd++;
}
}
}
vp=vi;
}
rep(i,1,n)cout<<ans[i]<<" \n"[i==n];
return;
}
bool ed;
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int tc=1;if(MUL){cin>>tc;}while(tc--)clr(),solve();
// cerr<<"time:"<<clock()<<"ms.\n";
// cerr<<fixed<<setprecision(4)<<"memory:"<<(1.0*(&st-&ed)/1048576.0)<<"MB.\n";
return 0;
}
提出情報
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
800 / 800 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt |
| All |
00_sample_00.txt, 01_small_00.txt, 02_handmade_00.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 02_handmade_08.txt, 02_handmade_09.txt, 02_handmade_10.txt, 02_handmade_11.txt, 02_handmade_12.txt, 02_handmade_13.txt, 02_handmade_14.txt, 02_handmade_15.txt, 02_handmade_16.txt, 02_handmade_17.txt, 02_handmade_18.txt, 02_handmade_19.txt, 02_handmade_20.txt, 02_handmade_21.txt, 02_handmade_22.txt, 02_handmade_23.txt, 02_handmade_24.txt, 02_handmade_25.txt, 02_handmade_26.txt, 02_handmade_27.txt, 02_handmade_28.txt, 02_handmade_29.txt, 02_handmade_30.txt, 02_handmade_31.txt, 02_handmade_32.txt, 02_handmade_33.txt, 03_random_00.txt, 03_random_01.txt, 03_random_02.txt, 03_random_03.txt, 03_random_04.txt, 03_random_05.txt, 03_random_06.txt, 03_random_07.txt, 03_random_08.txt, 03_random_09.txt, 03_random_10.txt, 03_random_11.txt, 03_random_12.txt, 03_random_13.txt, 03_random_14.txt, 03_random_15.txt, 03_random_16.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
1 ms |
3396 KiB |
| 01_small_00.txt |
AC |
4 ms |
3504 KiB |
| 02_handmade_00.txt |
AC |
61 ms |
8140 KiB |
| 02_handmade_01.txt |
AC |
61 ms |
8284 KiB |
| 02_handmade_02.txt |
AC |
18 ms |
8284 KiB |
| 02_handmade_03.txt |
AC |
49 ms |
8256 KiB |
| 02_handmade_04.txt |
AC |
49 ms |
8140 KiB |
| 02_handmade_05.txt |
AC |
49 ms |
8140 KiB |
| 02_handmade_06.txt |
AC |
56 ms |
8140 KiB |
| 02_handmade_07.txt |
AC |
57 ms |
8140 KiB |
| 02_handmade_08.txt |
AC |
46 ms |
8204 KiB |
| 02_handmade_09.txt |
AC |
46 ms |
8256 KiB |
| 02_handmade_10.txt |
AC |
47 ms |
8128 KiB |
| 02_handmade_11.txt |
AC |
47 ms |
8128 KiB |
| 02_handmade_12.txt |
AC |
38 ms |
8140 KiB |
| 02_handmade_13.txt |
AC |
38 ms |
8144 KiB |
| 02_handmade_14.txt |
AC |
35 ms |
8128 KiB |
| 02_handmade_15.txt |
AC |
35 ms |
8144 KiB |
| 02_handmade_16.txt |
AC |
50 ms |
8156 KiB |
| 02_handmade_17.txt |
AC |
50 ms |
8284 KiB |
| 02_handmade_18.txt |
AC |
41 ms |
8128 KiB |
| 02_handmade_19.txt |
AC |
46 ms |
8148 KiB |
| 02_handmade_20.txt |
AC |
45 ms |
8104 KiB |
| 02_handmade_21.txt |
AC |
45 ms |
8148 KiB |
| 02_handmade_22.txt |
AC |
43 ms |
8132 KiB |
| 02_handmade_23.txt |
AC |
43 ms |
8128 KiB |
| 02_handmade_24.txt |
AC |
42 ms |
8148 KiB |
| 02_handmade_25.txt |
AC |
42 ms |
8140 KiB |
| 02_handmade_26.txt |
AC |
40 ms |
8128 KiB |
| 02_handmade_27.txt |
AC |
42 ms |
8128 KiB |
| 02_handmade_28.txt |
AC |
47 ms |
8144 KiB |
| 02_handmade_29.txt |
AC |
47 ms |
8284 KiB |
| 02_handmade_30.txt |
AC |
38 ms |
8168 KiB |
| 02_handmade_31.txt |
AC |
38 ms |
8128 KiB |
| 02_handmade_32.txt |
AC |
36 ms |
8196 KiB |
| 02_handmade_33.txt |
AC |
36 ms |
8204 KiB |
| 03_random_00.txt |
AC |
156 ms |
64844 KiB |
| 03_random_01.txt |
AC |
70 ms |
24384 KiB |
| 03_random_02.txt |
AC |
149 ms |
62044 KiB |
| 03_random_03.txt |
AC |
112 ms |
46904 KiB |
| 03_random_04.txt |
AC |
142 ms |
59160 KiB |
| 03_random_05.txt |
AC |
43 ms |
10184 KiB |
| 03_random_06.txt |
AC |
137 ms |
56588 KiB |
| 03_random_07.txt |
AC |
91 ms |
36236 KiB |
| 03_random_08.txt |
AC |
164 ms |
67520 KiB |
| 03_random_09.txt |
AC |
146 ms |
53688 KiB |
| 03_random_10.txt |
AC |
162 ms |
63964 KiB |
| 03_random_11.txt |
AC |
164 ms |
66132 KiB |
| 03_random_12.txt |
AC |
48 ms |
3596 KiB |
| 03_random_13.txt |
AC |
59 ms |
3524 KiB |
| 03_random_14.txt |
AC |
79 ms |
3540 KiB |
| 03_random_15.txt |
AC |
81 ms |
3724 KiB |
| 03_random_16.txt |
AC |
82 ms |
12728 KiB |