QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#240627 | #5459. Goose, goose, DUCK? | ucup-team1769# | WA | 3ms | 30524kb | C++20 | 975b | 2023-11-05 17:04:05 | 2023-11-05 17:04:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1000100;
int a[N];
vector<int>pos[N];
vector<array<int,2>> seg,seg1;
queue<int>q;
int c[N];
void modify(int x,int d){
for(;x<=N;x+=x&-x) c[x]+=d;
}
int query(int x){
int s=0;
for(;x;x-=x&-x) s+=c[x];
return s;
}
int main(){
int n,k;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
pos[a[i]].push_back(i);
}
for(int i=1;i<=n;i++){
int x=a[i];
if(pos[x].size()>=k){
seg.push_back({i,pos[x][k-1]});
pos[x].erase(pos[x].begin());
}
}
int lst=0;
long long ans=0;
sort(seg.begin(),seg.end());
reverse(seg.begin(),seg.end());
for(int i=0;i<seg.size();i++){
if(query(seg[i][1])==0)
seg1.push_back({seg[i][0],seg[i][1]});
modify(seg[i][1],1);
}
sort(seg1.begin(),seg1.end());
for(auto [x,y]:seg1){
//cout<<x<<" "<<y<<endl;
ans=ans+1ll*(x-lst)*(n-y+1);
lst=x;
}
printf("%lld\n",1ll*n*(n-1)/2+n-ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 30448kb
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: 30448kb
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: 30524kb
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'