s[j][k]赋值为1可以正常运行,赋值为2则RE
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int n,m,q,r,k,a,b,a1,b1,cnt=0,s[3010][3010],t,x,y,dir[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};
void dfs(int x,int y){
bool b = 0;
for(int i=0;i<4;i++){
int dx = x + dir[i][0];
int dy = y + dir[i][1];
for(int j=0;j<4;j++){
int nx = dx + dir[j][0];
int ny = dy + dir[j][1];
if(s[nx][ny]==2) b=1;
}
if(b){
dfs(dx,dy);
s[dx][dy] = 1;
}
}
}
int main(){
IOS;
cin>>n>>m>>q>>r>>k;
for(int i=1;i<=q;i++){
cin>>a>>b>>a1>>b1;
for(int j=a;j<=a1;j++){
for(int k=b;k<=b1;k++){
s[j][k] = 2;
}
}
}
for(int i=1;i<=r;i++){
cin>>t>>x>>y;
s[x][y] = 1;
dfs(x,y);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
bool lake=0,tree=0;
for(int k=0;k<4;k++){
int dx = i + dir[k][0];
int dy = j + dir[k][1];
if(dx>=1 && dx<=n && dy>=1 && dy<=m) if(s[dx][dy]==1) tree=1;
}
if(tree && s[i][j]==1) cnt++;
s[i][j] = 0;
}
}
cout<<cnt;
return 0;
}