QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#449406#5459. Goose, goose, DUCK?ship2077WA 4ms29148kbC++171.5kb2024-06-21 08:40:242024-06-21 08:40:24

Judging History

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

  • [2024-06-21 08:40:24]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:29148kb
  • [2024-06-21 08:40:24]
  • 提交

answer

#include<bits/stdc++.h>
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
using namespace std;
constexpr int M=1e6+5;
vector<int>pos[M];
int n,k,a[M],mp[M];long long ans;
struct segtree{int mn,cnt,lazy;}tr[M<<2];
int read(){
    int x=0;char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
    return x;
}
void addtag(int x,int c){tr[x].mn+=c;tr[x].lazy+=c;}
void pushdown(int x){if (tr[x].lazy) addtag(ls(x),tr[x].lazy),addtag(rs(x),tr[x].lazy),tr[x].lazy=0;}
void pushup(int x){tr[x].mn=min(tr[ls(x)].mn,tr[rs(x)].mn);tr[x].cnt=(tr[x].mn==tr[ls(x)].mn?tr[ls(x)].cnt:0)+(tr[x].mn==tr[rs(x)].mn?tr[rs(x)].cnt:0);}
void build(int l,int r,int x){
    tr[x].cnt=r-l+1; if (l==r) return; int mid=l+r>>1;
    build(l,mid,ls(x));build(mid+1,r,rs(x));
}
void update(int L,int R,int c,int l=0,int r=n,int x=1){
    if (L<=l&&r<=R) return addtag(x,c);
    int mid=l+r>>1;pushdown(x);
    if (L<=mid) update(L,R,c,l,mid,ls(x));
    if (R>mid) update(L,R,c,mid+1,r,rs(x));
    pushup(x);
}
int main(){
    n=read();k=read(); build(0,n,1);
    for (int i=1;i<=n;i++) a[i]=read();
    for (int i=1;i<=n;i++)
        if (!mp[a[i]]) mp[a[i]]=1,
            pos[a[i]].emplace_back(0);
    for (int i=1;i<=n;i++){
        const int x=a[i];
        if (pos[x].size()>k)
            update(pos[x][k-1]+1,pos[x][k],-1);
        pos[x].emplace_back(i);
        if (pos[x].size()>k)
            update(pos[x][k-1]+1,pos[x][k],1);
        ans+=tr[1].cnt-(n-i+1);
    }
    printf("%lld\n",ans);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 27820kb

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

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 27432kb

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:

4622

result:

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