Submission #669843

# Submission time Handle Problem Language Result Execution time Memory
669843 2022-12-07T13:07:38 Z Do_you_copy Long Mansion (JOI17_long_mansion) C++17
0 / 100
3000 ms 19224 KB
/*
    I find it wholesome to be alone the greater part of the time.
    To be in company, even with the best, is soon wearisome and dissipating.
    I love to be alone.
    I never found the companion that was so companionable as solitude.
*/
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
mt19937_64 Rand(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 5e5 + 10;
//const int Mod = 1e9 + 7;
//const int inf =
int n;
vector <int> S[maxN];
int L[maxN], R[maxN];
int l[maxN], r[maxN];
int last[maxN];
int c[maxN];

bool inside(int l, int r, int x){
    return l <= x && x <= r;
}

bool can(int l, int r, int x){
    return inside(l, r, L[x]) || inside(l, r, R[x]);
}

void Init(){
    cin >> n;
    for (int i = 1; i < n; ++i) cin >> c[i];
    for (int i = 1; i <= n; ++i){
        int b; cin >> b;
        while (b--){
            int x; cin >> x;
            S[i].pb(x);
        }
    }
    for (int i = 1; i < n; ++i){
        for (int j: S[i]){
            last[j] = i;
        }
        L[i] = last[c[i]];
    }
    fill(last + 1, last + n + 1, n + 1);
    for (int i = n; i > 1; --i){
        for (int j: S[i]){
            last[j] = i;
        }
        R[i] = last[c[i - 1]];
    }
    for (int i = 1; i <= n; ++i){
        l[i] = r[i] = i;
        while (1){
            if (l[i] > 1 && can(l[i], r[i], l[i])){
                r[i] = max(r[i], r[l[i] - 1]);
                l[i] = l[l[i - 1]];
            }
            else{
                if (r[i] < n && can(l[i], r[i], r[i]))
                    ++r[i];
                else break;
            }
        }
    }
    int q; cin >> q;
    while (q--){
        int x, y;
        cin >> x >> y;
        cout << (inside(l[x], r[x], y) ? "YES\n" : "NO\n");
    }
}

#define debug
#define taskname "test"
signed main(){
    faster
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    int tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    if (fopen("timeout.txt", "r")){
        ofstream timeout("timeout.txt");
        timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000);
        timeout.close();
        #ifndef debug
        cerr << "Time elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n";
        #endif // debug
    }
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 3065 ms 12244 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3065 ms 12244 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3063 ms 19224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3065 ms 12244 KB Time limit exceeded
2 Halted 0 ms 0 KB -