結果
問題 |
No.3207 Digital Font
|
ユーザー |
👑 ![]() |
提出日時 | 2025-07-18 22:14:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 333 ms / 3,000 ms |
コード長 | 10,083 bytes |
コンパイル時間 | 2,521 ms |
コンパイル使用メモリ | 215,292 KB |
実行使用メモリ | 20,288 KB |
最終ジャッジ日時 | 2025-07-18 22:14:49 |
合計ジャッジ時間 | 12,469 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
ソースコード
//#include <bits/stdc++.h> //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<class T> using _pq = priority_queue<T, vector<T>, greater<T>>; //template<class T> int LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} //template<class T> int UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} //template<class T> bool chmin(T &a,T b){if(b<a){a=b;return 1;}else return 0;} //template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;} //template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());} //template<class T> void Sore(vector<T> &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<class T> void vec_out(vector<T> &p,int ty=0){ // if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";} // else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}} //template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} //template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} //template<class T> T vec_sum(vector<T> &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<class T> 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<long long>(l,r-1)(rng); //} // //#include <atcoder/segtree> //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<int> 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<vector<query>> 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<mint>(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<mint, op, e> seg(W); // vector<int> 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 <bits/stdc++.h> 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<class T> using _pq = priority_queue<T, vector<T>, greater<T>>; template<class T> int LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template<class T> int UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template<class T> bool chmin(T &a,T b){if(b<a){a=b;return 1;}else return 0;} template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;} template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());} template<class T> void Sore(vector<T> &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<class T> void vec_out(vector<T> &p,int ty=0){ if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";} else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}} template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} template<class T> T vec_sum(vector<T> &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<class T> 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<long long>(l,r-1)(rng); } #include <atcoder/segtree> 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<int> 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<vector<query>> 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<mint>(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<mint, op, e> seg(W); vector<int> 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]); } }