Why my code is not giving output?
Why the code i not giving output?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int co(int *ar,int n,int u, int v)
{
int c=0;
for(int i=u; i<=v; i++)
{
if(ar[u]==n)
c++;
}
return c;
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);
int t;
cin>>t;
for(int i=1; i<=t; i++)
{
int n;
cin>>n;
int ar[n];
for(int i=1; i<=n; i++)
cin>>ar[i];
int r;
cin>>r;
while(r--)
{
int u,v,c,sum=0;
cin>>u>>v;
for(int i=u; i<=v;i++)
{
c=co(ar,ar[i],u,v);
if(c%2==1)
sum++;
}
cout<<sum<<endl;
}
}
return 0;
}
|
Last edited on
undefined behaviour in the loop of line 31 (out of bounds access)
also possible in line 44
It would help the testing if you provide an example input.
Topic archived. No new replies allowed.