//#include //using namespace std; //using ll=long long; //const ll ILL=2167167167167167167; //const int INF=2100000000; //#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++) //#define all(p) p.begin(),p.end() //template using _pq = priority_queue, greater>; //template int LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} //template int UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} //template bool chmin(T &a,T b){if(b bool chmax(T &a,T b){if(a void So(vector &v) {sort(v.begin(),v.end());} //template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} //bool yneos(bool a,bool upp=false){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;} //template void vec_out(vector &p,int ty=0){ // if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'< T vec_min(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} //template T vec_max(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} //template T vec_sum(vector &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;} //int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;} //template T square(T a){return a * a;} // // //#include "po167_library/modint/mint61.hpp" //using mint = po167::mint61; //random_device seed_gen; //mt19937 rng(seed_gen()); //// return [l, r) //long long rand_long(long long l,long long r){ // return uniform_int_distribution(l,r-1)(rng); //} // //#include //mint op(mint a, mint b){ // return a + b; //} //mint e(){ // return 0; //} // //void solve(); //// POP'N ROLL MUSIC / TOMOO //int main() { // ios::sync_with_stdio(false); // cin.tie(nullptr); // // int t = 1; // // cin >> t; // rep(i, 0, t) solve(); //} // //void solve(){ // mint base = rand_long(1, mint::MOD); // mint inv = base.pow(mint::MOD - 2); // // inv = 10; // // base = inv.pow(mint::MOD - 2); // int H, W; // cin >> H >> W; // vector p = {0, 1, 2, -1, -1, 5, 9, -1, 8, 6}; // int N; // cin >> N; // struct query{ // int ty; // int x; // int l; // int r; // }; // vector> q(2); // rep(i, 0, N){ // int a, b, c; // cin >> a >> b >> c; // a--, b--; // q[0].push_back({-1, a, b, c}); // q[1].push_back({-1, H - a - 1, W - b - 1, p[c]}); // } // int Q; // cin >> Q; // rep(i, 0, Q){ // int l, d, r, u; // cin >> l >> d >> r >> u; // l--, d--; // rep(rp, 0, 2) { // q[rp].push_back({i, l, d, u}); // q[rp].push_back({i, r, d, u}); // swap(l, r); // swap(d, u); // l = H - l; // r = H - r; // d = W - d; // u = W - u; // } // } // vector ans(2, vector(Q)); // rep(i, 0, 2){ // sort(all(q[i]), [&](query l, query r){ // if (l.x == r.x) return l.ty > r.ty; // return l.x < r.x; // }); // atcoder::segtree seg(W); // vector seen(Q); // for (auto x : q[i]){ // if (x.ty == -1){ // seg.set(x.l, seg.get(x.l) + base.pow((ll)(H) * x.x + x.l) * x.r); // } // else{ // // if (x.ty == 5) cout << x.x << " " << x.l << " " << x.r << "\n"; // ans[i][x.ty] *= -1; // ans[i][x.ty] += seg.prod(x.l, x.r); // seen[x.ty]++; // if (seen[x.ty] == 2){ // ans[i][x.ty] *= inv.pow((ll)(H) * x.x + x.r); // } // } // } // } // rep(i, 0, Q){ // // cout << ans[0][i].x << " " << ans[1][i].x << "\n"; // yneos(ans[0][i] == ans[1][i]); // } //} // #line 1 "e.cpp" #include using namespace std; using ll=long long; const ll ILL=2167167167167167167; const int INF=2100000000; #define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++) #define all(p) p.begin(),p.end() template using _pq = priority_queue, greater>; template int LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template int UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,T b){if(b bool chmax(T &a,T b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} bool yneos(bool a,bool upp=false){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;} template void vec_out(vector &p,int ty=0){ if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'< T vec_min(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} template T vec_max(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} template T vec_sum(vector &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;} int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;} template T square(T a){return a * a;} #line 2 "/Users/Shared/po167_library/modint/mint61.hpp" // https://qiita.com/keymoon/items/11fac5627672a6d6a9f6 namespace po167{ struct mint61{ using u64 = unsigned long long; static constexpr u64 MOD = (1ULL << 61) - 1; static constexpr u64 MASK30 = (1ULL << 30) - 1; static constexpr u64 MASK31 = (1ULL << 31) - 1; u64 x; u64 calcmod(u64 a){ u64 au = (a >> 61); u64 ad = (a & MOD); u64 res = au + ad; if (res >= MOD) res -= MOD; return res; } mint61(){ x = 0;} mint61(long long x_){ while (x_ < 0) x_ += MOD; x = calcmod(x_); } mint61 &operator+=(mint61 b){ if ((x += b.x) >= MOD) x -= MOD; return *this; } mint61 &operator-=(mint61 b){ if (x >= b.x) x -= b.x; else{ x += MOD; x -= b.x; } return *this; } mint61 &operator*=(mint61 b){ u64 au = (x >> 31); u64 ad = (x & MASK31); u64 bu = (b.x >> 31); u64 bd = (b.x & MASK31); u64 mid = ad * bu + au * bd; u64 midu = (mid >> 30); u64 midd = (mid & MASK30); x = calcmod(au * bu * 2 + midu + (midd << 31) + ad * bd); return *this; } friend mint61 operator+(mint61 a, mint61 b){return a += b;} friend mint61 operator-(mint61 a, mint61 b){return a -= b;} friend mint61 operator*(mint61 a, mint61 b){return a *= b;} friend bool operator==(mint61 a, mint61 b){return a.x == b.x;} friend bool operator!=(mint61 a, mint61 b){return a.x != b.x;} mint61 pow(long long e) const { mint61 r = 1,b =*this; if (e < 0) e = MOD - 1 + e % (MOD - 1); while (e){ if (e & 1) r *= b; b *= b; e >>= 1; } return r; } }; } #line 27 "e.cpp" using mint = po167::mint61; random_device seed_gen; mt19937 rng(seed_gen()); // return [l, r) long long rand_long(long long l,long long r){ return uniform_int_distribution(l,r-1)(rng); } #include mint op(mint a, mint b){ return a + b; } mint e(){ return 0; } void solve(); // POP'N ROLL MUSIC / TOMOO int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; rep(i, 0, t) solve(); } void solve(){ mint base = rand_long(1, mint::MOD); mint inv = base.pow(mint::MOD - 2); // inv = 10; // base = inv.pow(mint::MOD - 2); int H, W; cin >> H >> W; vector p = {0, 1, 2, -1, -1, 5, 9, -1, 8, 6}; int N; cin >> N; struct query{ int ty; int x; int l; int r; }; vector> q(2); rep(i, 0, N){ int a, b, c; cin >> a >> b >> c; a--, b--; q[0].push_back({-1, a, b, c}); q[1].push_back({-1, H - a - 1, W - b - 1, p[c]}); } int Q; cin >> Q; rep(i, 0, Q){ int l, d, r, u; cin >> l >> d >> r >> u; l--, d--; rep(rp, 0, 2) { q[rp].push_back({i, l, d, u}); q[rp].push_back({i, r, d, u}); swap(l, r); swap(d, u); l = H - l; r = H - r; d = W - d; u = W - u; } } vector ans(2, vector(Q)); rep(i, 0, 2){ sort(all(q[i]), [&](query l, query r){ if (l.x == r.x) return l.ty > r.ty; return l.x < r.x; }); atcoder::segtree seg(W); vector seen(Q); for (auto x : q[i]){ if (x.ty == -1){ seg.set(x.l, seg.get(x.l) + base.pow((ll)(H) * x.x + x.l) * x.r); } else{ // if (x.ty == 5) cout << x.x << " " << x.l << " " << x.r << "\n"; ans[i][x.ty] *= -1; ans[i][x.ty] += seg.prod(x.l, x.r); seen[x.ty]++; if (seen[x.ty] == 2){ ans[i][x.ty] *= inv.pow((ll)(H) * x.x + x.r); } } } } rep(i, 0, Q){ // cout << ans[0][i].x << " " << ans[1][i].x << "\n"; yneos(ans[0][i] == ans[1][i]); } }