結果
| 問題 |
No.1675 Strange Minimum Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-09-11 00:59:47 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 493 ms / 2,000 ms |
| コード長 | 2,341 bytes |
| コンパイル時間 | 8,291 ms |
| コンパイル使用メモリ | 166,260 KB |
| 実行使用メモリ | 32,108 KB |
| 最終ジャッジ日時 | 2024-06-12 21:33:46 |
| 合計ジャッジ時間 | 18,083 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1<<25;
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using vvi = vector<vector<int>>;
template <typename T>
struct RMQ {
const T INF = numeric_limits<T>::max();
int n; // 葉の数
vector<T> dat; // 完全二分木の配列
RMQ(int n_) : n(), dat(n_ * 4, INF) { // 葉の数は 2^x の形
int x = 1;
while (n_ > x) {
x *= 2;
}
n = x;
}
void update(int i, T x) {
i += n - 1;
dat[i] = x;
while (i > 0) {
i = (i - 1) / 2; // parent
dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
}
}
// the minimum element of [a,b)
T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
T query_sub(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) {
return INF;
} else if (a <= l && r <= b) {
return dat[k];
} else {
T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
};
int main() {
int n, q;cin >> n >> q;
vvi ar1(n), ar2(n);
vector<tuple<int,int,int>> que;
rep(i, q) {
int l,r,b;cin >> l >> r >> b;
l--;r--;
que.emplace_back(make_tuple(l,r,b));
ar1[l].emplace_back(b);
ar2[r].emplace_back(b);
}
multiset<int> ms;
vi res(n, -1);
rep(i, n) {
for (int j : ar1[i]) {
//cout << j << endl;
ms.insert(j);
}
if(ms.size()==0)res[i] = 1;
else res[i] = *ms.rbegin();
//cout <<" "<< ms.size() << endl;
for (int j : ar2[i]) {
//cout << j << *ms.find(j) << endl;
//if (ms.find(j)==ms.end())cout << "%" << endl;
ms.erase(ms.find(j));
//cout << "#" << endl;
}
}
/* rep(i, n) {
cout << res[i] << " ";
}
cout << endl; */
RMQ<int> rmq(n);
rep(i, n) {
rmq.update(i, res[i]);
}
int ans = 1;
rep(i, q) {
int l,r,b;tie(l,r,b) = que[i];
if (rmq.query(l, r+1) > b) {
ans = 0;
break;
}
}
if(ans) {
rep(i, n){
cout << res[i];
if (i<n-1)cout << " ";
}
cout << endl;
}
else {
cout << -1 << endl;
}
}