結果
| 問題 |
No.1675 Strange Minimum Query
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2022-03-09 03:37:25 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 530 ms / 2,000 ms |
| コード長 | 2,214 bytes |
| コンパイル時間 | 4,902 ms |
| コンパイル使用メモリ | 150,464 KB |
| 実行使用メモリ | 32,652 KB |
| 最終ジャッジ日時 | 2024-09-12 22:13:00 |
| 合計ジャッジ時間 | 17,376 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#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;
}
siman