QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#774215 | #5459. Goose, goose, DUCK? | Yurily# | WA | 1ms | 5736kb | C++20 | 710b | 2024-11-23 12:28:54 | 2024-11-23 12:29:01 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1000010;
int n,k,a[N],num[N]={0};
vector<pair<int,int> > g;
void sol(){
int l=1;
for(int i=1;i<=n;i++){
num[a[i]]++;
if(num[a[i]]==k){
while(num[a[i]]==k){
num[a[l++]]--;
}
g.push_back(make_pair(i,l));
}
}
g.push_back(make_pair(n+1,n+1));
int ans=n*(n+1)/2,cnt=0;
for(int i=0;i<g.size();i++){
if(i!=0){
cnt+=(g[i].first-g[i-1].first)*(g[i-1].second-1);
}
}
cout<<ans-cnt<<"\n";
}
signed main(){
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
sol();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5644kb
input:
6 2 1 2 2 1 3 3
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5616kb
input:
6 1 1 2 3 4 5 6
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5736kb
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'