結果
問題 | No.1920 Territory |
ユーザー | 👑 tute7627 |
提出日時 | 2022-04-29 22:08:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 5,029 bytes |
コンパイル時間 | 3,581 ms |
コンパイル使用メモリ | 226,188 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-29 03:36:53 |
合計ジャッジ時間 | 9,010 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 8 ms
6,940 KB |
testcase_04 | AC | 8 ms
6,940 KB |
testcase_05 | AC | 8 ms
6,944 KB |
testcase_06 | AC | 9 ms
6,944 KB |
testcase_07 | AC | 9 ms
6,944 KB |
testcase_08 | AC | 8 ms
6,940 KB |
testcase_09 | AC | 8 ms
6,948 KB |
testcase_10 | AC | 7 ms
6,944 KB |
testcase_11 | AC | 8 ms
6,940 KB |
testcase_12 | AC | 8 ms
6,940 KB |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
ソースコード
//from:https://atcoder.jp/contests/joi2014ho/submissions/2337234 #include<bits/stdc++.h> using namespace std; typedef pair< int, int > Point; enum : int { CREATEY, APPEARX, DELETEY}; struct Event { int y, idx, type; bool operator<(const Event& e) const { if(y == e.y) return(type < e.type); return(y < e.y); } }; struct BinaryIndexedTree { vector< int > data; BinaryIndexedTree(int sz) { data.assign(sz + 2, 0); } int query(int k) { int ret = 0; for(++k; k > 0; k -= k & -k) ret += data[k]; return(ret); } void update(int k, int x) { for(++k; k < data.size(); k += k & -k) data[k] += x; } }; struct SegmentTree { vector< int > isnew; int sz; SegmentTree(int n) { sz = 1; while(sz < n) sz <<= 1; isnew.assign(2 * sz - 1, false); } inline void AddF(const int a, const int b, int k, int l, int r) { if(a >= r || b <= l) { return; } else if(a <= l && r <= b) { isnew[k] = true; } else { AddF(a, b, 2 * k + 1, l, (l + r) >> 1); AddF(a, b, 2 * k + 2, (l + r) >> 1, r); } } inline void DelF(const int a, const int b, int k, int l, int r) { if(a >= r || b <= l) { return; } else if(a <= l && r <= a + 1) { isnew[k] = false; } else { if(isnew[k]) { isnew[2 * k + 1] = true; isnew[2 * k + 2] = true; isnew[k] = false; } DelF(a, b, 2 * k + 1, l, (l + r) >> 1); DelF(a, b, 2 * k + 2, (l + r) >> 1, r); } } inline void AddF(int a, int b) { AddF(a, b, 0, 0, sz); } inline void DelF(const int x) { DelF(x, x + 1, 0, 0, sz); } inline bool CheckF(int k) { k += sz - 1; if(isnew[k]) return(true); while(k > 0) { k = (k - 1) >> 1; if(isnew[k]) return(true); } while(k > 0); return(false); } }; struct UnionFind { vector< int > data; UnionFind(){}; inline int Make() { data.push_back(-1); return(data.size() - 1); } inline bool Unite(int a, int b) { a = Find(a), b = Find(b); if(a == b) return(false); if(data[a] > data[b]) swap(a, b); data[a] += data[b]; data[b] = a; return(true); } inline int Find(int k) { if(data[k] < 0) return(k); else return(data[k] = Find(data[k])); } }; SegmentTree *tree; UnionFind *uf; BinaryIndexedTree *bit; int decode[200020]; int Evaluate(int x) { if(tree -> CheckF(x)) { tree -> DelF(x); return(uf -> Make()); } else { return(decode[x]); } } int Press(int *A, int sz1, int *B, int sz2) { vector< int > nums; copy(A, A + sz1, back_inserter(nums)); copy(B, B + sz2, back_inserter(nums)); nums.push_back(-1); sort(nums.begin(), nums.end()); nums.erase(unique(nums.begin(), nums.end()), nums.end()); transform(A, A + sz1, A, [&](int x) { return(lower_bound(nums.begin(), nums.end(), x) - nums.begin()); }); transform(B, B + sz2, B, [&](int x) { return(lower_bound(nums.begin(), nums.end(), x) - nums.begin()); }); return(nums.size()); } int main() { int W, H, N; int A[100004], B[100004], C[100004], D[100004]; W=300000; H=300000; int n,m;scanf("%d %d",&n,&m); N=n+m; for(int i = 0; i < n; i++) { scanf("%d",&B[i]); D[i]=B[i]; scanf("%d %d", &A[i], &C[i]); } for(int i = n; i < n+m; i++) { scanf("%d",&A[i]); C[i]=A[i]; scanf("%d %d", &B[i], &D[i]); } A[N] = 0; B[N] = 0; C[N] = W; D[N] = 0; ++N; A[N] = 0; B[N] = 0; C[N] = 0; D[N] = H; ++N; A[N] = W; B[N] = 0; C[N] = W; D[N] = H; ++N; A[N] = 0; B[N] = H; C[N] = W; D[N] = H; ++N; W = Press(A, N, C, N); vector< Event > Events; /* type = CREATEY: Y????????????????????? type = DELETEY: Y????????????????¶???? type = APPEARX: X???????????? */ for(int i = 0; i < N; i++) { if(A[i] == C[i]) { Events.push_back((Event){B[i], i, CREATEY}); Events.push_back((Event){D[i], i, DELETEY}); } else { Events.push_back((Event){B[i], i, APPEARX}); } } sort(Events.begin(), Events.end()); set< int > pool; uf = new UnionFind(); tree = new SegmentTree(W); bit = new BinaryIndexedTree(W); pool.insert(0); decode[0] = uf -> Make(); long long int sz = 0; for(int i = 0; i < Events.size(); i++) { const Event& e = Events[i]; const int& x = A[e.idx]; if(e.type == CREATEY) { int L = *--pool.lower_bound(x); decode[x] = Evaluate(x); decode[L] = Evaluate(L); decode[x] = decode[L]; pool.insert(x); bit -> update(x, 1); } else if(e.type == DELETEY) { int L = *--pool.lower_bound(x); decode[x] = Evaluate(x); decode[L] = Evaluate(L); if(uf -> Unite(decode[x], decode[L])) --sz; pool.erase(x); bit -> update(x, -1); } else { int x2 = C[e.idx]; int RSQ = bit -> query(x2) - bit -> query(x - 1) - 1; if(RSQ > 0) { sz += RSQ; tree -> AddF(x, *--pool.upper_bound(x2)); } } } printf("%lld\n", sz-1); }