結果
問題 | No.1920 Territory |
ユーザー | 👑 hos.lyric |
提出日時 | 2022-04-29 22:46:36 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 5,069 bytes |
コンパイル時間 | 1,314 ms |
コンパイル使用メモリ | 124,680 KB |
実行使用メモリ | 60,876 KB |
最終ジャッジ日時 | 2024-06-29 04:23:42 |
合計ジャッジ時間 | 13,766 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 30 ms
29,056 KB |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | AC | 29 ms
29,124 KB |
testcase_07 | RE | - |
testcase_08 | AC | 7 ms
5,376 KB |
testcase_09 | AC | 7 ms
5,376 KB |
testcase_10 | AC | 7 ms
5,376 KB |
testcase_11 | AC | 7 ms
5,376 KB |
testcase_12 | AC | 7 ms
5,376 KB |
testcase_13 | AC | 631 ms
60,672 KB |
testcase_14 | AC | 598 ms
60,876 KB |
testcase_15 | RE | - |
testcase_16 | AC | 611 ms
60,792 KB |
testcase_17 | AC | 606 ms
60,680 KB |
testcase_18 | AC | 509 ms
41,824 KB |
testcase_19 | AC | 514 ms
41,960 KB |
testcase_20 | AC | 519 ms
41,948 KB |
testcase_21 | AC | 528 ms
42,028 KB |
testcase_22 | AC | 517 ms
41,972 KB |
testcase_23 | AC | 421 ms
43,676 KB |
testcase_24 | AC | 202 ms
40,868 KB |
testcase_25 | AC | 153 ms
35,176 KB |
testcase_26 | AC | 141 ms
35,040 KB |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | AC | 293 ms
55,496 KB |
testcase_30 | AC | 285 ms
55,508 KB |
testcase_31 | AC | 305 ms
43,120 KB |
testcase_32 | AC | 301 ms
43,048 KB |
testcase_33 | RE | - |
testcase_34 | AC | 270 ms
48,992 KB |
ソースコード
#include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } int uf[200'010]; int root(int u) { return (uf[u] < 0) ? u : (uf[u] = root(uf[u])); } bool connect(int u, int v) { u = root(u); v = root(v); if (u == v) return false; if (uf[u] > uf[v]) swap(u, v); uf[u] += uf[v]; uf[v] = u; return true; } template <class T> void bAdd(vector<T> &bit, int pos, const T &val) { const int bitN = bit.size(); for (int x = pos; x < bitN; x |= x + 1) bit[x] += val; } template <class T> T bSum(const vector<T> &bit, int pos) { T ret = 0; for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) ret += bit[x]; return ret; } template <class T> T bSum(const vector<T> &bit, int pos0, int pos1) { return bSum(bit, pos1) - bSum(bit, pos0); } int M, N; vector<int> A, B, C; vector<int> P, Q, R; int main() { for (; ~scanf("%d%d", &M, &N); ) { A.resize(M); B.resize(M); C.resize(M); for (int i = 0; i < M; ++i) scanf("%d%d%d", &A[i], &B[i], &C[i]); P.resize(N); Q.resize(N); R.resize(N); for (int j = 0; j < N; ++j) scanf("%d%d%d", &P[j], &Q[j], &R[j]); int limX = 0, limY = 0; for (int i = 0; i < M; ++i) { chmax(limX, B[i]); chmax(limX, C[i]); chmax(limY, A[i]); } for (int j = 0; j < N; ++j) { chmax(limX, P[j]); chmax(limY, Q[j]); chmax(limY, R[j]); } ++limX; ++limY; Int numComps = 0; { int segN; for (segN = 1; segN < limX; segN <<= 1) {} vector<vector<int>> iss(segN << 1), jss(segN << 1); for (int i = 0; i < M; ++i) { // x \in [B[i], C[i]] int a = B[i], b = C[i] + 1; for (a += segN, b += segN; a < b; a >>= 1, b >>= 1) { if (a & 1) iss[a++].push_back(i); if (b & 1) iss[--b].push_back(i); } } for (int j = 0; j < N; ++j) { int a = P[j]; for (a += segN; a; a >>= 1) { jss[a].push_back(j); } } fill(uf, uf + (M + N), -1); for (int a = 1; a < segN << 1; ++a) if (!iss[a].empty() && !jss[a].empty()) { // cerr<<"is = ";pv(iss[a].begin(),iss[a].end()); // cerr<<"js = ";pv(jss[a].begin(),jss[a].end()); vector<pair<pair<int, int>, int>> events; for (const int i : iss[a]) { events.emplace_back(make_pair(A[i], 1), i); } for (const int j : jss[a]) { events.emplace_back(make_pair(Q[j], 0), j); } sort(events.begin(), events.end()); using Entry = pair<int, int>; priority_queue<Entry, vector<Entry>, greater<Entry>> que; for (const auto &e : events) { if (e.first.second) { const int i = e.second; for (; !que.empty() && que.top().first < A[i]; que.pop()) {} if (!que.empty()) { for (; ; ) { const auto p = que.top(); que.pop(); connect(i, M + p.second); if (que.empty()) { que.push(p); break; } } } } else { const int j = e.second; que.emplace(R[j], j); } } } for (int u = 0; u < M + N; ++u) if (uf[u] < 0) { ++numComps; } } // cerr<<"uf = ";pv(uf,uf+(M+N)); cerr<<"numComps = "<<numComps<<endl; Int numPoints = 0; { vector<vector<int>> adds(limX), rems(limX), jss(limY); for (int i = 0; i < M; ++i) { adds[B[i]].push_back(i); rems[C[i]].push_back(i); } for (int j = 0; j < N; ++j) { jss[P[j]].push_back(j); } vector<int> bit(limY, 0); for (int x = 0; x < limX; ++x) { for (const int i : adds[x]) { bAdd(bit, A[i], +1); } for (const int j : jss[x]) { Int num = 0; num += bSum(bit, R[j] + 1); num -= bSum(bit, Q[j]); numPoints += num; } for (const int i : rems[x]) { bAdd(bit, A[i], -1); } } } cerr<<"numPoints = "<<numPoints<<endl; Int ans = 0; ans += numPoints; ans -= (M + N); ans += numComps; printf("%lld\n", ans); } return 0; }