# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238362 | Sorting | Restore Array (RMI19_restore) | C++14 | 21 ms | 640 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int k_N = 5000 + 3;
const int k_M = 10000 + 3;
struct Constraint{
int l, r, k, value;
int cnt;
Constraint(){}
Constraint(int l, int r, int k, int value){
this->l = l;
this->r = r;
this->k = k;
this->value = value;
}
void set_cnt(){
if(!value)
cnt = k;
else
cnt = (r - l + 1) - k + 1;
}
};
int n, m;
int a[k_N];
Constraint c[k_M];
int prefix[k_N];
int get_count_ones(int l, int r){
if(l == 0)
return prefix[r];
return prefix[r] - prefix[l - 1];
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 0; i < m; ++i){
cin >> c[i].l >> c[i].r >> c[i].k >> c[i].value;
c[i].set_cnt();
}
for(int i = 0; i < n; ++i)
a[i] = -1;
sort(c, c + m, [](const Constraint &lvalue, const Constraint &rvalue){
if((lvalue.r - lvalue.l + 1) - lvalue.cnt != (rvalue.r - rvalue.l + 1) - rvalue.cnt)
return (lvalue.r - lvalue.l + 1) - lvalue.cnt < (rvalue.r - rvalue.l + 1) - rvalue.cnt;
if(lvalue.r - lvalue.l != rvalue.r - rvalue.l)
return (lvalue.r - lvalue.l) < (rvalue.r - rvalue.l);
return lvalue.l < rvalue.l;
});
for(int _ = 0; _ < m; ++_){
auto [l, r, k, value, cnt] = c[_];
//cout << l << " " << r << " " << k << " " << value << " " << cnt << "\n";
int curr_cnt = 0;
for(int i = l; i <= r; ++i)
if(a[i] == value)
++curr_cnt;
if(curr_cnt >= cnt)
continue;
for(int i = l; i <= r; ++i){
if(a[i] == -1){
a[i] = value;
--cnt;
if(!cnt)
break;
}
}
if(cnt){
cout << "-1\n";
return 0;
}
}
for(int i = 0; i < n; ++i)
a[i] = (a[i] == -1) ? 0 : a[i];
for(int i = 0; i < n; ++i)
cout << a[i] << " ";
cout << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |