QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#106895 | #3835. Oracle | zhouhuanyi | AC ✓ | 768ms | 6152kb | C++11 | 2.9kb | 2023-05-19 17:42:04 | 2023-05-19 17:42:21 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cstdlib>
#include<random>
#define N 60000
using namespace std;
mt19937 RAND(time(0));
int read()
{
char c=0;
int sum=0,f=1;
while (c!='-'&&(c<'0'||c>'9')) c=getchar();
if (c=='-') c=getchar(),f=-1;
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum*f;
}
int ST,n,p[N+1],leng,a,b,rt;
long long tong[N+1];
struct fhq_treap
{
struct node
{
int ls,rs,sz,rd;
long long data,lazy1,lazy2;
};
node tree[N+1];
int length;
int new_node(long long x)
{
tree[++length]=(node){0,0,1,RAND()%1000000000,x,0,0};
return length;
}
void push_up(int k)
{
tree[k].sz=tree[tree[k].ls].sz+tree[tree[k].rs].sz+1;
return;
}
void get_spread1(int k,long long d)
{
if (!k) return;
tree[k].data+=d,tree[k].lazy1+=d;
return;
}
void get_spread2(int k,long long d)
{
if (!k) return;
tree[k].data+=d*tree[tree[k].ls].sz,tree[k].lazy2+=d;
return;
}
void spread(int k)
{
if (tree[k].lazy1) get_spread1(tree[k].ls,tree[k].lazy1),get_spread1(tree[k].rs,tree[k].lazy1),tree[k].lazy1=0;
if (tree[k].lazy2) get_spread2(tree[k].ls,tree[k].lazy2),get_spread1(tree[k].rs,tree[k].lazy2*(tree[tree[k].ls].sz+1)),get_spread2(tree[k].rs,tree[k].lazy2),tree[k].lazy2=0;
return;
}
int merge(int x,int y)
{
if (!x||!y) return x^y;
if (tree[x].rd<tree[y].rd)
{
spread(y),tree[y].ls=merge(x,tree[y].ls),push_up(y);
return y;
}
else
{
spread(x),tree[x].rs=merge(tree[x].rs,y),push_up(x);
return x;
}
}
void split(int k,int d,int &x,int &y)
{
if (!k)
{
x=y=0;
return;
}
spread(k);
if (d<=tree[tree[k].ls].sz) split(tree[k].ls,d,x,tree[k].ls),y=k;
else split(tree[k].rs,d-tree[tree[k].ls].sz-1,tree[k].rs,y),x=k;
push_up(k);
return;
}
void solve(int k)
{
spread(k);
if (tree[k].ls) solve(tree[k].ls);
++leng,tong[leng]=tong[leng-1]+tree[k].data;
if (tree[k].rs) solve(tree[k].rs);
return;
}
int find(int k,int d,int cnt)
{
if (!k) return 0;
int scnt=cnt+tree[tree[k].ls].sz;
spread(k);
if (!scnt||1ll*d*scnt*scnt+1ll*d*a*scnt+1ll*d*b<tree[k].data) return max(scnt,find(tree[k].rs,d,scnt+1));
else return find(tree[k].ls,d,cnt);
}
};
fhq_treap T;
int main()
{
int ps,A,B,C;
ST=read();
while (ST--)
{
n=read(),T.length=0;
for (int i=1;i<=n;++i) p[i]=read();
a=read(),b=read(),rt=T.new_node(0);
for (int i=1;i<=n;++i)
{
ps=T.find(rt,p[i],0),T.split(rt,ps+1,A,C),B=T.new_node(1ll*p[i]*(ps+1)*(ps+1)+1ll*p[i]*a*(ps+1)+1ll*p[i]*b);
if (C) T.get_spread1(C,1ll*p[i]*(a+(ps<<1)+3)),T.get_spread2(C,p[i]*2);
rt=T.merge(T.merge(A,B),C);
}
leng=0,T.solve(rt);
for (int i=2;i<=leng;++i) printf("%lld ",tong[i]);
puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 768ms
memory: 6152kb
input:
20 50000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
50000 249999 699994 1499980 2749950 4549895 6999804 10199664 14249460 19249175 25298790 32498284 40947634 50746815 61995800 74794560 89243064 105441279 123489170 143486700 165533830 189730519 216176724 244972400 276217500 310011975 346455774 385648844 427691130 472682575 520723120 571912704 62635126...
result:
ok 20 lines