結果
| 問題 |
No.440 2次元チワワ問題
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2020-02-17 09:40:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2,246 ms / 5,000 ms |
| コード長 | 3,527 bytes |
| コンパイル時間 | 1,584 ms |
| コンパイル使用メモリ | 127,564 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-06 14:49:53 |
| 合計ジャッジ時間 | 16,264 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int h, w;
string s[505];
int a[10010], b[10010], c[10010], d[10010];
using Pi=pair<P, int>;
ll ans[10010];
int main()
{
cin>>h>>w;
for(int i=0; i<h; i++) cin>>s[i];
int q; cin>>q;
vector<Pi> vx(q), vy(q);
for(int i=0; i<q; i++){
cin>>a[i]>>b[i]>>c[i]>>d[i];a[i]--; b[i]--; c[i]--; d[i]--;
vx[i]=Pi(P(a[i], c[i]), i);
vy[i]=Pi(P(b[i], d[i]), i);
}
sort(vx.begin(), vx.end());
sort(vy.begin(), vy.end());
for(int i=0; i<h; i++){
int t=0;
for(int j=0; j<w; j++){
ll cntw=0, cnt=0;
for(int k=j; k<w; k++){
if(s[i][k]=='c') cnt+=cntw*(cntw-1)/2;
else cntw++;
while(t<q && vy[t].first<=P(j, k)){
if(vy[t].first==P(j, k) && a[vy[t].second]<=i && i<=c[vy[t].second]){
ans[vy[t].second]+=cnt;
}
t++;
}
}
}
}
for(int i=0; i<w; i++){
int t=0;
for(int j=0; j<h; j++){
ll cntw=0, cnt=0;
for(int k=j; k<h; k++){
if(s[k][i]=='c') cnt+=cntw*(cntw-1)/2;
else cntw++;
while(t<q && vx[t].first<=P(j, k)){
if(vx[t].first==P(j, k) && b[vx[t].second]<=i && i<=d[vx[t].second]){
ans[vx[t].second]+=cnt;
}
t++;
}
}
}
}
sort(vx.begin(), vx.end(), [](Pi a, Pi b){ return (a.first.second!=b.first.second)?(a.first.second>b.first.second):(a.first.first>b.first.first);});
sort(vy.begin(), vy.end(), [](Pi a, Pi b){ return (a.first.second!=b.first.second)?(a.first.second>b.first.second):(a.first.first>b.first.first);});
for(int i=0; i<h; i++){
int t=0;
for(int j=w-1; j>=0; j--){
ll cntw=0, cnt=0;
for(int k=j; k>=0; k--){
if(s[i][k]=='c') cnt+=cntw*(cntw-1)/2;
else cntw++;
while(t<q && (vy[t].first.second>j || (vy[t].first.second==j && vy[t].first.first>=k))){
if(vy[t].first==P(k, j) && a[vy[t].second]<=i && i<=c[vy[t].second]){
ans[vy[t].second]+=cnt;
}
t++;
}
}
}
}
for(int i=0; i<w; i++){
int t=0;
for(int j=h-1; j>=0; j--){
ll cntw=0, cnt=0;
for(int k=j; k>=0; k--){
if(s[k][i]=='c') cnt+=cntw*(cntw-1)/2;
else cntw++;
while(t<q && (vx[t].first.second>j || (vx[t].first.second==j && vx[t].first.first>=k))){
if(vx[t].first==P(k, j) && b[vx[t].second]<=i && i<=d[vx[t].second]){
ans[vx[t].second]+=cnt;
}
t++;
}
}
}
}
for(int i=0; i<q; i++) cout<<ans[i]<<endl;
return 0;
}
chocorusk