結果
問題 | No.1439 Let's Compare!!!! |
ユーザー | 🍮かんプリン |
提出日時 | 2021-03-28 14:26:00 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 488 ms / 2,000 ms |
コード長 | 3,816 bytes |
コンパイル時間 | 2,072 ms |
コンパイル使用メモリ | 179,184 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-05-06 22:39:36 |
合計ジャッジ時間 | 7,575 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 9 ms
5,376 KB |
testcase_08 | AC | 15 ms
5,376 KB |
testcase_09 | AC | 6 ms
5,376 KB |
testcase_10 | AC | 451 ms
5,376 KB |
testcase_11 | AC | 474 ms
5,376 KB |
testcase_12 | AC | 482 ms
5,376 KB |
testcase_13 | AC | 453 ms
5,376 KB |
testcase_14 | AC | 460 ms
5,376 KB |
testcase_15 | AC | 488 ms
5,376 KB |
testcase_16 | AC | 471 ms
5,376 KB |
testcase_17 | AC | 478 ms
5,376 KB |
testcase_18 | AC | 424 ms
5,376 KB |
ソースコード
/** * @FileName a.cpp * @Author kanpurin * @Created 2021.03.28 14:25:55 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; template < class Monoid > struct SegmentTree { private: using Func = std::function< Monoid(Monoid, Monoid) >; Func F; Monoid UNITY; int n; std::vector< Monoid > node; int _binary_search(int a, int b, const std::function<bool(Monoid)> &f, Monoid &s, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return n; if (a <= l && r <= b && !f(F(s,node[k]))) { s = F(s,node[k]); return n; } if (l == r - 1) {s = F(s,node[k]); return l;} int ret = _binary_search(a, b, f, s, 2 * k + 1, l, (r - l) / 2 + l); return ret != n ? ret : _binary_search(a, b, f, s, 2 * k + 2, (r - l) / 2 + l, r); } public: SegmentTree() {} SegmentTree(const std::vector< Monoid > &v, const Func f, const Monoid &unity) { F = f; UNITY = unity; int sz = v.size(); n = 1; while (n < sz) n <<= 1; node.resize(n * 2 - 1, UNITY); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; build(); } SegmentTree(int m, const Monoid &val, const Func f, const Monoid &unity) { F = f; UNITY = unity; n = 1; while (n < m) n <<= 1; node.resize(n * 2 - 1, UNITY); if (val != UNITY) { for (int i = 0; i < m; i++) node[i + n - 1] = val; build(); } } void set(int k, const Monoid &x) { node[n + k - 1] = x; } void build() { for (int i = n - 2; i >= 0; i--) node[i] = F(node[2 * i + 1], node[2 * i + 2]); } void update_query(int x, const Monoid &val) { if (x >= n || x < 0) return; x += n - 1; node[x] = val; while (x > 0) { x = (x - 1) >> 1; node[x] = F(node[2 * x + 1], node[2 * x + 2]); } } Monoid get_query(int l, int r) { Monoid L = UNITY, R = UNITY; if (l < 0) l = 0; if (r < 0) return UNITY; if (l >= n) return UNITY; if (r >= n) r = n; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) L = F(L, node[l++ - 1]); if (r & 1) R = F(node[--r - 1], R); } return F(L, R); } int binary_search(int l, int r, const std::function<bool(Monoid)> &f) { Monoid s = UNITY; int ret = _binary_search(l,r,f,s); return ret != n ? ret : -1; } Monoid operator[](int x) const { return node[n + x - 1]; } int size() { return n; } void print() { for (int i = 0; i < n; i++) { std::cout << i << "\t: " << node[n + i - 1] << std::endl; } } }; int main() { int n;cin >> n; string s,t;cin >> s >> t; int q;cin >> q; vector<bool> a(n); for (int i = 0; i < n; i++) { if (s[i] == t[i]) { a[i] = false; } else { a[i] = true; } } SegmentTree<bool> seg(a,[](bool a, bool b){return a | b;},false); while(q--) { char c; int x,y;cin >> c >> x >> y; if (c == 'S') { s[x-1] = char(y+'0'); } else { t[x-1] = char(y+'0'); } if (s[x-1] == t[x-1]) { seg.update_query(x-1,false); } else { seg.update_query(x-1,true); } int k = seg.binary_search(0,n,[](bool a){return a;}); if (k == -1) { cout << '=' << endl; } else if (s[k] < t[k]) { cout << '<' << endl; } else { cout << '>' << endl; } } return 0; }