Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- using namespace std;
- using ll = long long;
- using ld = long double;
- constexpr int N = 5e3 + 5;
- int n, t, q;
- int hor[N][N], ver[N][N];
- void Read()
- {
- cin >> n >> t;
- while (t--)
- {
- int k, rc, x, y;
- cin >> k >> rc >> x >> y;
- if (k == 1)
- {
- int u = (y - x + 1 + 1) / 2, // up
- v = (y - x + 1 + 2) / 2; // down
- ++hor[rc][x];
- --hor[rc][x + u];
- --hor[rc][x + v];
- ++hor[rc][y + 2];
- }
- else
- {
- int u = (y - x + 1 + 1) / 2, // up
- v = (y - x + 1 + 2) / 2; // down
- ++ver[x][rc];
- --ver[x + u][rc];
- --ver[x + v][rc];
- ++ver[y + 2][rc];
- }
- }
- cin >> q;
- }
- void Solve()
- {
- for (int i = 1; i <= n; ++i)
- for (int j = 1; j <= n; ++j)
- {
- hor[i][j] += hor[i][j - 1];
- ver[i][j] += ver[i - 1][j];
- }
- for (int i = 1; i <= n; ++i)
- for (int j = 1; j <= n; ++j)
- {
- hor[i][j] += hor[i][j - 1];
- ver[i][j] += ver[i - 1][j];
- }
- while (q--)
- {
- int x, y;
- cin >> x >> y;
- cout << hor[x][y] + ver[x][y] << "\n";
- }
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- freopen("ITABLE.INP", "r", stdin);
- freopen("ITABLE.OUT", "w", stdout);
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement