結果
問題 | No.440 2次元チワワ問題 |
ユーザー |
![]() |
提出日時 | 2016-10-31 05:12:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,250 ms / 5,000 ms |
コード長 | 3,119 bytes |
コンパイル時間 | 1,848 ms |
コンパイル使用メモリ | 182,528 KB |
実行使用メモリ | 13,568 KB |
最終ジャッジ日時 | 2024-11-24 23:57:48 |
合計ジャッジ時間 | 10,554 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define _p(...) (void)printf(__VA_ARGS__)#define forr(x,arr) for(auto&& x:arr)#define _overload3(_1,_2,_3,name,...) name#define _rep2(i,n) _rep3(i,0,n)#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)#define _rrep2(i,n) _rrep3(i,0,n)#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)#define all(x) (x).begin(), (x).end()#define bit(n) (1LL<<(n))#define sz(x) ((int)(x).size())#define fst first#define snd secondusing ll=long long;using pii=pair<int,int>;using vb=vector<bool>;using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;template <typename T> T read() {T t; cin >> t; return t;}int H, W;pii conv1(int y, int x, int rot) {if (rot == 0) return {y, x};if (rot == 1) return {H-x-1, y};if (rot == 2) return {H-y-1, W-x-1};if (rot == 3) return {x, W-y-1};assert(false);};pii conv2(int y, int x, int rot) {if (rot == 0) return {y, x};if (rot == 1) return {x, H-y-1};if (rot == 2) return {H-y-1, W-x-1};if (rot == 3) return {W-x-1, y};assert(false);};void Main() {H = read<int>();W = read<int>();vector<string> M(H);rep(i, H) M[i] = read<string>();int Q = read<int>();vi T(Q), L(Q), B(Q), R(Q);rep(i, Q) {T[i] = read<int>()-1;L[i] = read<int>()-1;B[i] = read<int>()-1;R[i] = read<int>()-1;}vl ans(Q);int HH = H, WW = W;rep(rot, 4) {vvl c(HH, vl(WW+1)), w(HH, vl(WW+1)), cw(HH, vl(WW+1)), ww(HH, vl(WW+1)), cww(HH, vl(WW+1));auto get = [&](int y, int x) -> char {pii yx = conv1(y, x, rot);//_p("rot: %d, (%d,%d)->(%d,%d)\n", rot, y, x, yx.fst, yx.snd);return M[yx.fst][yx.snd];};rep(y, HH) rep(x, WW) {c[y][x+1] = c[y][x];w[y][x+1] = w[y][x];cw[y][x+1] = cw[y][x];ww[y][x+1] = ww[y][x];cww[y][x+1] = cww[y][x];if (get(y, x) == 'c') {c[y][x+1]++;}else {w[y][x+1]++;cw[y][x+1] += c[y][x];ww[y][x+1] += w[y][x];cww[y][x+1] += cw[y][x];}}rep(q, Q) {int t = T[q];int l = L[q];int b = B[q];int r = R[q];{pii tl = conv2(t, l, rot);pii br = conv2(b, r, rot);t = min(tl.fst, br.fst);b = max(tl.fst, br.fst) + 1;l = min(tl.snd, br.snd);r = max(tl.snd, br.snd) + 1;}ll n = 0;rep(y, t, b) {n += cww[y][r] - cww[y][l]- cw[y][l] * (w[y][r] - w[y][l])- c[y][l] * (ww[y][r] - ww[y][l] - (w[y][l] * (w[y][r] - w[y][l])));}ans[q] += n;}swap(HH, WW);}rep(q, Q) {cout << ans[q] << endl;}}int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }