Submission #2850749


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//
bool solve(ll a,ll b,ll c,ll d){
    if (b > d) return false;
    // d >= b

    if (a < b) return false;
    // a >= b

    if (b > c) {
        ll r = a % b;
        ll h = d % b;
        if (r <= c) {
            if (h==0) return true;
            ll g = gcd(h,b);
            //ll g = gcd(d,b);
            h = g;

            ll on_q=(c+1-r)/h, on_r=(c+1-r)%h;
            if (on_r) on_q++;
            ll on = r + on_q*h;
            if (IN(on,c+1,b-1)) return false;

            // if (g == 1) return false;

            //ll w = (b-1-r+g-1)/g - (c+1-r)/g + 1;
            //if (h/g <= w) return false;
#if 0
            {
                h = g;

                ll on_q=(c+1-r)/h, on_r=(c+1-r)%h;
                if (on_r) on_q++;
                ll on = r + on_q*h;
                if (IN(on,c+1,b-1)) return false;
                // h != 0

                ll _h = b - h;
                ll off_q=(r-(-1))/_h, off_r=(r-(-1))%_h;
                if (off_r) off_q++;
                ll off = r - off_q*_h;
                if (IN(off,c+1-b,-1)) return false;
            }
#endif
            return true;
            // || (b-r-1)/h == (c-r)/h) return true;
            // else return false;
        } else {
            // c < r < b
            return false;
        }
    } else {
        // c >= b : always
        if (d < b) return false;
        // d >= b
        return true;
    }
}

int main() {
    int T; cin >> T;
    rep(t,T){
        ll a,b,c,d; cin >> a >> b >> c >> d;
        cout << (solve(a,b,c,d) ? "Yes" : "No") << endl;
    }
    return 0;
}

Submission Info

Submission Time
Task B - rng_10s
User naoya_t
Language C++14 (GCC 5.4.1)
Score 600
Code Size 3348 Byte
Status
Exec Time 2 ms
Memory 256 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 example_0, example_1
All 600 / 600 example_0, example_1, multi_0, multi_1, multi_2
Case Name Status Exec Time Memory
example_0 1 ms 256 KB
example_1 1 ms 256 KB
multi_0 2 ms 256 KB
multi_1 2 ms 256 KB
multi_2 2 ms 256 KB