Educational Codeforces Round 67 (Rated for Div. 2) C

  • Title effect: a sequence but do not know the specific numerical values are given some hints \ (t_i, L_i, r_i \) , \ (t_i = 0 \) representing the interval \ (L_i \) to \ (r_i \) ordered, \ (t_i = 1 \) was out of order
  • Ideas: first construct an all-1 sequence, which can meet all \ (t_i = 1 \) case, then each \ (t_i = 0 \) first determines whether there is a section \ (t_i = 0 \) section contains, if it contains can not be met otherwise represented by an array of tags after the position of the element with an element should remain orderly, non-binding and has the disorder. for each \ (t_i = 0 \) found in its range without a constraint elements which can be changed to a disordered (if the interval has an element of disorder need not be changed)
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<map>
#define ll long long 
#define FOR(i,n) for(int i =1; i <= n;++i ) 
#define FOR0(i,n) for(int i =0; i < n;++i )  
#define inf 0x3f3f3f3f
using namespace std; 


const int maxn = 1010;
int n,m;

struct node{
    int t,l,r;
}b[maxn];
int arr[maxn];
int vis[maxn];

int cmp(node x,node y){
    if(x.t == y.t){
        if(x.l == y.l){
            return x.t==1?x.r < y.r:x.r>=y.r;
        }
        return x.t==1? x.l < y.l: x.l>=y.l ;
    }
    return x.t > y.t;
}

int main(){
    cin >> n >> m;
    for(int i=1;i<=m;++i){
        cin >> b[i].t >> b[i].l >> b[i].r;
    }
    for(int i=1;i<=n;++i){
        arr[i] = 1;
    }
    sort(b+1,b+1+m,cmp);
    int r=0;
    bool sign= false;
    for(int i=1;i<=m;++i){
        if(!b[i].t){
            r = i;
            break;
        }
        for(int j=b[i].l;j<b[i].r;++j){
            vis[j] = 1;
        }
    }
    if(r==0){
        cout <<"YES" <<endl;
        for(int i=1;i<=n;++i)   cout << arr[i] << ' ';
        cout << endl;
    }else{
        for(int i=r;i<=m;++i){
            for(int j=1;j<r;++j){
                if(b[j].l<=b[i].l && b[j].r>=b[i].r){
                    sign = true;
                    break;
                }
            }
            if(sign)    break;
            int j;
            for(j=b[i].l;j<b[i].r;++j){
                if(vis[j]==-1)  break;
                else if(vis[j]==0){
                    vis[j] = -1;
                    arr[j] = arr[j+1]+1;
                    break;
                }
            }
            if(j==b[i].r){
                sign = true;    break;
            }
        }
        
        if(sign) cout << "NO" <<endl;
        else{
            cout <<"YES"<<endl;
            for(int i=1;i<=n;++i){
                cout << arr[i] << ' ';
            }
            cout << endl;
        }
    }
    
    
    return 0;
}
  • Summary: The general idea is greedy, but in the process \ (t_i = 0 \) when descending from the left end of the interval, otherwise the process will be covered later in front of the results (by hack out QAQ)

Guess you like

Origin www.cnblogs.com/xxrlz/p/11117808.html