Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
struct edge{int to,cost;};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    int memo=modpow(a,b/2);
    return memo*memo%MOD;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
    x=modpow(x,MOD-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
double dist(double ax,double ay,double bx,double by){
    return sqrt((bx-ax)*(bx-ax)+(ay-by)*(ay-by));
}
int h,w,q,r[1500][1500],par[2250000],siz[2250000];
char c[1500][1500];
void init(int n){
    rep(i,n){
        par[i]=i;
        siz[i]=1;
    }
}
int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
}
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(siz[x]<siz[y])swap(x,y);
    par[y]=x;
    siz[x]+=siz[y];
}
bool same(int x,int y){
    return find(x)==find(y);
}
int Size(int x){
    return siz[find(x)];
}
bool can(int i,int j,int l){
    int x2=i+l-1,y2=j+l-1;
    if(x2>=h||y2>=w)return false;
    return r[x2][y2]-(i?r[i-1][y2]:0)-(j?r[x2][j-1]:0)+(i&&j?r[i-1][j-1]:0)==0;
}
signed main(){
    cin>>h>>w;
    init(h*w);
    rep(i,h){
        rep(j,w){
            cin>>c[i][j];
        }
    }
    cin>>q;
    
    rep(i,h){
            r[i][0]=(c[i][0]=='#');
            for(int j=1;j<w;j++){
                r[i][j]=r[i][j-1]+(c[i][j]=='#');
            }
        }
        rep(j,w){
            for(int i=1;i<h;i++){
                r[i][j]+=r[i-1][j];
            }
        }
        rep(i,h){
            rep(j,w){
                if(i){
                    if(c[i-1][j]=='.'&&c[i][j]=='.'){
                        unite(i*w+j,(i-1)*w+j);
                    }
                }
                if(j){
                    if(c[i][j-1]=='.'&&c[i][j]=='.'){
                        unite(i*w+j,i*w+j-1);
                    }
                }
            }
        }
        rep(_,q){
            int x,y,l;
            cin>>x>>y>>l;
            x--,y--;
            int ans=0;
            rep(i,h){
                rep(j,w){
                    if(same(i*w+j,x*w+y)){
                        int x2=i+l-1,y2=j+l-1;
                        if(x2>=h||y2>=w)continue;
                        if(r[x2][y2]-(i?r[i-1][y2]:0)-(j?r[x2][j-1]:0)+(i&&j?r[i-1][j-1]:0)==0){
                            cout<<_<<" "<<i<<" "<<j<<endl;
                            ans++;
                        }
                    }
                }   
            }
            cout<<ans<<endl;
        }
        return 0;
    }
    rep(i,h){
        rep(j,w){
            if(i){
               if(c[i-1][j]=='.'&&c[i][j]=='.'){
                    unite(i*w+j,(i-1)*w+j);
                }
            }
            if(j){
               if(c[i][j-1]=='.'&&c[i][j]=='.'){
                   unite(i*w+j,i*w+j-1);
               }
            }
        }
    }
    
    rep(_,q){
        int x,y,l;
        cin>>x>>y>>l;
        x--,y--;
        cout<<Size(x*w+y)<<endl;
    }
    return 0;
}


Compiler output:
a.cc:8:18: error: expected unqualified-id before 'for'
    8 | #define rep(i,n) for(int i=0;i<n;i++)
      |                  ^~~
a.cc:148:5: note: in expansion of macro 'rep'
  148 |     rep(i,h){
      |     ^~~
a.cc:148:9: error: 'i' does not name a type; did you mean 'fi'?
  148 |     rep(i,h){
      |         ^
a.cc:8:30: note: in definition of macro 'rep'
    8 | #define rep(i,n) for(int i=0;i<n;i++)
      |                              ^
a.cc:148:9: error: 'i' does not name a type; did you mean 'fi'?
  148 |     rep(i,h){
      |         ^
a.cc:8:34: note: in definition of macro 'rep'
    8 | #define rep(i,n) for(int i=0;i<n;i++)
      |                                  ^
a.cc:8:18: error: expected unqualified-id before 'for'
    8 | #define rep(i,n) for(int i=0;i<n;i++)
      |                  ^~~
a.cc:163:5: note: in expansion of macro 'rep'
  163 |     rep(_,q){
      |     ^~~
a.cc:163:9: error: '_' does not name a type
  163 |     rep(_,q){
      |         ^
a.cc:8:30: note: in definition of macro 'rep'
    8 | #define rep(i,n) for(int i=0;i<n;i++)
      |                              ^
a.cc:163:9: error: '_' does not name a type
  163 |     rep(_,q){
      |         ^
a.cc:8:34: note: in definition of macro 'rep'
    8 | #define rep(i,n) for(int i=0;i<n;i++)
      |                                  ^
a.cc:169:5: error: expected unqualified-id before 'return'
  169 |     return 0;
      |     ^~~~~~
a.cc:170:1: error: expected declaration before '}' token
  170 | }
      | ^