Since I cant find the editorial i am asking my doubt here. my code to problem F
https://mirror.codeforces.com/contest/1729/problem/F
is repeatedly failing test case 7.
Here is my code for your reference:
https://mirror.codeforces.com/contest/1729/submission/172019259
thanks
you are trying to cast string to int with
stoi()
but the result is too large to represent it as integer. My local G++ 12.2.0 fails withstd::out_of_range
if i want to cast string '111...1' (length = 1000) to int withstoi()
for exampleim new to cpp. which is a more efficient method to do this cast?
stoi()
is the best. You just can't store 10^100 as a number using fundamental types (like int or long long) in cppi forgot about
stoll()
. This function works likestoi()
but it casts to long long (stoi()
casts to int)string qq=s.substr(l-1,r-l+1); int j=stoi(qq);//here it is exceeding integer limit...
notice that you don't need to store the whole number in 'j' variable ...just store gg%9 in 'j'
but still it will give TLE you need to process all 'w' substrings and store the information in an double dimentional vector and later in queries you can use them in O(1) time :-)