結果

問題 No.3207 Digital Font
ユーザー pitP
提出日時 2025-07-18 22:44:50
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 4,683 bytes
コンパイル時間 5,582 ms
コンパイル使用メモリ 335,820 KB
実行使用メモリ 51,740 KB
最終ジャッジ日時 2025-07-18 22:45:05
合計ジャッジ時間 10,676 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 18 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
istream &operator>>(istream &is, modint &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint &a) { return os << a.val(); }
istream &operator>>(istream &is, modint998244353 &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint998244353 &a) { return os << a.val(); }
istream &operator>>(istream &is, modint1000000007 &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint1000000007 &a) { return os << a.val(); } 

typedef long long ll;
typedef vector<vector<int>> Graph;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i,l,r) for (int i = l;i < (int)(r); i++)
#define rep(i,n) for (int i = 0;i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define my_sort(x) sort(x.begin(), x.end())
#define my_max(x) *max_element(all(x))
#define my_min(x) *min_element(all(x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<62) - 1;
const int MOD = 998244353;
const int MOD2 = 1e9+7;
const double PI = acos(-1);
vector<int> di = {1,0,-1,0};
vector<int> dj = {0,1,0,-1};

#ifdef LOCAL
#  include <debug_print.hpp>
#  define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define debug(...) (static_cast<void>(0))
#endif

// https://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=9187916#1
struct RollingHash2d{
    static const int B = 3;
    long long base_p[B] = {114514, 1919, 810};
    long long base_q[B] = {765, 961, 283};
    long long mod[B] = {1000000007, 1000000009, 998244353};

    int H, W;
    vector<vector<vector<long long>>> hash;
    vector<vector<long long>> pw_p, pw_q;
    RollingHash2d(vector<vector<int>> &S){
        hash.resize(B);
        pw_p.resize(B);
        pw_q.resize(B);

        H = S.size(), W = S[0].size();
        for(int b = 0; b < B; b++){
            hash[b].resize(H + 1);
            for(int i = 0; i <= H; i++){
                hash[b][i].resize(W + 1, 0);
            }

            for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                    hash[b][i + 1][j + 1] = S[i][j];
                    hash[b][i + 1][j + 1] = (hash[b][i + 1][j + 1] + hash[b][i + 1][j] * base_p[b]) % mod[b];
                    hash[b][i + 1][j + 1] = (hash[b][i + 1][j + 1] + hash[b][i][j + 1] * base_q[b]) % mod[b];
                    hash[b][i + 1][j + 1] = (hash[b][i + 1][j + 1] - (hash[b][i][j] * (base_p[b] * base_q[b]) % mod[b]) % mod[b] + mod[b]) % mod[b];
                }
            }
        }


        for(int b = 0; b < B; b++){
            pw_p[b].resize(W + 1, 1);
            pw_q[b].resize(H + 1, 1);
            for(int i = 0; i < max(H, W); i++){
                if(i < W) pw_p[b][i + 1] = (pw_p[b][i] * base_p[b]) % mod[b];
                if(i < H) pw_q[b][i + 1] = (pw_q[b][i] * base_q[b]) % mod[b];
            }
        }
    }

    // [i1, i2) x [j1, j2)
    vector<long long> get(int i1, int j1, int i2, int j2){
        vector<long long> res(B);
        for(int b = 0; b < B; b++){
            long long P = pw_p[b][j2 - j1], Q = pw_q[b][i2 - i1];
            res[b] = hash[b][i2][j2];
            res[b] = (res[b] - (hash[b][i2][j1] * P) % mod[b] + mod[b]) % mod[b];
            res[b] = (res[b] - (hash[b][i1][j2] * Q) % mod[b] + mod[b]) % mod[b];
            res[b] = (res[b] + hash[b][i1][j1] * ((P * Q) % mod[b])) % mod[b];
        }
        return res;
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int H, W; 
    cin >> H >> W;

    if((ll)H * W > 1e6){
        return 0;
    }

    int N; cin >> N;

    vector A(H, vector<int>(W));
    vector B(H, vector<int>(W));
    rep(i, N){
        int r, c, x;
        cin >> r >> c >> x;
        r--, c--;

        A[r][c] = x + 1;
        B[H - 1 - r][W - 1 - c] = x + 1;
        if(B[H - 1 - r][W - 1 - c] == 7) B[H - 1 - r][W - 1 - c] = 10;
        else if(B[H - 1 - r][W - 1 - c] == 10) B[H - 1 - r][W - 1 - c] = 7;
    }
    debug(A, B);

    RollingHash2d rA(A), rB(B);

    int Q; cin >> Q;
    while(Q--){
        int l, d, r, u;
        cin >> l >> d >> r >> u;
        l--, d--;
        debug(l, d, r, u);

        int i1 = H - r;
        int i2 = H - l;
        int j1 = W - u;
        int j2 = W - d;

        debug(i1, j1, i2, j2);

        cout << (rA.get(l, d, r, u) == rB.get(i1, j1, i2, j2) ? "Yes" : "No") << "\n";
    }
}
0