# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
258078 | tqbfjotld | Restore Array (RMI19_restore) | C++14 | 16 ms | 1148 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.
/*
value = 0 --> sum of range(l,r)<=r-l+1-k
value = 1 --> sum of range(l,r)>=r-l+1-k+1
*/
#include <bits/stdc++.h>
using namespace std;
typedef pair<pair<int,int>,pair<int,int> > query;
bool cmp(query a, query b){
if (a.second.first==1 && a.second.second==1) return true;
if (b.second.first==1 && b.second.second==1) return false;
if (a.second.first==a.first.second-a.first.first+1 && a.second.second==0) return true;
if (b.second.first==b.first.second-b.first.first+1 && b.second.second==0) return false;
return a<b;
}
int arr[5005];
vector<query> queries;
int main(){
int n,m;
scanf("%d%d",&n,&m);
for (int x = 0; x<m; x++){
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
queries.push_back({{a,b},{c,d}});
}
sort(queries.begin(),queries.end(),cmp);
for (auto x : queries){
int l = x.first.first;
int r = x.first.second;
int k = x.second.first;
int val = x.second.second;
if (k==1&&val==1){
for (int x = l; x<=r; x++){
arr[x] = 1;
}
continue;
}
if (k==r-l+1 && val==0){
for (int x = l; x<=r; x++){
if (arr[x]==1){
printf("-1");
return 0;
}
}
continue;
}
//if (val==0){
bool found = false;
for (int x = l; x<=r; x++){
if (val==arr[x]) found = true;
}
if (!found){
printf("-1");
return 0;
}
//}
}
for (int x = 0; x<n; x++){
printf("%d ",arr[x]);
}
}
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... |