60 bits
answer to 60 bits questionsunknown
c_cpp
a year ago
2.1 kB
9
Indexable
// #include<stdio.h> // long long int modulus=1000000007; // long long int power(long long int base, long long int exponent) // { // if (exponent == 0) // return 1; // else if (exponent % 2 == 0) // return power((base * base) % modulus, exponent / 2) % modulus; // else // return (base * power((base * base) % modulus, (exponent - 1) / 2)) % modulus; // } // int main() // { // int n; // long long int pro=1; // scanf("%d",&n); // long long int a[n],b[n]; // for(int i=0;i<n;i++) // scanf("%lld",&a[i]); // for(int i=0;i<n;i++) // scanf("%lld",&b[i]); // for(int i = 0; i < n; i++) // { // long long int product=((long long int)(power(a[i],b[i]))); // pro=(pro*product)%modulus; // } // printf("%lld",pro); // return 0; // } #include <stdio.h> int n, k; long long a[100005], satisfied[60]; int current_satisfied, max_satisfied; int max_clients() { int i, j; for (i = 0; i < k; i++) { for (j = 0; j < 60; j++) { if (a[i] & (1LL << j)) { if (satisfied[j] == 0) current_satisfied++; satisfied[j]++; } } } max_satisfied = current_satisfied; for (i = k; i < n; i++) { for (j = 0; j < 60; j++) { if (a[i - k] & (1LL << j)) { satisfied[j]--; if (satisfied[j] == 0) current_satisfied--; } if (a[i] & (1LL << j)) { if (satisfied[j] == 0) current_satisfied++; satisfied[j]++; } } if (current_satisfied > max_satisfied) max_satisfied = current_satisfied; } return max_satisfied; } int main() { scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); printf("%d\n", max_clients()); return 0; }
Editor is loading...