QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#101941#6355. 5zhouhuanyiTL 4920ms42936kbC++112.0kb2023-05-01 21:37:502023-05-01 21:37:53

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-01 21:37:53]
  • 评测
  • 测评结果:TL
  • 用时:4920ms
  • 内存:42936kb
  • [2023-05-01 21:37:50]
  • 提交

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)
{
    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.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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 32968kb

input:

7 9
0 0 0 1 1 2 5

output:

42

result:

ok 1 number(s): "42"

Test #2:

score: 0
Accepted
time: 2ms
memory: 34484kb

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: 3ms
memory: 34596kb

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: 6ms
memory: 34080kb

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: 3ms
memory: 33448kb

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: 1ms
memory: 33416kb

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: 20ms
memory: 35096kb

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: 35116kb

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: 611ms
memory: 42936kb

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: 693ms
memory: 40560kb

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: 1020ms
memory: 38724kb

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: 1190ms
memory: 38372kb

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: 1521ms
memory: 38964kb

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: 1925ms
memory: 38444kb

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: 3030ms
memory: 39572kb

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: 4357ms
memory: 38064kb

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: 4457ms
memory: 38600kb

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: 0
Accepted
time: 4920ms
memory: 38324kb

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...

output:

6527389951

result:

ok 1 number(s): "6527389951"

Test #19:

score: -100
Time Limit Exceeded

input:

42000 200000
1 1 1 1 1 1 1 1 23 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 239 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 1 1 1 1 2 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 10 1 58 1 ...

output:


result: