제출 #1256327

#제출 시각아이디문제언어결과실행 시간메모리
1256327hainam2k9Long Mansion (JOI17_long_mansion)C++20
100 / 100
152 ms59080 KiB
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 5e5+5;
const string NAME = "";
int n,q,c[MAXN],last[MAXN],l[MAXN],r[MAXN];
pair<int,int> p[MAXN];
vector<int> v[MAXN];
bool vis[MAXN];
bool checkleft(int L, int R){
    if(L>1&&r[L-1]>=L&&r[L-1]<=R) return 1;
    return 0;
}
bool checkright(int L, int R){
    if(R<n&&l[R+1]>=L&&l[R+1]<=R) return 1;
    return 0;
}
void calc(int i){
    if(vis[i]) return;
    vis[i]=1;
    while(1){
        if(checkleft(p[i].fi,p[i].se)){
            int nxt=p[i].fi-1;
            calc(nxt);
            p[i].fi=min(p[i].fi,p[nxt].fi),
            p[i].se=max(p[i].se,p[nxt].se);
        }else if(checkright(p[i].fi,p[i].se)){
            int nxt=p[i].se+1;
            calc(nxt);
            p[i].fi=min(p[i].fi,p[nxt].fi),
            p[i].se=max(p[i].se,p[nxt].se);
        }else break;
    }
}
int main()
{
    tt;
    if(fopen((NAME + ".INP").c_str(), "r")) fo;
    cin >> n;
    for(int i = 1; i<n; ++i)
        cin >> c[i];
    memset(last,0x3f,sizeof(last));
    for(int i = 1; i<=n; ++i){
        if(i>1) l[i]=min(i,last[c[i-1]]);
        int sz;
        cin >> sz;
        v[i].resize(sz);
        for(int j = 0; j<sz; ++j)
            cin >> v[i][j], last[v[i][j]]=i;
    }
    memset(last,0,sizeof(last));
    for(int i = n; i>0; --i){
        if(i<n) r[i]=max(i,last[c[i]]);
        for(int j = 0; j<sz(v[i]); ++j)
            last[v[i][j]]=i;
    }
    l[1]=1, r[n]=n;
    for(int i = 1; i<=n; ++i)
        p[i]={i,i};
    for(int i = 1; i<=n; ++i)
        calc(i);
    cin >> q;
    while(q--){
        int x,y;
        cin >> x >> y;
        if(y>=p[x].fi&&y<=p[x].se) cout << "YES\n";
        else cout << "NO\n";
    }
}

컴파일 시 표준 에러 (stderr) 메시지

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp:54:45: note: in expansion of macro 'fo'
   54 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
long_mansion.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp:54:45: note: in expansion of macro 'fo'
   54 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...