結果
問題 | No.1675 Strange Minimum Query |
ユーザー | sata shun |
提出日時 | 2021-09-10 21:33:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 324 ms / 2,000 ms |
コード長 | 4,437 bytes |
コンパイル時間 | 2,614 ms |
コンパイル使用メモリ | 222,532 KB |
実行使用メモリ | 30,372 KB |
最終ジャッジ日時 | 2024-06-11 22:40:19 |
合計ジャッジ時間 | 11,796 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 221 ms
13,960 KB |
testcase_04 | AC | 204 ms
14,800 KB |
testcase_05 | AC | 17 ms
8,320 KB |
testcase_06 | AC | 286 ms
16,236 KB |
testcase_07 | AC | 324 ms
17,380 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 3 ms
6,940 KB |
testcase_10 | AC | 68 ms
12,524 KB |
testcase_11 | AC | 19 ms
9,292 KB |
testcase_12 | AC | 75 ms
13,616 KB |
testcase_13 | AC | 151 ms
25,796 KB |
testcase_14 | AC | 169 ms
30,372 KB |
testcase_15 | AC | 187 ms
28,560 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 33 ms
7,424 KB |
testcase_18 | AC | 48 ms
7,936 KB |
testcase_19 | AC | 66 ms
13,576 KB |
testcase_20 | AC | 166 ms
18,240 KB |
testcase_21 | AC | 146 ms
18,252 KB |
testcase_22 | AC | 197 ms
20,932 KB |
testcase_23 | AC | 154 ms
14,796 KB |
testcase_24 | AC | 133 ms
14,164 KB |
testcase_25 | AC | 95 ms
10,780 KB |
testcase_26 | AC | 44 ms
9,196 KB |
testcase_27 | AC | 129 ms
17,528 KB |
testcase_28 | AC | 61 ms
12,496 KB |
testcase_29 | AC | 39 ms
11,704 KB |
testcase_30 | AC | 47 ms
9,304 KB |
testcase_31 | AC | 198 ms
16,684 KB |
testcase_32 | AC | 269 ms
24,860 KB |
testcase_33 | AC | 267 ms
24,852 KB |
testcase_34 | AC | 273 ms
24,736 KB |
testcase_35 | AC | 230 ms
20,116 KB |
testcase_36 | AC | 219 ms
19,964 KB |
ソースコード
//#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> V<T> make_vec(size_t a) { return V<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return V<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) #define per(i, b) per2(i, 0, b) #define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define ALL(c) (c).begin(), (c).end() #define SZ(x) ((int)(x).size()) constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; } template <class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; } template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "{"; rep(i, v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } #ifdef LOCAL void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif template <class T> void print(T x, int suc = 1) { cout << x; if (suc == 1) cout << "\n"; else if (suc == 2) cout << " "; } template <class T> void print(const vector<T>& v, int suc = 1) { for (int i = 0; i < v.size(); ++i) print(v[i], i == int(v.size()) - 1 ? suc : 2); } // index of root = 1 template <class U> struct segtree { using T = typename U::T; int sz; V<T> dat; segtree() {} segtree(int n) { sz = 1; while (sz < n) sz <<= 1; dat.assign(sz * 2, U::id()); } segtree(const V<T>& a) { int n = a.size(); sz = 1; while (sz < n) sz <<= 1; dat.assign(sz * 2, U::id()); for (int i = 0; i < n; ++i) { dat[sz + i] = a[i]; } for (int i = sz - 1; i >= 1; --i) { upd(i); } } void upd(int p) { dat[p] = U::op(dat[p << 1], dat[p << 1 | 1]); } void build() { for (int i = sz - 1; i > 0; --i) { dat[i] = U::op(dat[i << 1], dat[i << 1 | 1]); } } void modify(int p, T v) { p += sz; dat[p] = v; while (p >>= 1) { dat[p] = U::op(dat[p << 1], dat[p << 1 | 1]); } } //[l, r) T query(int l, int r) { T lval = U::id(), rval = U::id(); for (l += sz, r += sz; l < r; l >>= 1, r >>= 1) { if (l & 1) lval = U::op(lval, dat[l++]); if (r & 1) rval = U::op(dat[--r], rval); } return U::op(lval, rval); } }; // modify only U for use constexpr int INF = TEN(9) + 10; struct U { using T = int; static T id() { return INF; } static T op(const T& a, const T& b) { return min(a, b); } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, Q; cin >> N >> Q; VV<pii> ev(N + 1); V<tuple<int, int, int>> vec; rep(i, Q) { int l, r, x; cin >> l >> r >> x; --l; ev[l].eb(-1, x); ev[r].eb(1, x); vec.eb(l, r, x); } multiset<int> st; st.insert(1); V<int> A(N); rep(i, N) { sort(ALL(ev[i])); for (auto p : ev[i]) { if (p.fi == -1) { st.insert(p.se); } else { st.erase(st.find(p.se)); } } A[i] = *st.rbegin(); } segtree<U> seg(A); bool ok = 1; for (auto& [l, r, x] : vec) { if (seg.query(l, r) != x) { ok = 0; } } if (ok) { print(A); } else { cout << -1 << endl; } return 0; }