QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#546545 | #6355. 5 | little_pinkpig | RE | 65ms | 10228kb | C++14 | 2.5kb | 2024-09-04 09:01:53 | 2024-09-04 09:01:53 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define MAXN (200005)
#define MAXS (200005)
using namespace std;
void File()
{
freopen(".in","r",stdin);
freopen(".out","w",stdout);
}
template<typename type>
void read(type &x)
{
bool f=0;char ch=0;x=0;
while(ch<'0'||ch>'9'){f|=!(ch^'-');ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
x=f?-x:x;
}
template<typename type,typename... Args>
void read(type &x,Args &... args)
{
read(x);
read(args...);
}
struct item{
int l,r;
};
inline bool cmp(item x,item y){return (x.l^y.l)?(x.l<y.l):(x.r<y.r);}
int n,s,p,tot,sum;
int w[MAXN],v[MAXN],cnt[MAXS];
ll ans;
vector<item> f[MAXS];
void merge(vector<item> &fy,vector<item> fx,int dt)
{
vector<item> tmp;
int pt=0,nl=-1,nr=-1;
for(item I:fy)
{
ans-=I.r-I.l+1;
while(pt<fx.size()&&fx[pt].l+dt<I.l)
{
if((~nr)&&(nr<fx[pt].l+dt))
{
tmp.push_back({nl,nr});
ans+=nr-nl+1,nl=nr=-1;
}
if(nr==-1) nl=fx[pt].l+dt,nr=fx[pt].r+dt;
else if(nr>=fx[pt].l+dt) nr=max(nr,fx[pt].r+dt);
++pt;
}
if((~nr)&&(nr<I.l))
{
tmp.push_back({nl,nr});
ans+=nr-nl+1,nl=nr=-1;
}
if(nr==-1) nl=I.l,nr=I.r;
else if(nr>=I.l) nr=max(nr,I.r);
}
while(pt<fx.size())
{
if((~nr)&&(nr<fx[pt].l+dt))
{
tmp.push_back({nl,nr});
ans+=nr-nl+1,nl=nr=-1;
}
if(nr==-1) nl=fx[pt].l+dt,nr=fx[pt].r+dt;
else if(nr>=fx[pt].l+dt) nr=max(nr,fx[pt].r+dt);
++pt;
}
if(~nr) tmp.push_back({nl,nr}),ans+=nr-nl+1;
fy.swap(tmp);
}
int main()
{
#ifndef ONLINE_JUDGE
File();
#endif
read(n,s);
for(int i=1,x;i<=n;i++)
{
read(x);
++cnt[x];
}
for(int i=2,c,now;i<=s;i++)
{
c=cnt[i],now=1;
while(c)
{
++tot;w[tot]=now,v[tot]=(i-1)*now;
if(!(c&1)){++tot;w[tot]=now,v[tot]=(i-1)*now;}
c=(c-1)>>1,now<<=1;
}
}
ans=1ll*(cnt[0]+1)*(cnt[1]+1);
for(int i=0;i<=cnt[0];i++) f[n-i].push_back({i,i+cnt[1]});
sum=n;
for(int i=1;i<=tot;i++)
{
for(int j=sum;j>=n-cnt[0];j--)
if(!f[j].empty())
merge(f[j+v[i]],f[j],w[i]);
sum+=v[i];
}
printf("%lld",ans);
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 9816kb
input:
7 9 0 0 0 1 1 2 5
output:
42
result:
ok 1 number(s): "42"
Test #2:
score: 0
Accepted
time: 1ms
memory: 10228kb
input:
10 33 9 9 8 1 1 1 1 1 1 1
output:
48
result:
ok 1 number(s): "48"
Test #3:
score: 0
Accepted
time: 2ms
memory: 9896kb
input:
10 14 2 4 4 1 0 1 0 1 0 1
output:
81
result:
ok 1 number(s): "81"
Test #4:
score: 0
Accepted
time: 2ms
memory: 9368kb
input:
10 14 3 5 3 0 1 0 1 0 1 0
output:
87
result:
ok 1 number(s): "87"
Test #5:
score: 0
Accepted
time: 2ms
memory: 9884kb
input:
40 50 1 1 1 1 3 3 0 3 1 1 0 0 2 1 0 0 1 0 0 2 7 1 2 1 3 0 2 2 3 1 1 0 0 2 0 1 1 0 1 1
output:
1067
result:
ok 1 number(s): "1067"
Test #6:
score: 0
Accepted
time: 2ms
memory: 9156kb
input:
1200 1000 1 1 2 3 0 1 0 0 1 1 0 2 3 0 1 2 0 0 1 0 4 1 1 2 1 1 0 0 1 1 0 1 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 0 0 1 1 0 1 2 0 4 0 3 1 6 0 1 1 0 0 0 0 4 0 0 0 0 0 0 1 0 0 1 7 1 1 1 0 1 0 1 0 1 1 0 0 1 1 1 3 0 1 0 1 0 0 1 1 2 2 0 1 1 0 0 1 4 1 2 0 0 0 3 0 0 2 1 0 2 0 0 0 1 1 0 0 2 0 0 0 0 1 1 0 1 0 1 6 1 1 ...
output:
737899
result:
ok 1 number(s): "737899"
Test #7:
score: 0
Accepted
time: 14ms
memory: 9548kb
input:
12000 10000 1 1 0 0 1 0 2 1 3 0 0 1 0 3 1 1 0 1 1 1 1 1 2 1 0 1 2 1 0 1 2 0 5 1 1 1 0 2 0 1 0 1 0 3 2 0 1 0 1 1 2 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 0 4 0 1 3 1 0 0 1 0 1 2 1 0 0 1 1 0 2 1 1 0 1 0 1 0 0 2 1 1 3 0 1 1 1 0 0 0 1 1 1 0 3 0 0 0 2 0 0 0 1 0 2 0 1 1 1 0 0 1 0 1 0 2 0 0 0 0 0 0 0 1 0 1 0 0 4 1 ...
output:
73685347
result:
ok 1 number(s): "73685347"
Test #8:
score: 0
Accepted
time: 65ms
memory: 9724kb
input:
36000 30000 0 3 4 1 2 1 1 0 0 1 1 0 1 0 2 1 0 0 0 0 2 1 0 2 0 0 0 0 0 1 1 4 1 4 0 0 2 0 0 0 1 1 0 0 1 1 0 1 0 0 0 0 1 1 0 3 1 1 1 0 0 0 0 0 0 1 2 0 2 3 0 0 0 0 3 1 0 0 0 1 0 1 2 0 0 2 0 1 0 0 2 1 1 0 3 1 6 0 0 1 1 2 0 1 2 0 0 1 0 1 1 0 0 1 0 0 0 1 0 2 0 1 1 1 0 0 5 2 0 5 1 0 0 0 0 1 1 1 8 0 1 1 0 1 ...
output:
658813003
result:
ok 1 number(s): "658813003"
Test #9:
score: -100
Runtime Error
input:
200000 200000 0 1 1 1 1 1 0 1 0 3 1 0 0 1 1 0 1 1 1 2 3 0 1 0 1 0 2 5 0 1 1 4 1 1 0 0 0 0 0 0 2 1 0 0 2 1 1 2 0 3 0 1 3 0 1 1 1 0 1 0 1 2 0 1 1 0 0 2 2 1 0 1 1 2 4 1 0 2 0 5 1 2 0 0 1 0 2 3 1 0 1 1 1 1 0 0 0 5 1 0 0 1 2 1 1 0 0 0 1 0 0 1 2 1 0 0 2 1 2 3 0 0 3 1 0 1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 1 1 1 ...