QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#101939 | #6355. 5 | zhouhuanyi | TL | 4988ms | 43112kb | C++11 | 2.1kb | 2023-05-01 21:33:18 | 2023-05-01 21:33:20 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cassert>
#define N 400000
#define inf 1e9
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int n,S,cnt,cnt2,a[N+1],cnts[N+1];
long long ans;
vector<int>dp[N+1];
vector<int>A[N+1];
vector<int>B[N+1];
vector<int>c;
vector<int>d;
vector<int>operator + (vector<int>a,vector<int>b)
{
if (b.empty()) return a;
if (a.empty()) return b;
int ps=-1;
c.clear(),d.clear();
for (int i=0;i<b.size();++i)
{
while (ps+1<a.size()&&a[ps+1]<b[i]) c.push_back(a[++ps]);
c.push_back(b[i]);
}
for (int i=ps+1;i<a.size();++i) c.push_back(a[i]);
for (int i=0;i<c.size();++i)
{
while (!d.empty()&&d.back()==c[i]) d.pop_back();
while (d.size()>=2&&c[i]-d[(int)(d.size())-2]<=cnt2) d.pop_back();
d.push_back(c[i]);
}
return d;
}
vector<int>operator + (vector<int>p,int d)
{
for (int i=0;i<p.size();++i) p[i]+=d;
return p;
}
vector<int>operator - (vector<int>p,int d)
{
for (int i=0;i<p.size();++i) p[i]-=d;
return p;
}
int main()
{
int d,sr,res;
n=read(),S=read();
for (int i=1;i<=n;++i)
{
a[i]=read()-1;
if (a[i]==-1) cnt++;
if (a[i]==0) cnt2++;
if (a[i]>=1) cnts[a[i]]++;
}
res=cnt;
for (int i=0;i<=cnt;++i) dp[i].push_back(cnt-i);
for (int i=1;i<=S;++i)
if (cnts[i])
{
res+=cnts[i]*i;
for (int j=0;j<i;++j)
{
d=(res-j)/i;
for (int k=0;k<=d;++k)
{
if (!k||k/cnts[i]!=(k-1)/cnts[i]) A[k]=dp[k*i+j]-k;
else A[k]=A[k-1]+(dp[k*i+j]-k);
}
for (int k=d;k>=0;--k)
{
if (k==d||k/cnts[i]!=(k+1)/cnts[i]) B[k]=dp[k*i+j]-k;
else B[k]=B[k+1]+(dp[k*i+j]-k);
}
for (int k=0;k<=d;++k)
{
dp[k*i+j]=A[k]+k;
if (k>=cnts[i]) dp[k*i+j]=dp[k*i+j]+(B[k-cnts[i]]+k);
}
}
}
for (int i=0;i<=res;++i)
{
sr=-inf;
for (int j=0;j<dp[i].size();++j) ans+=dp[i][j]+cnt2-max(dp[i][j],sr+1)+1,sr=dp[i][j]+cnt2;
}
printf("%lld\n",ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 5ms
memory: 33904kb
input:
7 9 0 0 0 1 1 2 5
output:
42
result:
ok 1 number(s): "42"
Test #2:
score: 0
Accepted
time: 3ms
memory: 34636kb
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: 6ms
memory: 34120kb
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: 3ms
memory: 33496kb
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: 0ms
memory: 32932kb
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: 3ms
memory: 34388kb
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: 25ms
memory: 34300kb
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: 71ms
memory: 35988kb
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: 0
Accepted
time: 678ms
memory: 43112kb
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 ...
output:
23477878007
result:
ok 1 number(s): "23477878007"
Test #10:
score: 0
Accepted
time: 755ms
memory: 39892kb
input:
140000 200000 0 1 3 0 0 0 0 0 1 1 1 1 4 1 1 8 1 1 0 3 0 0 0 1 5 0 1 1 0 4 1 0 2 1 0 0 1 1 1 0 2 4 0 2 0 3 0 2 1 2 1 2 1 1 1 2 1 0 0 1 1 1 1 0 1 0 9 1 5 1 1 4 0 1 1 4 1 1 1 1 3 1 1 1 1 4 1 1 0 3 1 0 1 3 1 1 3 1 1 3 4 1 1 0 0 1 1 0 1 4 1 1 1 1 0 1 1 0 0 2 0 6 5 1 1 3 2 4 0 1 4 1 1 1 1 2 0 0 2 1 5 1 1 ...
output:
15405328745
result:
ok 1 number(s): "15405328745"
Test #11:
score: 0
Accepted
time: 1093ms
memory: 39324kb
input:
90000 200000 3 1 1 1 4 5 1 1 1 1 10 1 3 2 1 1 7 8 1 1 8 5 1 1 6 1 1 1 0 1 4 5 0 5 1 21 1 4 0 2 4 3 1 6 7 3 1 1 1 0 1 2 5 1 1 1 1 2 0 8 0 1 2 4 0 0 11 1 2 2 2 1 28 0 1 1 2 1 2 1 11 1 5 9 1 1 1 1 1 2 1 1 1 1 2 1 0 4 1 1 2 1 1 1 4 1 5 1 1 5 4 1 5 1 0 1 1 1 1 0 1 2 4 1 1 1 1 1 1 1 1 1 2 1 1 3 1 2 1 1 0 ...
output:
9895248405
result:
ok 1 number(s): "9895248405"
Test #12:
score: 0
Accepted
time: 1360ms
memory: 38288kb
input:
80000 200000 1 5 1 1 1 3 1 0 3 11 1 5 1 2 1 21 4 13 1 1 1 1 0 1 1 1 2 1 13 2 1 4 5 0 1 1 6 3 1 1 1 1 1 1 8 1 1 6 3 1 1 1 1 8 1 2 0 1 1 1 1 1 1 1 17 1 1 1 6 1 1 1 11 1 15 5 1 1 1 1 1 2 8 0 0 1 1 2 3 14 1 1 3 18 1 1 1 3 1 1 1 1 1 1 4 0 9 1 0 1 1 1 0 4 1 2 1 1 3 2 3 21 3 2 11 1 1 0 1 29 1 1 2 1 5 6 1 5...
output:
8980751457
result:
ok 1 number(s): "8980751457"
Test #13:
score: 0
Accepted
time: 1633ms
memory: 37856kb
input:
70000 200000 4 0 0 2 5 1 0 1 4 1 1 1 1 3 12 1 1 1 0 1 1 6 5 1 1 1 1 1 0 1 1 1 16 1 1 1 1 1 10 1 2 1 1 0 1 7 1 0 3 3 1 1 1 1 2 2 1 1 7 1 1 2 1 1 1 1 14 1 6 1 1 12 1 1 1 1 1 1 1 7 1 1 1 7 1 1 1 1 2 1 0 1 13 1 0 1 1 1 3 1 3 1 0 1 4 1 1 1 1 3 1 13 0 1 1 7 0 0 1 1 12 3 1 1 3 1 1 1 6 1 1 1 1 1 1 1 1 10 1 ...
output:
8196878191
result:
ok 1 number(s): "8196878191"
Test #14:
score: 0
Accepted
time: 2121ms
memory: 39472kb
input:
60000 200000 1 1 1 1 25 1 4 1 1 1 1 1 10 2 12 1 1 1 1 1 12 7 3 1 3 1 1 1 1 1 1 1 1 1 1 1 1 2 1 12 1 1 1 1 0 1 1 3 1 6 1 6 1 1 2 29 1 0 1 13 3 1 1 0 1 1 5 3 1 1 1 1 1 1 7 1 0 9 1 7 1 1 12 4 1 1 1 23 1 4 24 1 36 1 23 1 18 29 1 1 11 1 1 1 1 1 1 0 1 1 2 13 1 32 1 3 1 0 1 1 1 1 5 23 9 1 1 1 8 12 14 1 1 1...
output:
7466221263
result:
ok 1 number(s): "7466221263"
Test #15:
score: 0
Accepted
time: 3358ms
memory: 39612kb
input:
50000 200000 1 1 87 20 1 1 1 1 1 1 1 1 41 1 1 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 5 1 1 1 1 1 1 1 17 1 1 1 1 1 14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 17 18 1 1 1 1 1 13 1 1 1 1 1 32 1 1 7 1 10 1 1 1 1 14 20 1 1 1 1 1 3 23 27 1 1 1 9 1 1 1 1 4 8 1 12 1 1 1 53 1 1 1 1 26 1 1 1 1 1 1 1 1 1 1 1...
output:
6870036861
result:
ok 1 number(s): "6870036861"
Test #16:
score: 0
Accepted
time: 4730ms
memory: 38456kb
input:
45000 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 1 1 1 26 1 1 10 1 1 1 1 1 1 1 1 1 1 1 50 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 26 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 1 1 1 1...
output:
6615361583
result:
ok 1 number(s): "6615361583"
Test #17:
score: 0
Accepted
time: 4988ms
memory: 39640kb
input:
44000 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 6 1 16 1 1 1 1 104 1 1 1 1 1 1 50 23 1 1 1 1 1 1 23 1 18 1 1 1 1 1 1 1 28 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 1 1 1 1 1 1 1 49 1 1 1 1 1 1 1 1 1 1 1 1 53 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 76 1 1 1 1 1 1 1 1 1 149 1 1 1 1 1 0 1 1...
output:
6575348967
result:
ok 1 number(s): "6575348967"
Test #18:
score: -100
Time Limit Exceeded
input:
43000 200000 1 53 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 15 1 1 1 1 104 1 1 1 1 1 1 1 1 20 1 1 1 1 1 1 1 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 13 1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 65 1 1 1 1 138 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 15 62 1 1 1 1...