intmain(){ int c; longlong n, m; int q; cin >> c >> n >> m >> q; //空间占用超标 vector<vector<bool>> board(n + 1, vector<bool>(m + 1, false)); for (int i = 0; i < q; i++) { int t; longlong x1, y1, x2, y2; cin >> t >> x1 >> y1 >> x2 >> y2; if (t == 1) { for (longlong x = x1; x <= x2; x++) { board[y1][x] = true; } } } longlong ans = 0; for (int y = 1; y <= n; y++) { for (longlong x = 1; x <= m; x++) { if (board[y][x]) ans++; } } cout << ans << endl; return0; }
structSegTree { int n; vector<int> tree, lazy; SegTree(int _n) { n = _n; tree.assign(4 * n + 5, 0); lazy.assign(4 * n + 5, 0); } voidpush(int node, int l, int r){ if (lazy[node]) { tree[node] = (r - l + 1); if (l != r) { lazy[node * 2] = lazy[node * 2 + 1] = 1; } lazy[node] = 0; } } voidupdate(int node, int l, int r, int ul, int ur){ push(node, l, r); if (ul > r || ur < l) return; if (ul <= l && r <= ur) { lazy[node] = 1; push(node, l, r); return; } int mid = (l + r) >> 1; update(node * 2, l, mid, ul, ur); update(node * 2 + 1, mid + 1, r, ul, ur); tree[node] = tree[node * 2] + tree[node * 2 + 1]; } intquery(){ return tree[1]; } };
intmain(){ int c; longlong n, m; int q; cin >> c >> n >> m >> q; // 需要为每行建线段树,空间太大 unordered_map<longlong, SegTree*> rowTrees; for (int i = 0; i < q; i++) { int t; longlong x1, y1, x2, y2; cin >> t >> x1 >> y1 >> x2 >> y2; if (t == 1) { if (rowTrees.find(y1) == rowTrees.end()) { rowTrees[y1] = newSegTree(m); } rowTrees[y1]->update(1, 1, m, x1, x2); } } longlong ans = 0; for (auto& p : rowTrees) { ans += p.second->query(); } cout << ans << endl; return0; }