#include <iostream>
#include <bitset>
using namespace std;
long long n, k, a, wynik, x;
bitset<500005> occ;
int main()
{
scanf("%lld%lld", &n, &k);
for(int i = 1; i <= n; ++i){
scanf("%lld", &a);
if(!occ.test(a)){
--k;
wynik += x;
occ.flip(a);
}
else{
++x;
}
if(!k){
printf("%lld", wynik);
return 0;
}
}
printf("-1");
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 | #include <iostream> #include <bitset> using namespace std; long long n, k, a, wynik, x; bitset<500005> occ; int main() { scanf("%lld%lld", &n, &k); for(int i = 1; i <= n; ++i){ scanf("%lld", &a); if(!occ.test(a)){ --k; wynik += x; occ.flip(a); } else{ ++x; } if(!k){ printf("%lld", wynik); return 0; } } printf("-1"); return 0; } |
English