The question I saw was stated: You are given an array A of size N. An element Ai is said to be charged if its value(Ai) is greater than or equal to Ki and Ki is the total number of subsets of the array A, that contains an element Ai.
The logic is simply the number of times a number comes as a subset is 2^N-1 times. But in some test cases, N was 4000+. so, 2^N-1 will be way beyond any variable type can hold but in editorial, the writer used 1ll<<(N-1)
. I know the left shift operator is X<<Y = X*2^Y
. But what is this 1ll? And how is it able to store such large value?
#include <bits/stdc++.h>
#define M 1000000007
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
long long arr[N];
for (int i = 0; i < N; i++)
cin >> arr[i];
if (N >= 64)
cout << 0 << endl;
else {
long long val = (1ll << (N - 1));
long long ans = 0;
for (int i = 0; i < N; i++)
if (arr[i] >= val)
ans = (ans + arr[i] % M) % M;
cout << ans << endl;
}
}
}
1<<N-1
explains 2^N-1 but does the 1ll means that it can take upto long long and long long val = 1ll<<N-1
; means it can go upto 128bit?