 # HELP NEEDED for Wrong answer in ALATE problem of Loc august 2017

At first tried brute force so I was able to pass the first task but then for tle I used maps to store my answers I tried every test case which I was able to think with both brute force and this recursive method .
But still, they were giving same answers. Then why I am getting wrong answers?
In 2nd solution which i had designed for avoiding tle I am calculating required answer by two sub methods.
for e.g for 1 2 query, i would first calculate sum of squares of 4,8,12,16,…so on and I am storing each result of func(4), func(8),… as well as func(2) in maps so that I can use it later then why I am getting wrong ans ? PS I had updated my maps after query 2. please look at my solution and tell me whats wrong in that! I had thought about it for hours still was not able to find my mistake

Hello
Same problem here , I can’t find out what is wrong.

My code here : https://www.codechef.com/viewsolution/15155600

func is doing normal calculation but funccont is calculating remaining terms …
for e.g first if i will call for func(2) then what i want a*a + a*a+…a*a----
what i am doing is checking first if(value is present in map or not)… if not present then i would calculate it by calculating first a*a + a*a+… so on and then adding a*a+a*a+a*a…so on … ! i had used ‘s’ in funcont for
for incrementing by 2.x like i want in this in a and then a … so i had used funccont (funct continue :P) i hope now its clear .help me plz !

1 Like

it->second=it->second-A[x-1]A[x-1]%1000000007+yy%1000000007;
But we required only positive answer so you have to Add MOD(1000000007) in your it-> second whenever it-> second < 0
i.e while( it-> second < 0 ) it->second += MOD

https://www.codechef.com/viewsolution/15158824
dude see i had added that line my program but still its showing me WA
your point is correct but what about subtask 1 ? it is way less than MOD then why its showing WA

Hey @cis_pie,

• Use of long instead of long long as A[i] can be as large as possible up to 10^9 than its square would be around 10^18 and this won’t fit in long int.
• Your approach seems a bit wrong, because if all the queries are of type 2 and of the order of 10^5 than it won’t pass in specified time-limit. As it will be traversing the whole map
• it->second=it->second-A[x-1]A[x-1]%1000000007+yy%1000000007; can be negative as well.
• And what if some value that is not queried(1) but has been changed, in that case also your program will not give the value. as that value will not be stored in the map.

Hope any of this helps!