結果
問題 | No.1675 Strange Minimum Query |
ユーザー | siman |
提出日時 | 2022-03-09 03:37:25 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 479 ms / 2,000 ms |
コード長 | 2,214 bytes |
コンパイル時間 | 12,116 ms |
コンパイル使用メモリ | 111,544 KB |
実行使用メモリ | 32,536 KB |
最終ジャッジ日時 | 2023-10-09 23:41:55 |
合計ジャッジ時間 | 20,270 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,368 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,368 KB |
testcase_03 | AC | 352 ms
18,840 KB |
testcase_04 | AC | 354 ms
20,260 KB |
testcase_05 | AC | 37 ms
8,488 KB |
testcase_06 | AC | 479 ms
21,628 KB |
testcase_07 | AC | 475 ms
24,452 KB |
testcase_08 | AC | 1 ms
4,372 KB |
testcase_09 | AC | 3 ms
4,368 KB |
testcase_10 | AC | 208 ms
16,652 KB |
testcase_11 | AC | 50 ms
9,444 KB |
testcase_12 | AC | 229 ms
17,880 KB |
testcase_13 | AC | 247 ms
18,480 KB |
testcase_14 | AC | 375 ms
32,484 KB |
testcase_15 | AC | 382 ms
32,536 KB |
testcase_16 | AC | 2 ms
4,372 KB |
testcase_17 | AC | 54 ms
7,044 KB |
testcase_18 | AC | 77 ms
7,944 KB |
testcase_19 | AC | 113 ms
13,132 KB |
testcase_20 | AC | 225 ms
16,632 KB |
testcase_21 | AC | 218 ms
17,224 KB |
testcase_22 | AC | 278 ms
19,652 KB |
testcase_23 | AC | 212 ms
12,304 KB |
testcase_24 | AC | 201 ms
13,992 KB |
testcase_25 | AC | 133 ms
9,744 KB |
testcase_26 | AC | 65 ms
8,940 KB |
testcase_27 | AC | 184 ms
16,720 KB |
testcase_28 | AC | 96 ms
12,076 KB |
testcase_29 | AC | 75 ms
11,416 KB |
testcase_30 | AC | 70 ms
8,724 KB |
testcase_31 | AC | 277 ms
14,760 KB |
testcase_32 | AC | 372 ms
23,096 KB |
testcase_33 | AC | 364 ms
22,752 KB |
testcase_34 | AC | 385 ms
22,756 KB |
testcase_35 | AC | 424 ms
21,904 KB |
testcase_36 | AC | 420 ms
21,988 KB |
ソースコード
#include <cassert> #include <cmath> #include <algorithm> #include <iostream> #include <iomanip> #include <climits> #include <map> #include <queue> #include <set> #include <cstring> #include <vector> using namespace std; typedef long long ll; struct Command { int type; int num; Command(int type = -1, int num = -1) { this->type = type; this->num = num; } }; const double R = 1e-10; struct Node { int i; int v; Node(int i = -1, int v = -1) { this->i = i; this->v = v; } bool operator>(const Node &n) const { return v - i * R < n.v - n.i * R; } }; struct Query { int l; int r; int B; Query(int l = -1, int r = -1, int B = -1) { this->l = l; this->r = r; this->B = B; } bool operator>(const Query &n) const { return B - l * R < n.B - n.l * R; } }; int main() { int N, Q; cin >> N >> Q; vector<Command> commands[N + 2]; priority_queue <Query, vector<Query>, greater<Query>> p_query; for (int i = 0; i < Q; ++i) { int l, r, B; cin >> l >> r >> B; commands[l].push_back(Command(0, B)); commands[r + 1].push_back(Command(1, B)); p_query.push(Query(l, r, B)); } map<int, int> counter; priority_queue <int> pque; pque.push(1); counter[1]++; int ans[N + 1]; for (int i = 1; i <= N; ++i) { for (Command &cmd : commands[i]) { if (cmd.type == 0) { pque.push(cmd.num); counter[cmd.num]++; } else { counter[cmd.num]--; } } while (not pque.empty() && counter[pque.top()] == 0) { pque.pop(); } ans[i] = pque.top(); } priority_queue <Node, vector<Node>, greater<Node>> pque2; for (int i = 1; i <= N; ++i) { pque2.push(Node(i, ans[i])); } while (not pque2.empty()) { Node node = pque2.top(); pque2.pop(); while (not p_query.empty()) { Query q = p_query.top(); if (q.B != node.v) break; if (q.l <= node.i && node.i <= q.r) { p_query.pop(); } else { break; } } } if (p_query.empty()) { for (int i = 1; i <= N; ++i) { cout << ans[i]; if (i < N) cout << " "; } cout << endl; } else { cout << -1 << endl; } return 0; }