bro i m not able to understand your code or your approach …why so much complex approach when u can solve this in very easy manner
i have done the same mistake. take n as input and calculate n*(n+1)/2 which can be greater than int.
that is the problem. just take n as long
Overflow 
Might come as a surprise but even python has a limit. Its around 10^{7000} or something for value of variables. Once you cross this, you get a runtime error.
Code 1
if (a[i] % 2 == 0)
a[i] = 1
else
a[i] = 0
Code 2
if (a[i] % 2 == 1)
a[i] = 0
else
a[i] = 1
I used Code 1 and I had AC but I used Code 2 and had WA. I’m trying to understand why. Any idea?
can anyone where I am getting wrong ,I tried a brute force approach to the problem and its giving correct outputs as per me .Link to the code is below,please help and thanks.
https://www.codechef.com/viewsolution/31680208
I did the same but it get wrong answer in two cases… Please review it… Thanks… CodeChef: Practical coding for everyone
Could you please explain it a bit more ? Why sum = 1 works ?
2,6,10,14,18,22… this is series they all no. are do not give the pp-qq result.
so all they no. if we identify then we see that all no. are devided by 4 remainder ==2
2%4==2
6%4==2
10%4==2
so why we need to calculate temp%4==0 or temp%4!=0
Does that mean If sum = 1 then the product has only one 2 in prime factor. And that’s why It doesn’t count
How can it be N*logN?
Please help?
And how will O(N) pass the test cases?
the constraints specify that
N over all test cases does not exceed 10^6
and there are 10^3 tests cases
then for O(N) there are 10^3 * 10^6 = 10^9 operations
how will O(N ) pass the test cases?
Yeah absolutely right
squared subsequence
i tried to implement the editorial solution but getting only partial marks and cant seem to figure out why?
Can anyone please help?
@ssrivastava90 I followed exactly the same approach but my code is failing in 2 tasks. Please check if you could fix out the bug . Any help is welcomed.
Yes, it is yielding a wrong answer despite passing the given test case . Can anyone tell me why is it so? The logic applied seems to be correct .
my approach is same as yours . but only got WA please have a look.
#include <bits/stdc++.h>
using namespace std;
long long int um(int a[], int n, int sum)
{
unordered_map<long long int,long long int> pum;
long long int res = 0;
long long int cum = 0;
for (int i = 0; i < n; i++) {
cum += a[i];
if (cum == sum)
res++;
if (pum.find(cum - sum) != pum.end())
res += (pum[cum - sum]);
pum[cum]++;
}
return res;
}
int main()
{
int t ;
scanf("%d",&t);
while(t–){
int n,i;
scanf("%d",&n);
int a[n],b[n];
for (i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++){
if (a[i]%4==0)
b[i]=2;
else if(a[i]%2==0)
b[i]=1;
else if(a[i]%2==1)
b[i]=0;
else
b[i]=3; }
long long int k,m=(n*(n+1)/2);
k=m-um(b,n,1);
printf("%lld\n",k);
}
return 0;
}
please look at my solution , Don’t know why it giving WA .
https://www.codechef.com/viewsolution/31565416