Submission #1292077

#TimeUsernameProblemLanguageResultExecution timeMemory
1292077qmdz1908Long Mansion (JOI17_long_mansion)C++17
100 / 100
250 ms37816 KiB
#include <bits/stdc++.h>
using namespace std;
#define pii pair <int, int>
#define fi first
#define se second
const int maxn = 5e5 + 5, oo = 1e18, mod = 1e9 + 7;
int n, c[maxn], L[maxn], R[maxn];
vector <int> a[maxn];
bool has (int l, int r, int x) {
    return *lower_bound (a[x].begin(), a[x].end(), l) <= r; 
}
void solve () {
    cin >> n;
    for (int i = 1; i < n; i++)
        cin >> c[i];
    for (int i = 1, m; i <= n; i++) {
        cin >> m;
        for (int j = 1, x; j <= m; j++) {
            cin >> x;
            a[x].push_back (i);
        }
    }
    for (int i = 1; i <= n; i++) a[i].push_back (oo);
    for (int i = 1; i <= n; i++) {
        L[i] = R[i] = i;
        bool loop = true;
        while (loop) {
            loop = false;
            if (L[i] > 1 && has(L[i], R[i], c[L[i] - 1])) {
            int p = L[i] - 1;
            L[i] = min(L[i], L[p]);
            R[i] = max(R[i], R[p]);
            loop = true;
        }
        if (R[i] < n && has(L[i], R[i], c[R[i]])) {
            R[i]++;
            loop = true;
        }
    }

    }
    int q;
    cin >> q;
    while (q--) {
        int x, y;
        cin >> x >> y;
        if (y >= L[x] && y <= R[x]) cout << "YES\n";
        else cout << "NO\n";
    }
}
signed main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen ("code.inp", "r")) {
        freopen ("code.inp", "r", stdin);
        freopen ("code.out", "w", stdout);
    }
    int tc = 1;
//    cin >> tc;
    while (tc--) solve ();
}

Compilation message (stderr)

long_mansion.cpp:6:32: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
    6 | const int maxn = 5e5 + 5, oo = 1e18, mod = 1e9 + 7;
      |                                ^~~~
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:56:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen ("code.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp:57:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen ("code.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...