Language: C++

//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;

int main(void)
{
	//変数の宣言
	int n,m,q;
	static char c[2010];
	static int s[2010][2010];
	static int x1[200010];
	static int y1[200010];
	static int x2[200010];
	static int y2[200010];
	static int memo[2010];
	static int tate[2010][2010];
	static int yoko[2010][2010];
	static int ruiseki[2010][2010];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	ll int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;



	//データの読み込み

/*
//	scanf("%d",&n);
	scanf_s("%d",&n);

	for(i=0;i<n;i++){
//		scanf("%d %d",&a[i],&b[i]);
		scanf_s("%d %d",&a[i],&b[i]);
	}*/

	scanf("%d %d %d",&n,&m,&q);
	for(i=0;i<n;i++){
		scanf("%s",&s);
		for(j=0;j<m;j++){
			sint[i][j]=s[j]-'0';
		}
	}

	for(i=0;i<q;i++){
		scanf("%d %d %d %d",&x1[i],&y1[i],&x2[i],&y2[i]);
	}

/*	scanf_s("%d %d %d",&n,&m,&q);
	for(i=0;i<n;i++){
		scanf_s("%s",&c,2010);
		for(j=0;j<m;j++){
			s[i][j]=c[j]-'0';
		}
	}

	for(i=0;i<q;i++){
		scanf_s("%d %d %d %d",&x1[i],&y1[i],&x2[i],&y2[i]);
	}*/

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	for(i=0;i<n-1;i++){
		for(j=0;j<m;j++){
			if(j==0){
				if(s[i][j]==1&&s[i+1][j]==1){
					tate[i][0]=1;
				}else{
					tate[i][0]=0;
				}
			}else if(s[i][j]==1&&s[i+1][j]==1){
				tate[i][j]=tate[i][j-1]+1;
			}else{
				tate[i][j]=tate[i][j-1];
			}
		}
	}

	for(i=0;i<n;i++){
		for(j=0;j<m-1;j++){
			if(i==0){
				if(s[i][j]==1&&s[i][j+1]==1){
					yoko[0][j]=1;
				}else{
					yoko[0][j]=0;
				}
			}else if(s[i][j]==1&&s[i][j+1]==1){
				yoko[i][j]=yoko[i-1][j]+1;
			}else{
				yoko[i][j]=yoko[i-1][j];
			}
		}
	}

	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(j==0){
				memo[j]=s[i][j];
			}else if(s[i][j-1]==0){
				memo[j]=memo[j-1]+s[i][j];
			}else{
				memo[j]=memo[j-1];
			}
		}

		if(i==0){
			for(j=0;j<m;j++){
				ruiseki[0][j]=memo[j];
			}
		}else{
			for(j=0;j<m;j++){
				ruiseki[i][j]=ruiseki[i-1][j]+memo[j]-tate[i-1][j];
			}
		}
	}

	for(i=0;i<q;i++){
		ans=ruiseki[x2[i]-1][y2[i]-1];
		if(x1[i]==1&&y1[i]==1){
			//nothing
		}else if(x1[i]==1){
			ans=ans-ruiseki[x2[i]-1][y1[i]-2]+yoko[x2[i]-1][y1[i]-2];
		}else if(y1[i]==1){
			ans=ans-ruiseki[x1[i]-2][y2[i]-1]+tate[x1[i]-2][y2[i]-1];
		}else{
			ans=ans-ruiseki[x2[i]-1][y1[i]-2]+yoko[x2[i]-1][y1[i]-2];
			ans=ans-ruiseki[x1[i]-2][y2[i]-1]+tate[x1[i]-2][y2[i]-1];
			ans=ans+ruiseki[x1[i]-2][y1[i]-2]-yoko[x1[i]-2][y1[i]-2]-tate[x1[i]-2][y1[i]-2];
		}
		printf("%d\n",ans);
	}

	printf("yoko[i][j]\n");
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			printf("%d ",yoko[i][j]);
		}
		printf("\n");
	}

	printf("tate[i][j]\n");
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			printf("%d ",tate[i][j]);
		}
		printf("\n");
	}
	
	printf("ruiseki[i][j]\n");
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			printf("%d ",ruiseki[i][j]);
		}
		printf("\n");
	}
	//	printf("計算部分終了\n");

	//出力

	
	//	printf("結果の出力終了\n");

	return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:78:25: error: 'sint' was not declared in this scope; did you mean 'uint'?
   78 |                         sint[i][j]=s[j]-'0';
      |                         ^~~~
      |                         uint