I was watching the editorial of weird values problem and copied the code from there with one modificaiton.
I replaced for(int i=1;i<(int)(size(indsx))-x;i++)
with for(ll i=1;i<indsx.size()-x;i++)
and it is giving segmentation fault on submitting. Although, it is passing the sample test cases.
Can someone guide me why?
#include"bits/stdc++.h"
#define ll long long int
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
vector<vector<ll>> inds(n+1);
for(ll i=1;i<=n;i++)
{
ll x;
cin>>x;
if(x<=n)
inds[x].push_back(i);
}
ll ans=0;
for(ll x=1;x<=n;x++)
{
vector<ll> indsx=inds[x];
indsx.insert(begin(indsx),0);
indsx.push_back(n+1);
for(ll i=1;i<indsx.size()-x;i++)
{
ans+=x*(indsx[i]-indsx[i-1])*(indsx[i+x]-indsx[i+x-1]);
}
}
cout<<ans<<"\n";
}
return 0;
}```