//Jakub Rozek
//Oranżada
//czas: n
//pamiec: n/32
#include "bits/stdc++.h"
using namespace std;
const int N=500005;
long long n,k,x,odp,w;
bitset <N> tb;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>k;
for(int i=1; i<=n; ++i)
{
cin>>x;
if(tb[x]) ++w;
else
{
tb[x]=1;
odp+=w;
--k;
}
if(k==0) break;
}
if(k) cout<<"-1";
else cout<<odp;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | //Jakub Rozek //Oranżada //czas: n //pamiec: n/32 #include "bits/stdc++.h" using namespace std; const int N=500005; long long n,k,x,odp,w; bitset <N> tb; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>k; for(int i=1; i<=n; ++i) { cin>>x; if(tb[x]) ++w; else { tb[x]=1; odp+=w; --k; } if(k==0) break; } if(k) cout<<"-1"; else cout<<odp; return 0; } |
English