QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#44572 | #4585. Greedy Knapsack | eyiigjkn | Compile Error | / | / | C++14 | 2.5kb | 2022-08-19 10:50:46 | 2022-08-19 10:50:48 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2022-08-19 10:50:48]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2022-08-19 10:50:46]
- 提交
answer
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr double alp=1-1./sqrt(2);
int w[100010],v[100010],stk[5000010],lc[5000010],rc[5000010],sz[5000010],tot=0,cnt=0;
ll len[5000010],val[5000010],addmk[5000010];
bool flag[5000010];
int newnode(int s=0,ll l=0,ll v=0)
{
int cur=(stk[0]?stk[stk[0]--]:++tot);cnt++;
assert(cur<=5000000);
addmk[cur]=lc[cur]=rc[cur]=0;
sz[cur]=s;
len[cur]=l;val[cur]=v;
return cur;
}
int copy(int rt)
{
int cur=(stk[0]?stk[stk[0]--]:++tot);cnt++;
assert(cur<=5000000);
tie(lc[cur],rc[cur],sz[cur],len[cur],val[cur],addmk[cur])=make_tuple(lc[rt],rc[rt],sz[rt],len[rt],val[rt],addmk[rt]);
return cur;
}
void pushup(int rt)
{
if(!lc[rt]) return;
sz[rt]=sz[lc[rt]]+sz[rc[rt]];
len[rt]=len[lc[rt]]+len[rc[rt]];
val[rt]=max(val[lc[rt]],val[rc[rt]]);
}
void update(int rt,ll x)
{
val[rt]+=x;addmk[rt]+=x;
}
void pushdown(int rt)
{
if(addmk[rt])
{
if(lc[rt]) update(lc[rt]=copy(lc[rt]),addmk[rt]);
if(rc[rt]) update(rc[rt]=copy(rc[rt]),addmk[rt]);
addmk[rt]=0;
}
}
int join(int x,int y)
{
int rt=newnode();
lc[rt]=x;rc[rt]=y;
pushup(rt);
return rt;
}
int merge(int x,int y)
{
if(!x || !y) return x+y;
pushdown(x);pushdown(y);
if(min(sz[x],sz[y])>=alp*(sz[x]+sz[y])) return join(x,y);
if(sz[x]>=sz[y])
if(sz[lc[x]]>=alp*(sz[x]+sz[y])) return merge(lc[x],merge(rc[x],y));
else return pushdown(rc[x]),merge(merge(lc[x],lc[rc[x]]),merge(rc[rc[x]],y));
else
if(sz[rc[y]]>=alp*(sz[x]+sz[y])) return merge(merge(x,lc[y]),rc[y]);
else return pushdown(lc[y]),merge(merge(x,lc[lc[y]]),merge(rc[lc[y]],rc[y]));
}
void split(int rt,ll k,int &x,int &y)
{
if(!rt) return x=y=0,void();
if(sz[rt]==1)
if(!k) return x=0,y=rt,void();
else if(k==len[rt]) return x=rt,y=0,void();
else return x=newnode(1,k,val[rt]),y=newnode(1,len[rt]-k,val[rt]),void();
pushdown(rt);
if(k<=len[lc[rt]]) split(lc[rt],k,x,y),y=merge(y,rc[rt]);
else split(rc[rt],k-len[lc[rt]],x,y),x=merge(lc[rt],x);
}
void dfs(int rt)
{
if(!rt || flag[rt]) return;
flag[rt]=1;
dfs(lc[rt]);dfs(rc[rt]);
}
int main()
{
int n,rt;
ll m;
cin>>n>>m;
for(int i=1;i<=n;i++) scanf("%d",&w[i]);
for(int i=1;i<=n;i++) scanf("%d",&v[i]);
rt=newnode(1,m+1,0);
for(int i=n;i;i--)
{
int a,b,c,d;
split(rt,w[i],a,b);
split(rt,m-w[i]+1,c,d);
if(c) update(c,v[i]);
rt=merge(a,c);nw=0;
if(cnt>4990000)
{
cnt=stk[0]=0;dfs(rt);
for(int i=1;i<=tot;i++)
if(flag[i]) flag[i]=0,cnt++;
else stk[++stk[0]]=i;
}
}
cout<<val[rt]<<endl;
return 0;
}
Details
answer.code: In function ‘int main()’: answer.code:94:31: error: ‘nw’ was not declared in this scope; did you mean ‘n’? 94 | rt=merge(a,c);nw=0; | ^~ | n answer.code:85:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 85 | for(int i=1;i<=n;i++) scanf("%d",&w[i]); | ~~~~~^~~~~~~~~~~~ answer.code:86:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 86 | for(int i=1;i<=n;i++) scanf("%d",&v[i]); | ~~~~~^~~~~~~~~~~~