답안 #730351

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730351 2023-04-25T17:50:49 Z DJeniUp Restore Array (RMI19_restore) C++17
컴파일 오류
0 ms 0 KB
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pairll;
typedef pair<ll,ull>pairull;
typedef pair<ll,pairll>pair3l;
typedef long double ld;

#define fr first
#define sc second
#define pb push_back
#define endl '\n'
#define N 100007
#define MOD 1000000007
#define INF 100000000000007
#define eps 0.00000000001
//#define A ll(1e12)

ll n,m,r[5007],f[N];

struct D{
    ll tp,l,r,k,h;
}d[N];

int main(){

    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>d[i].l>>d[i].r>>d[i].k>>d[i].tp;
        d[i].l++;
        d[i].r++;
    }
    ll x=1;

    for(int i=1;i<=n;i++){
        ll y=0;
        for(int j=1;j<=m;j++){
            f[j]=0;
            if(d[j].l<=i && i<=d[j].r && d[j].tp==1 && d[j].h<=d[j].r-d[j].l+1-d[j].k+1)f[j]=1;
            if(d[j].l<=i && i<=d[j].r && d[j].tp==0 && d[j].h>=d[j].r-d[j].l+1-d[j].k){
                f[j]=2;
                y=1;
            }

        }
        for(int j=1;j<=m;j++){
            if(d[j].l<=i && i<=d[j].r){
                d[j].h++;
            }

        }
        if(y==0){
            r[i]=1;
        }
       // cout<<r[i]<<endl;
    }
    for(int i=1;i<=n;i++){
        ll y=0;
        ll fl=0;
        for(int j=1;j<=m;j++){
            if(d[j].l<=i && i<=d[j].r && d[j].tp==1 && d[j].h<d[j].r-d[j].l+1-d[j].k+1)fl=1;
        }
        if(fl==0)continue;
        for(int j=1;j<=m;j++){
            f[j]=0;
            if(d[j].l<=i && i<=d[j].r && d[j].tp==1)f[j]=1;
            if(d[j].l<=i && i<=d[j].r && d[j].tp==0 && d[j].h==d[j].r-d[j].l+1-d[j].k){
                f[j]=2;
                y=1;
            }
        }
        if(y==0){
            r[i]=1;
            for(int j=1;j<=m;j++){
                if(d[j].l<=i && i<=d[j].r){
                    d[j].h++;
                }

            }
            continue;
        }
        fl=0;
        while(x<i && fl==0){
            if(r[x]==0){
                x++;
                continue;
            }
            for(int j=1;j<=m;j++){
                if(d[j].l<=x && x<=d[j].r && (f[j] && d[j].h<=d[j].r-d[j].l+1-d[j].k+1)){
                    fl=-1;
                    break;
                }
                if((x<d[j].l || d[j].r<x) && f[j]==2){
                    fl=-1;
                    break;
                }
            }
            if(fl==0)fl=x;
            else fl=0;
            x++;
        }
        if(fl==0){
            cout<<-1<<endl;
            return 0;
        }
        r[fl]=0;
        r[i]=1;
        for(int j=1;j<=m;j++){
            if(d[j].l<=i && i<=d[j].r){
                d[j].h++;
            }
            if(d[j].l<=fl && fl<=d[j].r){
                d[j].h--;
            }

        }
    }
    for(int i=1;i<=m;i++){
        if(d[j].tp==0 && d[j].h>d[j].r-d[j].l+1-d[j].k){
            cout<<-1<<endl;
            return 0;
        }
        if(d[j].tp==1 && d[j].h<=d[j].r-d[j].l+1-d[j].k){
            cout<<-1<<endl;
            return 0;
        }
    }
    for(int i=1;i<=n;i++){
        cout<<r[i]<<" ";
    }
    cout<<endl;

    return 0;
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:122:14: error: 'j' was not declared in this scope
  122 |         if(d[j].tp==0 && d[j].h>d[j].r-d[j].l+1-d[j].k){
      |              ^
restore.cpp:126:14: error: 'j' was not declared in this scope
  126 |         if(d[j].tp==1 && d[j].h<=d[j].r-d[j].l+1-d[j].k){
      |              ^