Pagini recente » Cod sursa (job #191232) | Cod sursa (job #1512387) | Cod sursa (job #1587811) | Cod sursa (job #2572485) | Cod sursa (job #197643)
Cod sursa(job #197643)
#include<fstream.h>
#include<stdlib.h>
#include<fstream.h>
int main()
{
ifstream fin("gropi.in");
ofstream fout("gropi.out");
long c,n,m,g[300]={0},h[300]={0};
fin>>c>>n;
long a,b,l=0;
long i=0,j=0,unu,doi;
for (i=0;i<n;i++)
for (j=0;j<1;j++)
{
fin>>a>>b;
if (a==1)
if (b<300)
g[b]++;
if (a==2)
if (b<300)
h[b]++;
}
fin>>m;
int juca=0,jucb=0;
for (i=0;i<c;i++)
{
if (g[i]==0)
g[i]=juca;
else
{
juca++;
g[i]=juca;
}
if (h[i]==0)
h[i]=jucb;
else
{
jucb++;
h[i]=jucb;
}
}
long q,w,e,r;
for (i=0;i<m;i++)
{
fin>>q>>w>>e>>r;
long big,small;
if (w>r)
{
big=w;
small=r;
}
else
{
big=r;
small=w;
}
long aprox=big-small+1;
if (q==e==1)
aprox=aprox+g[big]-g[small];
if (q==e==2)
aprox=aprox+h[big]-h[small];
if (q!=e)
{
int med=((g[big]-g[small])+(h[big]-h[small]))/2;
aprox=aprox+med;
}
fout<<aprox<<'\n';
}
fin.close();
fout.close();
return 0;
}