while trying this problem ,i faced a very strange doubt.
while declaring array x and y locally i am getting wrong answer ,but at the same time if i declare the arrays x and y globally i am getting correct answer…why is this happenning?
why such thing ?? please help
#include <bits/stdc++.h>
using namespace std;
int main() {
int x[1000010],y[1000010];
int b;
cin>>b;
while(b--)
{
int xmin=1e7,xmax=0,ymin=1e7,ymax=0;
for (int i=0;i<3;i++)
{
int xa,ya;
cin>>xa>>ya;
xmin=min(xmin,xa);
xmax=max(xmax,xa);
ymin=min(ymin,ya);
ymax=max(ymax,ya);
}
xmin++;ymin++;
x[xmin]++;
y[ymin]++;
x[xmax]--;
y[ymax]--;
}
for (int i=1;i<1000010;i++)
{
x[i]+=x[i-1];
y[i]+=y[i-1];
}
int f;
cin>>f;
while(f--)
{
char a;char b;int i;
cin>>a>>b>>i;
if (a=='x')
{
cout<<x[i]<<endl;
}
else
cout<<y[i]<<endl;
}
return 0;
}