結果
問題 | No.1675 Strange Minimum Query |
ユーザー | playroller |
提出日時 | 2021-09-11 16:35:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,214 bytes |
コンパイル時間 | 2,055 ms |
コンパイル使用メモリ | 180,052 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-06-23 00:46:55 |
合計ジャッジ時間 | 10,181 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | AC | 23 ms
6,940 KB |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 236 ms
10,496 KB |
testcase_14 | AC | 338 ms
10,496 KB |
testcase_15 | WA | - |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | RE | - |
testcase_24 | WA | - |
testcase_25 | RE | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | RE | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,j,n) for(int i=j;i<n;++i) #define all(i) i.begin(),i.end() #define rall(i) i.rbegin(), i.rend() #define INF 1e9 #define LINF 1e18 // const int mod = 998244353; const int mod = 1000000007; using i64 = long long; using pi = pair<int, int>; template <class T> using vt = vector<T>; template <class T> using vvt = vector<vector<T>>; i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));} i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);} int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; #include <vector> #include <functional> template <class Monoid, class OperatorMonoid = Monoid> class LazySegmentTree { using F = std::function<Monoid(Monoid, Monoid)>; using G = std::function<Monoid(Monoid, OperatorMonoid, int)>; using H = std::function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>; private: int n; std::vector<Monoid> seg; std::vector<OperatorMonoid> lazy; const F f; const G g; const H h; const Monoid M1; const OperatorMonoid OM1; void lazyUpdate(int k, int l, int r) { if(lazy[k] == OM1) return; if(2 * k + 1 < 2 * n - 1) { lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]); lazy[2 * k + 2] = h(lazy[2 * k + 2], lazy[k]); } seg[k] = g(seg[k], lazy[k], r - l); lazy[k] = OM1; } public: LazySegmentTree(int sz, const F f, const G g, const H h, const Monoid &M1, const OperatorMonoid &OM1) : f(f), g(g), h(h), M1(M1), OM1(OM1) { n = 1; while(n < sz) n *= 2; seg.resize(2 * n - 1, M1); lazy.resize(2 * n - 1, OM1); } void update(int a, int b, Monoid x, int k = 0, int l = 0, int r = -1) { if(r < 0) r = n; lazyUpdate(k, l, r); if(b <= l || r <= a) return; if(a <= l && r <= b) { lazy[k] = h(lazy[k], x); lazyUpdate(k, l, r); } else { update(a, b, x, 2 * k + 1, l, (l + r) / 2); update(a, b, x, 2 * k + 2, (l + r) / 2, r); seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]); } } Monoid query(int a, int b, int k = 0, int l = 0, int r = -1) { if(r < 0) r = n; lazyUpdate(k, l, r); if(b <= l || r <= a) return M1; if(a <= l && r <= b) return seg[k]; Monoid vl = query(a, b, 2 * k + 1, l, (l + r) / 2); Monoid vr = query(a, b, 2 * k + 2, (l + r) / 2, r); return f(vl, vr); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, q; cin >> n >> q; vt<int> l(n), r(n), b(n); rep(i, 0, q) cin >> l[i] >> r[i] >> b[i]; rep(i, 0, q) l[i]--; vt<int> idx(q); iota(all(idx), 0); sort(all(idx), [&](const int &i, const int &j){ return b[i] < b[j]; }); LazySegmentTree<int> seg(n, [](int a, int b){ return min(a, b); }, [](int a, int b, int len){ if(a == INF) return b; else return max(a, b); }, [](int a, int b){ return max(a, b); }, INF, 0); rep(i, 0, q) { seg.update(l[idx[i]], r[idx[i]], b[idx[i]]); } rep(i, 0, q) { if(seg.query(l[i], r[i] + 1) != b[i]) return cout << -1 << endl, 0; } rep(i, 0, n) { cout << seg.query(i, i + 1) << " \n"[i == n - 1]; } }