QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#322609 | #8229. 栈 | zhouhuanyi | 0 | 35ms | 100956kb | C++14 | 4.2kb | 2024-02-07 12:01:12 | 2024-02-07 12:01:12 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 100000
#define as 0.75
using namespace std;
long long read()
{
char c=0;
long long sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
struct WBLT
{
struct node
{
int ls,rs;
long long sz,data;
};
node tree[400*N+1];
int length;
int new_node(int d)
{
++length,tree[length]=(node){0,0,1,d};
return length;
}
void push_up(int k)
{
tree[k].sz=tree[tree[k].ls].sz+tree[tree[k].rs].sz,tree[k].data=tree[tree[k].ls].data+tree[tree[k].rs].data;
return;
}
int merge(int x,int y)
{
if (!x||!y) return x^y;
int res=tree[x].sz+tree[y].sz;
if (tree[x].sz>tree[y].sz)
{
if (tree[x].sz<=as*res)
{
int nw=++length;
tree[nw].ls=x,tree[nw].rs=y,push_up(nw);
return nw;
}
else if (tree[tree[x].ls].sz>(1-as)*res)
{
int nw=++length;
tree[nw].ls=tree[x].ls,tree[nw].rs=merge(tree[x].rs,y),push_up(nw);
return nw;
}
else
{
int nw=++length;
tree[nw].ls=merge(tree[x].ls,tree[tree[x].rs].ls),tree[nw].rs=merge(tree[tree[x].rs].rs,y),push_up(nw);
return nw;
}
}
else
{
if (tree[y].sz<=as*res)
{
int nw=++length;
tree[nw].ls=x,tree[nw].rs=y,push_up(nw);
return nw;
}
else if (tree[tree[y].rs].sz>(1-as)*res)
{
int nw=++length;
tree[nw].ls=merge(x,tree[y].ls),tree[nw].rs=tree[y].rs,push_up(nw);
return nw;
}
else
{
int nw=++length;
tree[nw].ls=merge(x,tree[tree[y].ls].ls),tree[nw].rs=merge(tree[tree[y].ls].rs,tree[y].rs),push_up(nw);
return nw;
}
}
}
void split(int k,int d,int &x,int &y)
{
if (!tree[k].ls)
{
if (!d) x=0,y=k;
else x=k,y=0;
return;
}
int nw1=++length,nw2=++length;
if (d<=tree[tree[k].ls].sz) split(tree[k].ls,d,nw1,nw2),x=nw1,y=merge(nw2,tree[k].rs);
else split(tree[k].rs,d-tree[tree[k].ls].sz,nw1,nw2),x=merge(tree[k].ls,nw1),y=nw2;
return;
}
int get_kth(int k,int d)
{
if (!tree[k].ls) return 1;
if (d<=tree[tree[k].ls].data) return get_kth(tree[k].ls,d);
else return get_kth(tree[k].rs,d-tree[tree[k].ls].data)+tree[tree[k].ls].sz;
}
};
WBLT T;
struct reads
{
long long sz;
int data;
};
reads operator + (reads a,reads b)
{
int A,B;
if (a.data<=b.sz) return (reads){a.sz+b.sz-a.data,b.data};
else
{
T.split(a.data,T.tree[a.data].sz-b.sz,A,B);
return (reads){a.sz,T.merge(A,b.data)};
}
}
struct seg
{
struct node
{
int l,r;
reads lazy;
};
node tree[(N<<2)+1];
void build(int k,int l,int r)
{
tree[k].l=l,tree[k].r=r;
if (l==r) return;
int mid=(l+r)>>1;
build(k<<1,l,mid),build(k<<1|1,mid+1,r);
return;
}
void spread(int k)
{
if (tree[k].lazy.sz||tree[k].lazy.data) tree[k<<1].lazy=tree[k<<1].lazy+tree[k].lazy,tree[k<<1|1].lazy=tree[k<<1|1].lazy+tree[k].lazy,tree[k].lazy=(reads){0,0};
return;
}
void add(int k,int l,int r,reads d)
{
if (tree[k].l==l&&tree[k].r==r)
{
tree[k].lazy=tree[k].lazy+d;
return;
}
spread(k);
int mid=(tree[k].l+tree[k].r)>>1;
if (r<=mid) add(k<<1,l,r,d);
else if (l>=mid+1) add(k<<1|1,l,r,d);
else add(k<<1,l,mid,d),add(k<<1|1,mid+1,r,d);
return;
}
long long query(int k,int x,long long p,long long q)
{
if (tree[k].l==tree[k].r)
{
int A,B,C,tmp;
q=min(q,T.tree[tree[k].lazy.data].sz);
if (p>q) return 0;
T.split(tree[k].lazy.data,q,tmp,C),T.split(tmp,p-1,A,B);
return T.tree[B].data;
}
spread(k);
int mid=(tree[k].l+tree[k].r)>>1;
if (x<=mid) return query(k<<1,x,p,q);
else return query(k<<1|1,x,p,q);
}
};
seg T2;
int n,m;
int fast_pow(int a,int b)
{
int res=0,mul=a;
while (b)
{
if (b&1) res=T.merge(res,mul);
mul=T.merge(mul,mul),b>>=1;
}
return res;
}
int main()
{
int op,l,r,k,x,y;
long long w,p,q;
n=read(),m=read(),T2.build(1,1,n);
for (int i=1;i<=m;++i)
{
op=read();
if (op==1) l=read(),r=read(),x=read(),y=read(),T2.add(1,l,r,(reads){0,fast_pow(T.new_node(y),x)});
else if (op==2) l=read(),r=read(),w=read(),T2.add(1,l,r,(reads){w,0});
else k=read(),p=read(),q=read(),printf("%lld\n",T2.query(1,k,p,q));
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 35ms
memory: 100956kb
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 0 203015110 200648623 98486697 214102593 123945 0 61782451 0 0 0 762429740 0 638060258 0 4594954595 0 1792521566 6640518748 209997360 122249391 0 5250788038 0 0 0 118545795 1530005511 1394456248 0 0 1694570763 0 0 0 0 1356781860 642842550 0 113773506 5380189150 0 0 0 274738278 0 0 0 217...
result:
wrong answer 3rd numbers differ - expected: '903396180', found: '0'
Subtask #2:
score: 0
Memory Limit Exceeded
Test #6:
score: 0
Memory Limit Exceeded
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 4366274868 593473604 2592655824 3657975552 5652513833 110091352 1226646296 1989326852 763582808 8205318671 1659086055 3012598941 20085582585 3242801176 17381308704 24555397019 4722824224 20308857160 899316516 38935050954 988382364 13341823621 11397759491 2449683584 5875277101 80572355...
result:
Subtask #3:
score: 0
Memory Limit Exceeded
Test #12:
score: 0
Memory Limit Exceeded
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:
0 43794 0 1951 0 0 0 29245 0 0 0 0 0 84246 24537 0 0 0 0 37527 0 0 0 20502 0 223619 57614 1602 129470 61935 4068 0 17609 152949 26099 47500 63902 0 13206 125791 0 0 42058 0 0 34540 0 0 0 13978 0 0 0 0 0 2914 108 0 0 0 0 30137 118370 0 12422 0 34954 44775 0 19049 0 0 26603 0 0 0 46243 0 50099 0 30799...
result:
Subtask #4:
score: 0
Memory Limit Exceeded
Test #17:
score: 0
Memory Limit Exceeded
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:
0 34602584 0 0 27712482939 1362841668 83115 1902514434 1902514434 0 1902514434 15794375094 0 4192446657 0 0 0 5216355443 1385452703 77203035 77203035 77203035 0 6843261316 0 0 0 14166158305 6144703384 6542442770 8463978444 4496343819 14992706913 0 10890418194 411945666 8007904658 522526886 326063373...
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
0%