how i create an array of 10^9 and store elements on each index
use long long instead of int .
yes i used long long int
but in case of
for(i to 10^9)
a[i]=i
it gives run time error
You cannot store it in an array. Use a vector instead. Its max capacity is 4611686018427387903.
should it depends on machine like 32 bit or 64
in case of long long definitely u can use but there are other reasons for run time error like Invalid memory access during run-time …
I wonder why no one mentioned abt maps
whenever u feel like u need large arrays then the ans is map
can you provide some content for abt maps from where i learn it
geeksforgeeks
cppreference
these are my fav sites for c++
remember u cannot traverse all 10^9 elements coz then u will easily cross ur user id i.e time limit
traversing 10^8 elements takes 1 sec
then 10^9 elements will require 10sec
hence even if u could store 10^9 elements in an array, u won’t be able to traverse it
ohh thanks a lot it help me a lot thanks all of you specifically ganesh92
time limit is best name i think:joy:
also thanks knakul853 for providing that link
this works with 10^8 not with 10^9 why??
#include <iostream>
#define SIZE 100000000
typedef unsigned long long int ulli;
ulli a[SIZE];
int main() {
for (ulli i = 0; i < SIZE; ++i) {
a[i] = i;
}
std::cout << a[99999998] << "\n";
std::cout << a[99999999] << "\n";
}