Advertisement
Alex_tz307

ABC 182: E - Akari

Nov 8th, 2020 (edited)
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.12 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define x first
  3. #define y second
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     ios_base::sync_with_stdio(false);
  9.     cin.tie(nullptr);
  10.     cout.tie(nullptr);
  11.     int H, W, N, M;
  12.     cin >> H >> W >> N >> M;
  13.     vector < pair < int , int > > bulbs(N), blocks(M);
  14.     for(auto& x : bulbs)
  15.         cin >> x.x >> x.y;
  16.     vector < vector < int > > lin_prev_block(H + 4, vector < int >(W + 4)),
  17.                               lin_next_block(H + 4, vector < int >(W + 4)),
  18.                               col_prev_block(H + 4, vector < int >(W + 4)),
  19.                               col_next_block(H + 4, vector < int >(W + 4));
  20.     vector < vector < bool > > block(H + 4, vector < bool >(W + 4));
  21.     for(auto& x : blocks) {
  22.         cin >> x.x >> x.y;
  23.         lin_prev_block[x.x][x.y] = lin_next_block[x.x][x.y] = col_prev_block[x.x][x.y] = col_next_block[x.x][x.y] = 1;
  24.         block[x.x][x.y] = true;
  25.     }
  26.     for(int i = 1; i <= H; ++i) {
  27.         for(int j = 1; j <= W; ++j)
  28.             if(lin_prev_block[i][j] == 1)
  29.                 lin_prev_block[i][j] = j;
  30.             else
  31.                 lin_prev_block[i][j] = lin_prev_block[i][j - 1];
  32.         for(int j = W; j > 0; --j)
  33.             if(lin_next_block[i][j] == 1)
  34.                 lin_next_block[i][j] = j;
  35.             else
  36.                 lin_next_block[i][j] = lin_next_block[i][j + 1];
  37.     }
  38.     for(int j = 1; j <= W; ++j) {
  39.         for(int i = 1; i <= H; ++i)
  40.             if(col_prev_block[i][j] == 1)
  41.                 col_prev_block[i][j] = i;
  42.             else
  43.                 col_prev_block[i][j] = col_prev_block[i - 1][j];
  44.         for(int i = H; i > 0; --i)
  45.             if(col_next_block[i][j] == 1)
  46.                 col_next_block[i][j] = i;
  47.             else
  48.                 col_next_block[i][j] = col_next_block[i + 1][j];
  49.     }
  50.     vector < vector < int > > lines(H + 4, vector < int >(W + 4)),
  51.                               cols(H + 4, vector < int >(W + 4));
  52.     for(auto x : bulbs) {
  53.         int lin = x.x, col = x.y;
  54.         int c1 = lin_prev_block[lin][col], c2 = lin_next_block[lin][col];
  55.         if(c2 == 0)
  56.             c2 = W + 1;
  57.         int l1 = col_prev_block[lin][col], l2 = col_next_block[lin][col];
  58.         if(l2 == 0)
  59.             l2 = H + 1;
  60.         ++lines[lin][c1 + 1];
  61.         --lines[lin][c2];
  62.         ++cols[l1 + 1][col];
  63.         --cols[l2][col];
  64.     }
  65.     for(int i = 1; i <= H; ++i)
  66.         for(int j = 1; j <= W; ++j) {
  67.             int add = 0;
  68.             if(lines[i][j] > 0)
  69.                 add = 1;
  70.             if(block[i][j])
  71.                 lines[i][j] = 0;
  72.             else
  73.                 lines[i][j] = lines[i][j - 1] + add;
  74.         }
  75.     for(int j = 1; j <= W; ++j)
  76.         for(int i = 1; i <= H; ++i) {
  77.             int add = 0;
  78.             if(cols[i][j] > 0)
  79.                 add = 1;
  80.             if(block[i][j])
  81.                 cols[i][j] = 0;
  82.             else
  83.                 cols[i][j] = cols[i - 1][j] + add;
  84.         }
  85.     int ans = 0;
  86.     for(int i = 1; i <= H; ++i)
  87.         for(int j = 1; j <= W; ++j)
  88.             if(lines[i][j] > 0 || cols[i][j] > 0)
  89.                 ++ans;
  90.     cout << ans;
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement