QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#714432#5459. Goose, goose, DUCK?WzyWA 0ms3612kbC++141.1kb2024-11-05 23:12:072024-11-05 23:12:08

Judging History

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

  • [2024-11-05 23:12:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-11-05 23:12:07]
  • 提交

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),d(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++) d[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]);
        for(int j=k;j<y.size();j++) d[y[j]]=max(d[y[j]],y[j-k]);
    }

    LL res=0;



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

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

        if(d[i]>=f[i]) continue;
        res+=f[i]-d[i];
    }
    //cout<<endl;

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

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

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

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:

4836

result:

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