QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#335324 | #8229. 栈 | Konvex | 0 | 363ms | 269212kb | C++14 | 4.1kb | 2024-02-23 09:33:26 | 2024-02-23 09:33:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const double alpha=0.25,beta=(1-alpha*2)/(1-alpha);
#define N 100010
namespace WBLT{
struct data{
ll sz,sum;
};
data operator+(data a,data b){
return (data){a.sz+b.sz,a.sum+b.sum};
}
struct node{
int ch[2],ncnt;
data d;
}d[15000000];
int dcnt=1;
int newnode(int ncnt,data z){
assert(ncnt<150000000);
int x=dcnt++;d[x].d=z;d[x].ncnt=ncnt;
return x;
}
#define lc(x) d[x].ch[0]
#define rc(x) d[x].ch[1]
int cp(int x){
int y=newnode(d[x].ncnt,d[x].d);
lc(y)=lc(x),rc(y)=rc(x);return y;
}
void pushup(int x){
assert(d[x].ncnt!=1);
d[x].d=d[lc(x)].d+d[rc(x)].d;
d[x].ncnt=d[lc(x)].ncnt+d[rc(x)].ncnt;
}
void turn(int x,int k){//both x and y must be copied
int y=d[x].ch[k];
swap(lc(x),rc(x));swap(lc(y),rc(y));swap(d[x].ch[k],d[y].ch[k^1]);
pushup(y);
}
int combine(int x,int y){
int z=newnode(d[x].ncnt+d[y].ncnt,d[x].d+d[y].d);
lc(z)=x,rc(z)=y;return z;
}
int merge(int x,int y){
if(!x||!y)return x+y;
if(min(d[x].ncnt,d[y].ncnt)>alpha*(d[x].ncnt+d[y].ncnt))return combine(x,y);
if(d[x].ncnt>d[y].ncnt){
if(d[lc(x)].ncnt>alpha*(d[x].ncnt+d[y].ncnt))return combine(lc(x),merge(rc(x),y));
return combine(merge(lc(x),lc(rc(x))),merge(rc(rc(x)),y));
}else{
if(d[rc(y)].ncnt>alpha*(d[x].ncnt+d[y].ncnt))return combine(merge(x,lc(y)),rc(y));
return combine(merge(x,lc(lc(y))),merge(rc(lc(y)),rc(y)));
}
}
void wblt(int x){//x must be copied
assert(d[x].ncnt!=1);
int k=0;
if(d[lc(x)].ncnt<d[x].ncnt*alpha)k=1;
else if(d[rc(x)].ncnt<d[x].ncnt*alpha)k=0;
else return;
int y=d[x].ch[k];
if(d[d[y].ch[k^1]].ncnt>d[y].ncnt*beta){
y=d[x].ch[k]=cp(d[x].ch[k]);
d[y].ch[k^1]=cp(d[y].ch[k^1]);
turn(y,k^1);
}
turn(x,k);
}
int del(int x,ll sz){
assert(sz<=d[x].d.sz&&sz>=0);
if(!sz)return x;
if(sz==d[x].d.sz)return 0;
if(d[x].ncnt==1){
int y=cp(x);int v=d[x].d.sum/d[x].d.sz;
d[y].d.sz-=sz;d[y].d.sum-=1LL*v*sz;return y;
}
if(sz>=d[rc(x)].d.sz)return del(lc(x),sz-d[rc(x)].d.sz);
else{
x=cp(x);rc(x)=del(rc(x),sz);
wblt(x);
return x;
}
}
ll qry(int x,ll l,ll r){
if(!x||r<1||l>d[x].d.sz)return 0;
if(d[x].ncnt==1)return d[x].d.sum/d[x].d.sz*(min(d[x].d.sz,r)-max(1LL,l)+1);
if(l<=1&&d[x].d.sz<=r)return d[x].d.sum;
return qry(lc(x),l,r)+qry(rc(x),l,r);
}
#undef lc
#undef rc
};
namespace SEG{
struct tag{
ll pp,rt;
void spread(tag t){
if(t.pp){
if(t.pp>=WBLT::d[rt].d.sz)pp+=t.pp-WBLT::d[rt].d.sz,rt=0;
else rt=WBLT::del(rt,t.pp);
}
rt=WBLT::merge(rt,t.rt);
}
};
struct node{
tag t;
}d[N<<2];
#define lc (rt<<1)
#define rc ((rt<<1)|1)
void pushdown(int rt){
d[lc].t.spread(d[rt].t);
d[rc].t.spread(d[rt].t);
d[rt].t.pp=d[rt].t.rt=0;
}
ll qry(int rt,int l,int r,int x,int ql,int qr){
if(l==r)return WBLT::qry(d[rt].t.rt,ql,qr);
pushdown(rt);int mid=(l+r)>>1;
if(x<=mid)return qry(lc,l,mid,x,ql,qr);
else return qry(rc,mid+1,r,x,ql,qr);
}
void push(int rt,int l,int r,int ul,int ur,int x,int y){
if(ul<=l&&r<=ur){
d[rt].t.rt=WBLT::merge(d[rt].t.rt,WBLT::newnode(1,(WBLT::data){x,1LL*x*y}));//could do better
return;
}
int mid=(l+r)>>1;pushdown(rt);
if(ul<=mid)push(lc,l,mid,ul,ur,x,y);
if(mid<ur)push(rc,mid+1,r,ul,ur,x,y);
}
void pop(int rt,int l,int r,int ul,int ur,ll x){
if(ul<=l&&r<=ur){
if(WBLT::d[d[rt].t.rt].d.sz<=x){d[rt].t.pp+=x-WBLT::d[d[rt].t.rt].d.sz;d[rt].t.rt=0;}
else d[rt].t.rt=WBLT::del(d[rt].t.rt,x);
return;
}
int mid=(l+r)>>1;pushdown(rt);
if(ul<=mid)pop(lc,l,mid,ul,ur,x);
if(mid<ur)pop(rc,mid+1,r,ul,ur,x);
}
};
int n,m;
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int op;scanf("%d",&op);
if(op==1){
int l,r,x,y;scanf("%d%d%d%d",&l,&r,&x,&y);
SEG::push(1,1,n,l,r,x,y);
}else if(op==2){
int l,r;ll w;scanf("%d%d%lld",&l,&r,&w);
SEG::pop(1,1,n,l,r,w);
}else{
int k;ll l,r;scanf("%d%lld%lld",&k,&l,&r);
printf("%lld\n",SEG::qry(1,1,n,k,l,r));
}
}
return 0;
}
详细
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
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:
result:
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 363ms
memory: 269212kb
input:
99999 99998 1 5026 18575 27178 90423 3 30623 1 1 3 76936 1 1 1 77021 95683 84664 24734 1 46085 74886 40512 11266 3 5048 8594 22468 1 53318 77721 97151 70784 1 70645 91192 37556 13013 1 56752 56940 91812 62887 1 7928 34576 87339 69404 3 74875 32807 100970 3 22338 17221 25771 3 21421 20602 57957 3 717...
output:
0 0 1254619125 4703224026 593473604 2592655824 1143798656 5629679917 110091352 1226646296 1989326852 1002183182 0 0 0 0 1790873593 5187399319 0 0 42868467293 899316516 0 6411326682 0 20615360837 3215147936 6840597923 13597117610 0 456207732 0 42991458601 0 0 948784563 23357328942 0 9499520539 0 0 0 ...
result:
wrong answer 4th numbers differ - expected: '4366274868', found: '4703224026'
Subtask #3:
score: 0
Runtime Error
Test #12:
score: 0
Runtime Error
input:
100000 99993 1 47773 70467 16065 1 2 52349 78446 2304 3 40821 1 1 1 40216 93069 78144 1 1 41089 43671 76025 1 2 35263 68629 31066 3 79881 13534 57327 3 5556 1 1 2 21962 38192 1 1 664 58116 9417 1 3 28089 6039 7989 2 88500 90302 9946 3 63215 49410 60770 2 11069 89527 57581 2 70303 97603 12363 1 3420 ...
output:
result:
Subtask #4:
score: 0
Runtime Error
Test #17:
score: 0
Runtime Error
input:
99999 99996 3 77889 1 10000000000 1 6316 86327 89644 386 3 9260 1 10000000000 2 2603 47234 69717 2 20260 73011 19290 2 62477 81233 26127 1 50140 68508 37004 98794 2 14449 22788 16063 1 43860 84932 50375 21777 1 67345 94584 28202 66610 2 661 68654 1 1 14411 94422 82738 61196 1 16563 94416 4920 38408 ...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
0%