# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
891268 |
2023-12-22T15:52:18 Z |
Irate |
RMQ (NOI17_rmq) |
C++14 |
|
0 ms |
344 KB |
#include<bits/stdc++.h>
using namespace std;
struct Query{
int l, r, val;
bool operator<(Query &other){
return val < other.val;
}
};
struct SegmentTree{
vector<int>sTree;
SegmentTree(int n){
sTree.resize(4 * n);
}
void Build(int node, int l, int r, vector<int>&v){
if(l == r){
sTree[node] = v[l - 1];
}
else{
int mid = (l + r) >> 1;
Build(node * 2, l, mid, v);
Build(node * 2 + 1, mid + 1, r, v);
sTree[node] = min(sTree[node * 2], sTree[node * 2 + 1]);
}
}
int Query(int node, int l, int r, int ql, int qr){
if(ql <= l && r <= qr){
return sTree[node];
}
if(ql > r || l > qr)return 1e9;
int mid = (l + r) >> 1;
int lc = Query(node * 2, l, mid, ql, qr);
int rc = Query(node * 2 + 1, mid + 1, r, ql, qr);
return min(lc, rc);
}
};
struct LazySegmentTree{
vector<int>sTree;
vector<int>lazy;
LazySegmentTree(int n){
sTree.assign(4 * n, -1);
lazy.assign(4 * n, -1);
}
void Propagate(int node, int l, int r){
if(lazy[node] == -1)return;
if(l != r){
lazy[node * 2] = lazy[node * 2 + 1] = lazy[node];
}
else {
sTree[node] = lazy[node];
}
lazy[node] = -1;
}
void R_Update(int node, int l, int r, int ql, int qr, int val){
Propagate(node, l, r);
if(ql <= l && r <= qr){
lazy[node] = val;
Propagate(node, l, r);
return;
}
if(ql > r || l > qr)return;
int mid = (l + r) >> 1;
R_Update(node * 2, l, mid, ql, qr, val);
R_Update(node * 2 + 1, mid + 1, r, ql, qr, val);
}
int Get(int node, int l, int r, int pos){
Propagate(node, l, r);
if(l == r){
return sTree[node];
}
else{
int mid = (l + r) >> 1;
if(pos <= mid){
return Get(node * 2, l, mid, pos);
}
else{
return Get(node * 2 + 1, mid + 1, r, pos);
}
}
}
};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<Query>queries(q);
for(int i = 0;i < q;++i){
int l, r, val;
cin >> l >> r >> val;
queries[i] = {l, r, val};
}
sort(queries.begin(), queries.end());
vector<bool>chosen(n);
set<int>s;
for(int i = 0;i < n;++i)s.insert(i);
LazySegmentTree tree2(n);
for(int i = 0;i < q;++i){
int l = queries[i].l, r = queries[i].r, val = queries[i].val;
s.erase(val);
tree2.R_Update(1, 1, n, l + 1, r + 1, val);
}
vector<int>v(n, -1);
for(int i = 0;i < n;++i){
v[i] = tree2.Get(1, 1, n, i + 1);
}
auto itr = s.begin();
for(int i = 0;i < n;++i){
if(v[i] != -1 && !chosen[v[i]])chosen[v[i]] = 1;
else {
v[i] = *itr;
itr++;
}
}
SegmentTree tree1(n);
tree1.Build(1, 1, n, v);
bool check = true;
for(int i = 0;i < q && check;++i){
int l = queries[i].l, r = queries[i].r, val = queries[i].val;
if(tree1.Query(1, 1, n, l + 1, r + 1) != val){
check = 0;
}
}
if(check){
for(int i = 0;i < n;++i){
cout << v[i] << " ";
}
}
else{
for(int i = 0;i < n;++i){
cout << -1 << " ";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |