CodeForce Round 578 Div 2 C. Round Corridor

C. Round Corridor

Problem

Amugae is in a very large round corridor. The corridor consists of two areas. The inner area is equally divided by n n n sectors, and the outer area is equally divided by m m m sectors. A wall exists between each pair of sectors of same area (inner or outer), but there is no wall between the inner area and the outer area. A wall always exists at the 12 o’clock position.

在这里插入图片描述

The inner area’s sectors are denoted as ( 1 , 1 ) , ( 1 , 2 ) , … , ( 1 , n ) (1,1),(1,2),…,(1,n) (1,1),(1,2),,(1,n) in clockwise direction. The outer area’s sectors are denoted as ( 2 , 1 ) , ( 2 , 2 ) , … , ( 2 , m ) (2,1),(2,2),…,(2,m) (2,1),(2,2),,(2,m) in the same manner. For a clear understanding, see the example image above.

Amugae wants to know if he can move from one sector to another sector. He has q q q questions.

For each question, check if he can move between two given sectors.

Input

The first line contains three integers $ n , m , q (1 \leq n,m \leq 10^{18}, 1 \leq q \leq 10^4) $— the number of sectors in the inner area, the number of sectors in the outer area and the number of questions.

Each of the next q q q lines contains four integers s x , s y , e x , e y ( 1 ≤ s x , e x ≤ 2 s_x, s_y, e_x, e_y (1 \leq s_x,e_x \leq 2 sx,sy,ex,ey(1sx,ex2; if$ s_x=1 , t h e n , then ,then 1 \leq s_y \leq n$, otherwise 1 ≤ s y ≤ m 1 \leq s_y \leq m 1sym; constraints on e y e_y ey are similar). Amague wants to know if it is possible to move from sector$ (s_x,s_y) t o s e c t o r to sector tosector (e_x,e_y)$.

Output

For each question, print “YES” if Amugae can move from ( s x , s y ) (sx,sy) (sx,sy) to ( e x , e y ) (ex,ey) (ex,ey), and “NO” otherwise.

You can print each letter in any case (upper or lower).

Example

input

4 6 3
1 1 2 3
2 6 1 2
2 6 2 4

output

YES
NO
YES

Note

Example is shown on the picture in the statement.

想法

看到图就想到内圈每隔 x x x个,外圈每隔 y y y个,形成一个自闭组,那么这有什么关系吗?

有,每隔几个每隔几个,就是gcd的意义啊

那么思路清晰了,计算他们的gcd,就是最大公约数——代表着他们同时分成多少大自闭组,再分别用内外圈总数/自闭组数,就是内外圈每个自闭组包含几个单位范围,再确定询问的位置是否属于同一个自闭组,判断即可

The Code Of My Program

/*********************
*@Author:   ChenShou *
*@Language: C++11    *
*********************/
//#include <bits/stdc++.h> 
#pragma comment(linker, "/STACK:102400000,102400000")
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
 
//#define DEBUG
#define RI register int
#define endl "\n"
 
using namespace std;
typedef long long ll;
//typedef __int128 lll;
//const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-9;
const int INF = 0x3f3f3f3f;
 
inline ll read(){
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f; 
}
 
 
int main()
{
#ifdef DEBUG
    freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
#endif
    //cout.tie(0);
    ll n=read(),m=read(),q=read();
    ll ggcd=__gcd(n,m);
    while(q--){
	ll x_1=read(),y_1=read(),x_2=read(),y_2=read();
	if(x_1!=x_2){
		if(x_1==2&&x_2==1)swap(y_1,y_2);
	    ll num_1=n/ggcd,num_2=m/ggcd;
	    ll no_1=y_1/num_1,no_2=y_2/num_2;
	    if(y_1%num_1)no_1++;
	    if(y_2%num_2)no_2++;
	    if(no_1==no_2){
	    	printf("YES\n");
	    }
	    else printf("NO\n");
	}
	else if(x_1==1){
		ll num_1=n/ggcd,num_2=n/ggcd;
	    ll no_1=y_1/num_1,no_2=y_2/num_1;
	    if(y_1%num_1)no_1++;
	    if(y_2%num_1)no_2++;
	    if(no_1==no_2){
	    	printf("YES\n");
	    }
	    else printf("NO\n");
	}
	else {
		ll num_1=m/ggcd,num_2=m/ggcd;
	    ll no_1=y_1/num_1,no_2=y_2/num_2;
	    if(y_1%num_1)no_1++;
	    if(y_2%num_2)no_2++;
	    if(no_1==no_2){
	    	printf("YES\n");
	    }
	    else printf("NO\n");
	}
}
    //continue;
#ifdef DEBUG
    printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
    //cout << "Fuck You !" << endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值