1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include<bits/stdc++.h> using namespace std; #define int long long const int N = 3010; int n,m,qq,r,k; int mp[N][N]; struct happening { int t; int thing; int x,y; bool operator <(const happening& xx) const { return t > xx.t; } }; priority_queue <happening> q; bool check_grow(int x,int y) { return x>=1&&x<=n&&y>=1&&y<=m&&mp[x][y]==0&& (mp[x-1][y]==1||mp[x+1][y]==1||mp[x][y-1]==1||mp[x][y+1]==1); } void solve() { cin>>n>>m>>qq>>r>>k; k*=2; for(int _=1;_<=qq;_++) { int xa,xb,ya,yb; cin>>xa>>ya>>xb>>yb; for(int x=xa;x<=xb;x++) for(int y=ya;y<=yb;y++) mp[x][y]=1; } for(int _=1;_<=r;_++) { int t,x,y; cin>>t>>x>>y; q.push({t*2,0,x,y}); } int ans=0; while(!q.empty()) { happening tmp=q.top(); q.pop(); if(tmp.thing==0) { if(mp[tmp.x][tmp.y]==0) { mp[tmp.x][tmp.y]=2; if(mp[tmp.x-1][tmp.y]==0&& mp[tmp.x+1][tmp.y]==0&& mp[tmp.x][tmp.y-1]==0&& mp[tmp.x][tmp.y+1]==0) q.push({tmp.t+k+1,1,tmp.x,tmp.y}); if(check_grow(tmp.x-1,tmp.y))q.push({tmp.t+2,0,tmp.x-1,tmp.y}); if(check_grow(tmp.x+1,tmp.y))q.push({tmp.t+2,0,tmp.x+1,tmp.y}); if(check_grow(tmp.x,tmp.y-1))q.push({tmp.t+2,0,tmp.x,tmp.y-1}); if(check_grow(tmp.x,tmp.y+1))q.push({tmp.t+2,0,tmp.x,tmp.y+1}); } } else if(tmp.thing==1) { if(mp[tmp.x-1][tmp.y]==0&& mp[tmp.x+1][tmp.y]==0&& mp[tmp.x][tmp.y-1]==0&& mp[tmp.x][tmp.y+1]==0) mp[tmp.x][tmp.y]=0; } } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(mp[i][j]==2)ans++; cout<<ans<<endl; } signed main() { ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); solve(); return 0; }
|