Hello. I was trying to solve Problem C, and used the following approach.
Using dynamic programming, for all dp(i, j) such that i, j >= 1 if dp(i, j-1) = 0 || dp(i+1, j) = 0 || sum from index i to j = 0, then dp(i, j) = 0 else dp(i, j) = 1

Can someone please help me with this problem? Is the dp approach that I’m using correct?
The problem is that in pretest 3, the value of N = 2 x 10^5. Please help.

What i did was i calculated ans like how many subarrays ending at ith index have a subsegment with sum=0,so all those for each index i-I calculated the largest index j(j<=i) such that sum(j,i)=0,so we cant include the subarrays with starting point <=j ,if there is no subarrys ending at ith position having sum=0,then we just add the maximum value of starting index occured previously because
since we have calculated ans for subarrays ending at [1,i-1] if for current index i we cant include those with starting index<=max starting index uptil now so just add ans+=(max starting index uptil now),if(there is a subarray ending at ith position having sum 0 and starting at pos=j){
if(max starting index<j)ans+=j,max starting index=j;
else ans+=max starting index
}
and finally ans=n*(n+1)/2 - ans
my solution :https://codeforces.com/contest/1333/submission/75895071