QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#53810 | #3272. 简单数据结构 | aglast | 20 | 7ms | 4816kb | C++ | 4.8kb | 2022-10-05 23:00:20 | 2022-10-05 23:00:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e13;
const int maxn=200025;
const int maxm=maxn*20;
int n,m,i,j,t,k,s,a[maxn],op[maxn],lef[maxn],rig[maxn];
int ord[maxn],stp[maxn],edp[maxn];
int rt[maxn],ls[maxm],rs[maxm],tot;
ll ki[maxm],bi[maxm],va[maxn];
bool hv[maxm];
inline ll up_div(ll x,ll y){return (x+y-1)/y;}
void upd(int &nrt,int ort,int l,int r,ll nk,ll nb)
{
nrt=++tot;ls[nrt]=ls[ort];rs[nrt]=rs[ort];
if (!hv[ort])
{
hv[nrt]=1;ki[nrt]=nk;bi[nrt]=nb;return;
}
ki[nrt]=ki[ort];bi[nrt]=bi[ort];hv[nrt]=hv[ort];
int mid=(l+r)>>1;
ll v0=ki[nrt]*mid+bi[nrt],v1=nk*mid+nb;
if (v0>v1) swap(ki[nrt],nk),swap(bi[nrt],nb);
if (l<r)
{
if (ki[nrt]*l+bi[nrt]>nk*l+nb)
upd(ls[nrt],ls[ort],l,mid-1,nk,nb);
else if (ki[nrt]*r+bi[nrt]>nk*r+nb)
upd(rs[nrt],rs[ort],mid+1,r,nk,nb);
}
}
ll query(int rt,int l,int r,int pl)
{
if (!hv[rt]) return INF;
if (l==r) return ki[rt]*pl+bi[rt];
int mid=(l+r)>>1;
return min(ki[rt]*pl+bi[rt],
(pl>mid?query(rs[rt],mid+1,r,pl):query(ls[rt],l,mid,pl)));
}
void erfen(int l,int r,int L,int R)
{
if (L>R){for (int i=l;i<=r;++i) stp[i]=L,edp[i]=R;return;}
if (l==r){stp[l]=L;edp[l]=R;return;}
int mid=(l+r)>>1,p=L-1;
for (int i=L;i<=R;++i)
{
ll tmp=query(rt[mid],1,n,ord[i]);
if (tmp<a[ord[i]])
{
++p;swap(ord[i],ord[p]);
}
}
erfen(l,mid,L,p);erfen(mid+1,r,p+1,R);
}
int lit[maxn<<2];
ll val[maxn<<2],sum[maxn<<2],tgk[maxn<<2],tgb[maxn<<2];
bool hvtg[maxn<<2];
inline void pushdown(int rt)
{
if (hvtg[rt])
{
hvtg[rt<<1]=hvtg[rt<<1|1]=1;hvtg[rt]=0;
tgk[rt<<1]=tgk[rt<<1|1]=tgk[rt];
tgb[rt<<1]=tgb[rt<<1|1]=tgb[rt];
sum[rt<<1]=lit[rt<<1]*tgb[rt]+tgk[rt]*val[rt<<1];
sum[rt<<1|1]=lit[rt<<1|1]*tgb[rt]+tgk[rt]*val[rt<<1|1];
tgk[rt]=tgb[rt]=0;
}
}
void updlit(int rt,int l,int r,int pl,ll vv)
{
if (l==r)
{
sum[rt]=vv;val[rt]=r;lit[rt]=1;
//printf("ohh lit %d %lld\n",pl,vv);
return;
}
pushdown(rt);int mid=(l+r)>>1;
if (pl<=mid) updlit(rt<<1,l,mid,pl,vv);
else updlit(rt<<1|1,mid+1,r,pl,vv);
sum[rt]=sum[rt<<1]+sum[rt<<1|1];
val[rt]=val[rt<<1]+val[rt<<1|1];
lit[rt]=lit[rt<<1]+lit[rt<<1|1];
}
void updtag(int rt,int l,int r,int L,int R,ll kk,ll bb)
{
if (l>=L&&r<=R)
{
hvtg[rt]=1;tgk[rt]=kk;tgb[rt]=bb;
sum[rt]=bb*lit[rt]+kk*val[rt];
return;
}
pushdown(rt);int mid=(l+r)>>1;
if (L<=mid) updtag(rt<<1,l,mid,L,R,kk,bb);
if (R>mid) updtag(rt<<1|1,mid+1,r,L,R,kk,bb);
sum[rt]=sum[rt<<1]+sum[rt<<1|1];
val[rt]=val[rt<<1]+val[rt<<1|1];
lit[rt]=lit[rt<<1]+lit[rt<<1|1];
}
ll query_hul(int rt,int l,int r,int L,int R)
{
if (l>=L&&r<=R) return sum[rt];
pushdown(rt);int mid=(l+r)>>1;
if (R<=mid) return query_hul(rt<<1,l,mid,L,R);
if (L>mid) return query_hul(rt<<1|1,mid+1,r,L,R);
return query_hul(rt<<1,l,mid,L,R)+
query_hul(rt<<1|1,mid+1,r,L,R);
}
ll tr[maxn];
inline void tradd(int x,ll y){for(;x<=n;x+=(x&(-x)))tr[x]+=y;}
inline ll trqry(int x)
{
ll ret=0;//printf("%d\n",x);
for (;x;x-=(x&(-x))) ret+=tr[x];
return ret;
}
ll vk[maxn],vb[maxn];int tp;
int main()
{
bi[0]=INF;hv[0]=0;
scanf("%d%d",&n,&m);
for (i=1;i<=n;++i) scanf("%d",&a[i]);
t=0;
for (i=1;i<=m;++i)
{
scanf("%d",&op[i]);
rt[i]=rt[i-1];
if (op[i]==1)
{
scanf("%lld",&va[i]);
upd(rt[i],rt[i-1],1,n,-t,va[i]);
}
else if (op[i]==3)
{
scanf("%d%d",&lef[i],&rig[i]);
}
else
{
++t;
}
}
for (i=1;i<=n;++i) ord[i]=i;
erfen(0,m,1,n);//printf("assdadas\n");
for (i=1;i<=n;++i)
{
tr[i]+=a[i];
if (i+(i&(-i))<=n) tr[i+(i&(-i))]+=tr[i];
}
t=0;tp=0;
/*for (i=0;i<=m;++i)
{
printf("%d ",i);
for (j=stp[i];j<=edp[i];++j) printf("%d ",ord[j]);
puts("");
}*/
for (i=1;i<=m;++i)
{
//printf("#%d\n",i);
if (op[i]==1)
{
// -t,va[i]
if (tp&&vk[tp]*n+vb[tp]<=-t*1ll*n+va[i])
continue;
if (tp&&vk[tp]==t)
{
if (vb[tp]>va[i]) --tp;
else continue;
}
while(tp)
{
if (tp==1)
{
if (vk[1]+vb[1]>va[i]-t) --tp;
break;
}
else if ((vb[tp]-vb[tp-1])*(vk[tp-1]+t)
<(va[i]-vb[tp-1])*(vk[tp-1]-vk[tp])) break;
--tp;
}
k=(!tp?1:up_div(va[i]-vb[tp],vk[tp]+t));
vb[++tp]=va[i];vk[tp]=-t;
//printf("aoaoao %d\n",k);
updtag(1,1,n,k,n,-t,va[i]);
for (j=stp[i];j<=edp[i];++j)
{
updlit(1,1,n,ord[j],va[i]-t*1ll*ord[j]);
tradd(ord[j],-a[ord[j]]);
//printf("col %d\n",ord[j]);
}
//for (j=1;j<=tp;++j)
// printf("%lld %lld\n",vk[j],vb[j]);
}
//chg stp[i-1] - > edp[i-1]
else if (op[i]==2) ++t;
else
{
//printf("asdas\n");
ll ans=trqry(rig[i])-trqry(lef[i]-1);
//printf("%lld ",ans);
ans+=query_hul(1,1,n,lef[i],rig[i]);
//printf("%lld ",ans);
ans+=1ll*(lef[i]+rig[i])*(rig[i]-lef[i]+1)/2ll*t;
printf("%lld\n",ans);
}
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 7ms
memory: 4816kb
input:
5000 5000 29940 259997 53132 912489 608312 594283 432259 344137 889466 383028 320097 337418 571199 372832 563110 542407 133378 998389 238387 120880 477310 634888 191990 133585 935315 558139 141724 893331 190118 991968 843042 384930 935256 891482 123419 91431 955722 376987 197566 106433 234494 645967...
output:
512185934 455189773 121665669 408693244 291779262 45671866 242375008 302245547 222004631 41963113 343434445 347127029 183849524 2144625 278637672 220461451 20719635 108759503 22099550 34631220 55848925 92362584 36949030 86469096 43509864 50829332 1334865 76069109 114623436 13564322 79974466 15230088...
result:
ok 1671 numbers
Test #2:
score: -10
Wrong Answer
time: 6ms
memory: 4724kb
input:
5000 5000 754848159362 799142221874 945332296572 929342054343 220343371940 207059247564 870301066785 609144766745 830351478389 198801101804 768950635554 592202774571 800496073014 730985048260 581401590014 934021096780 587980626010 77068543347 206074783770 390850923112 122794404396 281461236458 11092...
output:
23128506805 64179327088 114676811784 4852799790 -35545229926 28487092850 71982251353 18562441637 90091265591 36423991323 13132526044 -139166271992 10820066132 8362045506 62500879431 55120277621 2978114020 3584136860 -33078275153 66109700105 41993551594 -120570554832 7772926360 -51366377908 276988242...
result:
wrong answer 1st numbers differ - expected: '116508179221533', found: '23128506805'
Subtask #2:
score: 20
Accepted
Subtask #3:
score: 0
Wrong Answer
Test #1:
score: 15
Accepted
time: 3ms
memory: 4656kb
input:
5000 5000 29940 259997 53132 912489 608312 594283 432259 344137 889466 383028 320097 337418 571199 372832 563110 542407 133378 998389 238387 120880 477310 634888 191990 133585 935315 558139 141724 893331 190118 991968 843042 384930 935256 891482 123419 91431 955722 376987 197566 106433 234494 645967...
output:
512185934 455189773 121665669 408693244 291779262 45671866 242375008 302245547 222004631 41963113 343434445 347127029 183849524 2144625 278637672 220461451 20719635 108759503 22099550 34631220 55848925 92362584 36949030 86469096 43509864 50829332 1334865 76069109 114623436 13564322 79974466 15230088...
result:
ok 1671 numbers
Test #2:
score: -15
Wrong Answer
time: 5ms
memory: 4712kb
input:
5000 5000 754848159362 799142221874 945332296572 929342054343 220343371940 207059247564 870301066785 609144766745 830351478389 198801101804 768950635554 592202774571 800496073014 730985048260 581401590014 934021096780 587980626010 77068543347 206074783770 390850923112 122794404396 281461236458 11092...
output:
23128506805 64179327088 114676811784 4852799790 -35545229926 28487092850 71982251353 18562441637 90091265591 36423991323 13132526044 -139166271992 10820066132 8362045506 62500879431 55120277621 2978114020 3584136860 -33078275153 66109700105 41993551594 -120570554832 7772926360 -51366377908 276988242...
result:
wrong answer 1st numbers differ - expected: '116508179221533', found: '23128506805'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%