Pagini recente » Cod sursa (job #1749176) | Cod sursa (job #185011) | Cod sursa (job #2943132) | Cod sursa (job #3139173) | Cod sursa (job #197578)
Cod sursa(job #197578)
#include<iostream>
#include<fstream.h>
using namespace std;
ifstream fin("gropi.in");
ofstream fout("gropi.out");
long long int c,x,y,y1,y2,timp,t;
int n=100000,m,a[2][1000000],x1,x2;
void citirea();
int rez(long long i,long long ii){
if(i==ii){
if(x1!=x2) return 2;
else return 1;
}
else{
t=0;
if(i<ii){
int ind=x1;
while(i!=ii){
if(a[ind][i+1]){ ind=!ind;t++;}
i++;
t++;
}
if (ind!=x2) t++;
}
else{
int ind=x2;
while(i!=ii){
if(a[ind][ii+1]){ ind=!ind;t++;}
ii++;
t++;
}
if (ind!=x1) t++;
}
t++;
return t;
}
}
void citirea(){
fin>>c>>n;
for(int i=0; i<n; i++){
fin>>x>>y;
y--;x--;
a[x][y]=1;
}
fin>>m;
}
int main(){
citirea();
for (int i=0; i<m;i++){
fin>>x1>>y1>>x2>>y2;
x1--;y1--;x2--;y2--;
timp=rez(y1,y2);
fout<<timp<<endl;
}
/*for(int i=0; i<c; i++){
cout<<a[0][i]<<" "<<a[1][i]<<endl;
}*/
fin.close();
fout.close();
return 0;
}