Advertisement
Dang_Quan_10_Tin

ITABLE (HSGHN L9 2020-2021)

Dec 19th, 2021
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5.  
  6. using ll = long long;
  7. using ld = long double;
  8.  
  9. constexpr int N = 5e3 + 5;
  10. int n, t, q;
  11. int hor[N][N], ver[N][N];
  12.  
  13. void Read()
  14. {
  15.     cin >> n >> t;
  16.  
  17.     while (t--)
  18.     {
  19.         int k, rc, x, y;
  20.         cin >> k >> rc >> x >> y;
  21.  
  22.         if (k == 1)
  23.         {
  24.             int u = (y - x + 1 + 1) / 2, // up
  25.                 v = (y - x + 1 + 2) / 2; // down
  26.             ++hor[rc][x];
  27.             --hor[rc][x + u];
  28.             --hor[rc][x + v];
  29.             ++hor[rc][y + 2];
  30.         }
  31.         else
  32.         {
  33.  
  34.             int u = (y - x + 1 + 1) / 2, // up
  35.                 v = (y - x + 1 + 2) / 2; // down
  36.             ++ver[x][rc];
  37.             --ver[x + u][rc];
  38.             --ver[x + v][rc];
  39.             ++ver[y + 2][rc];
  40.         }
  41.     }
  42.  
  43.     cin >> q;
  44. }
  45.  
  46. void Solve()
  47. {
  48.     for (int i = 1; i <= n; ++i)
  49.         for (int j = 1; j <= n; ++j)
  50.         {
  51.             hor[i][j] += hor[i][j - 1];
  52.             ver[i][j] += ver[i - 1][j];
  53.         }
  54.     for (int i = 1; i <= n; ++i)
  55.         for (int j = 1; j <= n; ++j)
  56.         {
  57.             hor[i][j] += hor[i][j - 1];
  58.             ver[i][j] += ver[i - 1][j];
  59.         }
  60.  
  61.     while (q--)
  62.     {
  63.         int x, y;
  64.         cin >> x >> y;
  65.         cout << hor[x][y] + ver[x][y] << "\n";
  66.     }
  67. }
  68.  
  69. int32_t main()
  70. {
  71.     ios::sync_with_stdio(0);
  72.     cin.tie(0);
  73.     cout.tie(0);
  74.     freopen("ITABLE.INP", "r", stdin);
  75.     freopen("ITABLE.OUT", "w", stdout);
  76.  
  77.     Read();
  78.     Solve();
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement