QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#774553#5459. Goose, goose, DUCK?Yurily#WA 4ms13884kbC++202.1kb2024-11-23 13:26:022024-11-23 13:26:02

Judging History

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

  • [2024-11-23 13:26:02]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:13884kb
  • [2024-11-23 13:26:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAX=1e6+6;
int n,k;
int mins[MAX*4],tag[MAX*4],a[MAX],d[MAX][2],nxt[MAX],cnt[MAX*4];
vector<int> g[MAX];
long long ans;
void add(int k,int l,int r,int v){
    tag[k]+=v;
    mins[k]+=v;
}
void pushdown(int k,int l,int r){
    if(!tag[k])
        return;
    int mid=l+r>>1;
    add(k<<1,l,mid,tag[k]);
    add(k<<1|1,mid+1,r,tag[k]);
    tag[k]=0;
}
void modify(int k,int l,int r,int x,int y,int v){
    if(l>=x&&r<=y){
        return add(k,l,r,v);
    }

    pushdown(k,l,r);

    int mid=l+r>>1;
    if(x<=mid){
        modify(k<<1,l,mid,x,y,v);
    }
    if(mid<y){
        modify(k<<1|1,mid+1,r,x,y,v);
    }

    mins[k]=min(mins[k<<1],mins[k<<1|1]);
    cnt[k]=0;
    if(mins[k<<1]==mins[k])
        cnt[k]+=cnt[k<<1];
    if(mins[k<<1|1]==mins[k])
        cnt[k]+=cnt[k<<1|1];
}
void build(int k,int l,int r){
    if(l==r){
        cnt[k]=1;
        return;
    }
    int mid=l+r>>1;
    build(k<<1,l,mid);
    build(k<<1|1,mid+1,r);
    cnt[k]=cnt[k<<1]+cnt[k<<1|1];
}
int main(){
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    cin>>n>>k;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        g[a[i]].push_back(i);
    }

    build(1,1,n);
    for(int i=1;i<=(int)1e6;++i){
        for(int j=0;j<(int)g[i].size()-k+1;++j){
            d[g[i][j]][0]=g[i][j+k-1];
            if(j!=(int)g[i].size()-1-k+1){
                nxt[g[i][j]]=g[i][j+1];
                d[g[i][j]][1]=g[i][j+k];
            }
            else{
                d[g[i][j]][1]=n;
            }
            if(j==0){
                modify(1,1,n,d[g[i][j]][0],d[g[i][j]][1],1);
            }
        }
    }

    for(int i=1;i<=n;++i){
        if(mins[1]==0){
            ans+=n-cnt[1];
        }
        else{
            ans+=n;
        }
        if(d[i][0]){
            modify(1,1,n,d[i][0],d[i][1],-1);
        }
        if(nxt[i]){
            modify(1,1,n,d[nxt[i]][0],d[nxt[i]][1],1);
        }
    }

    cout<<1LL*n*(n+1)/2-ans;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 11904kb

input:

6 2
1 2 2 1 3 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 0ms
memory: 13884kb

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 11788kb

input:

100 10
142826 764475 142826 986320 764475 142826 142826 986320 764475 986320 764475 764475 764475 142826 142826 986320 764475 986320 764475 764475 142826 764475 142826 764475 986320 986320 764475 142826 764475 764475 142826 764475 764475 986320 142826 142826 142826 142826 764475 986320 986320 764475...

output:

4152

result:

wrong answer 1st numbers differ - expected: '4309', found: '4152'