Below is the link to question:
Here is my solution ,I dont know in which case its failing:
#include<iostream>
#include<cstdio>
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main()
{
FAST_IO
int T,N,M,Q;
cin>>T;
while(T--)
{
cin>>N>>M;
long long int A[N],B[M],sum_A=0,sum_B=0 , n,L,R,X;;
for(int i=0;i<N;i++)
{
cin>>A[i];
sum_A=sum_A+A[i];
}
for(int i=0;i<M;i++)
{
cin>>B[i];
sum_B=sum_B+B[i];
}
cin>>Q;
while(Q--)
{
cin>>n;
if(n==1)
{
cin>>L>>R>>X;
sum_A=sum_A+((R-L+1)*X);
}
else if(n==2)
{
cin>>L>>R>>X;
sum_B=sum_B+((R-L+1)*X);
}
else
{
long long int sum=0;
sum=((sum_A%998244353)*(sum_B%998244353))%998244353;
cout<<sum<<"\n";
}
}
}
return 0;
}
carre
2
In queries of type 1 and 2, when you add values to sum_a or sum_b, do it using the modular addition
I have modified the code but still getting wrong answer:
#include<iostream>
#include<cstdio>
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main()
{
FAST_IO
int T,N,M,Q;
cin>>T;
while(T--)
{
cin>>N>>M;
long long int A[N],B[M],sum_A=0,sum_B=0 , n,L,R,X;;
for(int i=0;i<N;i++)
{
cin>>A[i];
sum_A=((sum_A%998244353)+(A[i]%998244353))%998244353;
}
for(int i=0;i<M;i++)
{
cin>>B[i];
sum_B=((sum_B%998244353)+(B[i]%998244353))%998244353;
}
cin>>Q;
while(Q--)
{
cin>>n;
if(n==1)
{
cin>>L>>R>>X;
sum_A=((sum_A%998244353)+(((R-L+1)*X)%998244353))%998244353;
}
else if(n==2)
{
cin>>L>>R>>X;
sum_B=((sum_B%998244353)+(((R-L+1)*X)%998244353))%998244353;
}
else
{
long long int sum=0;
sum=((sum_A%998244353)*(sum_B%998244353))%998244353;
cout<<sum<<"\n";
}
}
}
return 0;
}
carre
4
you are not doing the modular addition correctly, numbers can be negative. Check this CodeChef: Practical coding for everyone