| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 636871 | ogibogi2004 | Restore Array (RMI19_restore) | C++14 | 158 ms | 780 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 MAXN=5e3+6;
int A[MAXN],n,m;
vector<pair<int,int> >no_zero;
vector<pair<int,int> >no_one;
vector<pair<int,int> >one;
vector<pair<int,int> >zero;
vector<pair<pair<int,int>,int> >onezero;
int arr[MAXN];
bool done[2*MAXN];
int main()
{
    memset(arr,-1,sizeof(arr));
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int l,r,k,val;
        cin>>l>>r>>k>>val;
        if(k==1&&val==1)no_zero.push_back({l,r});
        if(k==r-l+1&&val==1)one.push_back({l,r});
        if(k==1&&val==0)zero.push_back({l,r});
        if(k==r-l+1&&val==0)no_one.push_back({l,r});
    }
    for(auto xd:no_zero)
    {
        for(int i=xd.first;i<=xd.second;i++)
        {
            arr[i]=1;
        }
    }
    for(auto xd:no_one)
    {
        for(int i=xd.first;i<=xd.second;i++)
        {
            if(arr[i]==1)
            {
                cout<<"-1\n";
                return 0;
            }
            arr[i]=0;
        }
    }
    for(auto xd:one)
    {
        bool found=0;
        for(int i=xd.first;i<=xd.second;i++)
        {
            if(arr[i]==1)found=1;
        }
        if(!found)onezero.push_back({xd,1});
    }
    for(auto xd:zero)
    {
        bool found=0;
        for(int i=xd.first;i<=xd.second;i++)
        {
            if(arr[i]==0)found=1;
        }
        if(!found)onezero.push_back({xd,0});
    }
    for(int i=1;i<=n;i++)
    {
        if(arr[i]>=0)continue;
        int minr=n+1,what=-1;
        for(int i=0;i<onezero.size();i++)
        {
            if(done[i]==0&&onezero[i].first.second<minr)
            {
                minr=onezero[i].first.second;
                what=onezero[i].second;
            }
        }
        if(what==-1)
        {
            arr[i]=0;
        }
        else arr[i]=what;
        for(int i=0;i<onezero.size();i++)
        {
            if(onezero[i].first.first<=i&&onezero[i].first.second>=i&&onezero[i].second==arr[i])
            {
                done[i]=1;
            }
        }
    }
    for(int i=0;i<onezero.size();i++)
    {
        if(done[i]==0)
        {
            cout<<"-1\n";
            return 0;
        }
    }
    for(int i=1;i<=n;i++)cout<<arr[i]<<" ";
    cout<<endl;
return 0;
}
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... | ||||
