Please help me in finding the erroe in my code

i am not able to pass two test cases
question -sum of length of subarrays with distinct elements

#include<bits/stdc++.h>
using namespace std;
#define endl “\n”
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long int
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll sumoflength(ll a[],ll n)
{ ll mod=1e9+7;
int j=0;
unordered_sets;
ll sum=0;
for(int i=0;i<n;i++)
{
while(j<n && s.find(a[j])==s.end())
{
s.insert(a[i]);
j++;
}
sum+=((j-i)*(j-i+1))/2;
s.erase(a[i]);
}
sum=sum%mod;
return sum;
}

int main()
{
/#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“output.txt”, “w”, stdout);
#endif
/
ll n;
cin>>n;
ll a[n];
for(int i=0;i<n;i++)
cin>>a[i];
ll ans=sumoflength(a,n);
cout<<ans<<endl;

return 0;

}

@be10046.19 here


dont forget to hit like and mark resolved if cleared :smiley:

why was the error coming you only removed the mod

@be10046.19 no see the code i have commented you were inserting a[i] but it should be a[j]

1 Like