QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#714400#5459. Goose, goose, DUCK?WzyWA 0ms3824kbC++14922b2024-11-05 23:02:052024-11-05 23:02:05

Judging History

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

  • [2024-11-05 23:02:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3824kb
  • [2024-11-05 23:02:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef  long long LL;
typedef pair<int,int> PII;
const int N=2e5+10,M=1e6+10;
const int mod=1e9+7;
int INF = 1e9;

 
void solve(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n),f(n+10);
    map<int,vector<int>> mp;

    for(int i=0;i<n;i++) cin>>a[i];

    for(int i=0;i<n;i++){
        mp[a[i]].push_back(i);
    }
    for(int i=0;i<n;i++) f[i]=-1;
    for(auto [x,y]:mp){
        if(y.size()<k) continue;

        for(int j=k-1;j<y.size();j++) f[y[j]]=max(f[y[j]],y[j-k+1]);
    }

    LL res=0;



    for(int i=0;i<n;i++){
        if(i) f[i]=max(f[i],f[i-1]);

        //cout<<f[i]<<endl;

        res+=f[i]+1;
    }

    res=(LL)n*(n+1)/2-res;

    cout<<res<<endl;

}
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T=1;
    //cin>>T;
    while(T--) solve();
 
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3824kb

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:

1943

result:

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