QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408028 | #8286. Stacks | light_ink_dots# | WA | 6ms | 16624kb | C++20 | 3.1kb | 2024-05-09 16:17:21 | 2024-05-09 16:17:22 |
Judging History
answer
#include<bits/stdc++.h>
#define lc(x) (x<<1)
#define rc(x) (x<<1|1)
#define mid (l+r>>1)
using namespace std;
const int maxn=100005,maxt=maxn<<2;
int n,m;
int qx[maxn],qy[maxn],qo[maxn];
long long tmp,res,tmpL,tmpR;
long long qa[maxn],qb[maxn],ans[maxn],sum[maxt],tot[maxt],eat[maxt],rec[maxt];
vector<int>o[maxn],q[maxn];
long long query(int l,int r,int now,long long k){
if(k<=0)
return 0;
if(tot[now]<=k)
return sum[now];
if(l==r)
return k*qy[l];
if(tot[rc(now)]>=k)
return query(mid+1,r,rc(now),k);
return query(l,mid,lc(now),k-tot[rc(now)]+eat[rc(now)])+sum[rc(now)];
}
long long querytot(int l,int r,int now,int R){
long long res=0;
if(r<=R){
if(tmp>=tot[now])
res=0,tmp-=tot[now],tmp+=eat[now];
else res=tot[now]-tmp,tmp=eat[now];
return res;
}
if(mid<R)
res+=querytot(mid+1,r,rc(now),R);
res+=querytot(l,mid,lc(now),R);
return res;
}
void pushup(int l,int r,int now){
rec[now]=query(l,mid,lc(now),eat[rc(now)]),sum[now]=sum[lc(now)]+sum[rc(now)]-rec[now];
if(eat[rc(now)]>=tot[lc(now)])
eat[now]=eat[rc(now)]-tot[lc(now)]+eat[lc(now)],tot[now]=tot[rc(now)];
else eat[now]=eat[lc(now)],tot[now]=tot[lc(now)]-eat[rc(now)]+tot[rc(now)];
}
void modify(int l,int r,int now,int p,int op){
if(l==r){
if(op==1){
if(qo[p]==1)
eat[now]=0,tot[now]=qx[p],sum[now]=1ll*qx[p]*qy[p];
else eat[now]=qa[p],tot[now]=0,sum[now]=0;
}
else eat[now]=tot[now]=sum[now]=0;
return ;
}
if(p<=mid)
modify(l,mid,lc(now),p,op);
else modify(mid+1,r,rc(now),p,op);
pushup(l,r,now);
}
void find(int l,int r,int now,int R){
// if(now==1)
// printf(" R=%d tmp=%lld\n",R,tmp);
if(tmpR==0)
return ;
if(r<=R){
// printf("now=%d {%lld,%lld}\n",now,tot[now],eat[now]);
if(tmpL>=tot[now]){
tmpL-=tot[now],tmpL+=eat[now];
// printf("delete [%d,%d] noweq{%lld,%lld}\n",l,r,tmpL,tmpR);
return ;
}
if(tmpL+tmpR>=tot[now]){
// printf("have [%d,%d] - %lld\n",l,r,tmpL);
res+=sum[now]-query(l,r,now,tmpL),tmpR-=tot[now]-tmpL,tmpL=eat[now];
return ;
}
if(l==r){
// printf("solve pos=%d %lld,%lld\n",tmpL,tmpR);
res+=tmpR*qy[l],tmpL=tmpR=0;
return ;
}
}
if(mid<R)
find(mid+1,r,rc(now),R);
find(l,mid,lc(now),R);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1,l,r;i<=m;i++){
scanf("%d",&qo[i]);
if(qo[i]==1)
scanf("%d%d%d%d",&l,&r,&qx[i],&qy[i]),o[l].emplace_back(i),o[r+1].emplace_back(-i);
if(qo[i]==2)
scanf("%d%d%lld",&l,&r,&qa[i]),o[l].emplace_back(i),o[r+1].emplace_back(-i);
if(qo[i]==3)
scanf("%d%lld%lld",&l,&qa[i],&qb[i]),q[l].emplace_back(i);
}
for(int i=1;i<=n;i++){
for(int j=0;j<o[i].size();j++){
int k=o[i][j];
if(k>0)
modify(1,m,1,k,1);
else modify(1,m,1,-k,-1);
}
for(int j=0;j<q[i].size();j++){
int k=q[i][j];
tmp=0;
long long s=querytot(1,m,1,k);
// printf("k=%d s=%lld\n",k,s);
if(qa[k]>s)
continue;
tmpL=max(s-qb[k],0ll),tmpR=s-qa[k]+1-tmpL;
// printf("L=%lld R=%lld\n",tmpL,tmpR);
res=0,find(1,m,1,k),ans[k]=res;
// printf("res=%lld\n",res);
}
}
for(int i=1;i<=m;i++)
if(qo[i]==3)
printf("%lld\n",ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 16624kb
input:
4907 4910 2 763 3330 1 3 307 1 1 1 2262 3430 22699 89397 1 1915 4000 51541 67587 2 212 2990 9763 2 1086 2162 1 2 1813 4496 16760 1 51 2796 68005 99390 1 1267 1519 74236 66178 3 1768 23808 54314 2 900 4122 27758 3 3287 17350 28989 2 3277 4024 3633 2 444 4866 1 2 353 4219 1061 1 987 3141 99906 17320 2...
output:
0 3032090730 903396180 471569175 200648623 98486697 647114751 123945 50793012 61782451 0 0 0 762429740 321140700 871619914 536311874 5361094892 0 1792521566 6640518748 2415375780 249435711 225987900 5250788038 -5648213223 140071334 0 118545795 3086405469 5646099271 84280112 1232466642 4992966775 796...
result:
wrong answer 26th numbers differ - expected: '1145132507', found: '-5648213223'