QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#545724#6355. 5tx344WA 273ms19288kbC++142.2kb2024-09-03 16:38:072024-09-03 16:38:09

Judging History

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

  • [2024-09-03 16:38:09]
  • 评测
  • 测评结果:WA
  • 用时:273ms
  • 内存:19288kb
  • [2024-09-03 16:38:07]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ld double
#define PII pair<int,int>
#define PLI pair<ll,int>
#define fi first
#define se second
using namespace std;
const int N=2e5+5;
int n,m,b[N],tot;
ll ans;
vector<PII>f[N*2],vec;
struct Node{int x,y;}a[N];
void Merge(vector<PII>&F,vector<PII>&G,int x)
{
    int j=0,L=-1,R=-1;
    for(int i=0;i<F.size();i++)
    {
        ans-=F[i].se-F[i].fi+1;
        while(j<G.size()&&G[j].fi+x<F[i].fi)
        {
            if(~R&&R<G[j].fi+x)vec.push_back({L,R}),ans+=R-L+1,L=R=-1;
            if(R<0)L=G[j].fi+x,R=G[j].se+x;
            else if(R>=G[j].fi+x)R=max(R,G[j].se+x);
            ++j;
        }
        if(~R&&R<F[i].fi)vec.push_back({L,R}),ans+=R-L+1,L=R=-1;
        if(R<0)L=F[i].fi,R=F[i].se;
        else if(R>=F[i].fi)R=max(R,F[i].se);
    }
    while(j<G.size())
    {
        if(~R&&R<G[j].fi+x)vec.push_back({L,R}),ans+=R-L+1,L=R=-1;
        if(R<0)L=G[j].fi+x,R=G[j].se+x;
        else if(R>=G[j].fi+x)R=max(R,G[j].se+x);
        ++j;
    }
    if(~R)vec.push_back({L,R}),ans+=R-L+1;
    // printf("Merge:%d\n",x);
    // for(PII p:F)printf("[%d,%d] ",p.fi,p.se);puts("");
    // for(PII p:G)printf("[%d,%d] ",p.fi,p.se);puts("");
    // for(PII p:vec)printf("[%d,%d] ",p.fi,p.se);puts("");
    F=vec;
    vec.clear();
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
	#endif
	
    scanf("%d%d",&n,&m);
    for(int i=1,x;i<=n;i++)
    {
        scanf("%d",&x);
        ++b[x];
    }
    for(int i=2;i<=m;i++)
    {
        int x=b[i],y=1;
        while(x)
        {
            a[++tot]={y,(i-1)*y};
            if(x%2==0)a[++tot]={y,(i-1)*y};
            x=(x-1)/2,y<<=1;
        }
    }
    // for(int i=1;i<=tot;i++)printf("%d %d\n",a[i].x,a[i].y);
    ans=(b[0]+1)*(b[1]+1);
    for(int i=0;i<=b[0];i++)f[N-i].push_back({i,i+b[1]});
    int R=N;
    for(int o=1;o<=tot;o++)
    {
        for(int i=R;i>=N-b[0];i--)if(!f[i].empty())
        {
            // printf("Out:%d %d %d\n",i+a[o].y-N,i-N,a[o].x);
            Merge(f[i+a[o].y],f[i],a[o].x);
        }
        R+=a[o].y;
    }
    printf("%lld\n",ans);
    
	cerr<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 14444kb

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

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: 0ms
memory: 14260kb

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

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

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

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: 9ms
memory: 14568kb

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: 25ms
memory: 15408kb

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
Wrong Answer
time: 273ms
memory: 19288kb

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:

19182910711

result:

wrong answer 1st numbers differ - expected: '23477878007', found: '19182910711'