답안 #773103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773103 2023-07-04T15:15:30 Z PixelCat Long Mansion (JOI17_long_mansion) C++14
10 / 100
3000 ms 28368 KB
/*     code by PixelCat     */
/*         meow owo         */

#include <bits/stdc++.h>
#define int LL  //__int128
#define double long double
using namespace std;
using LL = long long;
// using i128 = __int128_t;
using ull = unsigned long long;
using pii = pair<int, int>;

#define For(i, a, b) for (int i = a; i <= b; i++)
#define Fors(i, a, b, s) for (int i = a; i <= b; i += s)
#define Forr(i, a, b) for (int i = a; i >= b; i--)
#define F first
#define S second

#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair

#define MOD (int)(998244353)
// #define MOD (int)((LL)1'000'000'007)
#define INF (int)(4e18)
#define EPS (1e-6)

namespace PixelCat {

#ifdef NYAOWO
#include "/home/pixelcat/yodayo/meow/library/debug.hpp"
inline void USACO(const string &s) {
    cerr << "USACO: " << s << "\n";
}

#else
#define debug(...)
inline void timer() {}
inline void USACO(const string &s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

#endif

inline void NYA() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}
inline int gcd(int a, int b) {
    return __gcd(a, b);
}
inline int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int fpow(int b, int p, const int &mod = MOD) {
    int ans = 1;
    for (; p; p >>= 1, b = b * b % mod)
        if (p & 1) ans = ans * b % mod;
    return ans;
}
template <typename T>
inline void chmin(T &_a, const T &_b) {
    if (_b < _a) _a = _b;
}
template <typename T>
inline void chmax(T &_a, const T &_b) {
    if (_a < _b) _a = _b;
}
mt19937_64 rng(
    chrono::steady_clock::now().time_since_epoch().count());

} // namespace PixelCat
using namespace PixelCat;

const int MAXN = 500050;

int key[MAXN];
vector<int> pos[MAXN];
pii ans[MAXN];

// check if there's any key of type [k] in range [l, r]
bool check(int l, int r, int k) {
    return lower_bound(all(pos[k]), l) != upper_bound(all(pos[k]), r);
}

struct Ayaya {
    vector<int> start;
    int l, r, sl, sr;
    Ayaya(int s): start(1, s), l(s), r(s), sl(s), sr(s) {}
    int len() { return r - l + 1; }
    bool inside(int x) { return l <= x && x <= r; }
    void dead() { for(auto &i:start) ans[i] = pii(l, r); }
    bool expand(int n) {
        if(r < n && check(l, r, key[r])) {
            r++; return true;
        } else if(l > 1 && check(l, r, key[l - 1])) {
            l--; return true;
        }
        return false;
    }
};
void merge(Ayaya *&a, Ayaya *&b) {
    if(sz(a->start) < sz(b->start)) swap(a, b);
    a->start.insert(a->start.end(), all(b->start));
    a->l = min(a->l, b->l);
    a->sl = min(a->sl, b->sl);
    a->r = max(a->r, b->r);
    a->sr = max(a->sr, b->sr);
}
bool overlap(Ayaya *a, Ayaya *b) {
    return (a->inside(b->sl) || a->inside(b->sr)) &&
           (b->inside(a->sl) || b->inside(a->sr));
}

struct AyayaCmp {
    bool operator()(Ayaya* const& a, Ayaya* const& b) {
        if(a->len() != b->len()) return a->len() > b->len();
        return a->l > b->l;
    }
};

void solve(int n) {
    priority_queue<Ayaya*, vector<Ayaya*>, AyayaCmp> pq;
    For(i, 1, n) {
        pq.emplace(new Ayaya(i));
    }
    while(!pq.empty()) {
        Ayaya* a = pq.top(); pq.pop();
        if(sz(pq) && overlap(a, pq.top())) {
            Ayaya* b = pq.top(); pq.pop();
            merge(a, b);
            delete b;
            pq.emplace(a);
        } else if(a->expand(n)) {
            pq.emplace(a);
        } else {
            a->dead();
            delete a;
        }
    }
}

void solve_slow(int n) {
    For(i, 1, n) {
        Ayaya aya(i);
        while(aya.expand(n));
        aya.dead();
    }
}

int32_t main() {
    NYA();
    // nyaacho >/////<
    int n; cin >> n;
    For(i, 1, n - 1) cin >> key[i];
    For(i, 1, n) {
        int k; cin >> k;
        while(k--) {
            int x; cin >> x;
            pos[x].eb(i);
        }
    }

    solve(n);
    
    int q; cin >> q;
    while(q--) {
        int x, y; cin >> x >> y;
        pii &r = ans[x];
        if(r.F <= y && y <= r.S) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }

    // For(i, 1, n) {
    //     cerr << ans[i].F << ", " << ans[i].S << "\n";
    // }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12372 KB Output is correct
2 Correct 158 ms 12520 KB Output is correct
3 Correct 985 ms 12776 KB Output is correct
4 Correct 12 ms 12372 KB Output is correct
5 Correct 200 ms 12352 KB Output is correct
6 Correct 33 ms 12376 KB Output is correct
7 Correct 13 ms 12372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12372 KB Output is correct
2 Correct 158 ms 12520 KB Output is correct
3 Correct 985 ms 12776 KB Output is correct
4 Correct 12 ms 12372 KB Output is correct
5 Correct 200 ms 12352 KB Output is correct
6 Correct 33 ms 12376 KB Output is correct
7 Correct 13 ms 12372 KB Output is correct
8 Correct 93 ms 13924 KB Output is correct
9 Correct 78 ms 13864 KB Output is correct
10 Correct 232 ms 14176 KB Output is correct
11 Correct 989 ms 14468 KB Output is correct
12 Correct 89 ms 13904 KB Output is correct
13 Correct 82 ms 14088 KB Output is correct
14 Correct 77 ms 14068 KB Output is correct
15 Correct 89 ms 14128 KB Output is correct
16 Correct 246 ms 14284 KB Output is correct
17 Correct 76 ms 14028 KB Output is correct
18 Correct 81 ms 14284 KB Output is correct
19 Correct 86 ms 14116 KB Output is correct
20 Correct 148 ms 14308 KB Output is correct
21 Correct 270 ms 14412 KB Output is correct
22 Correct 125 ms 14116 KB Output is correct
23 Correct 80 ms 13968 KB Output is correct
24 Correct 78 ms 13900 KB Output is correct
25 Correct 79 ms 13888 KB Output is correct
26 Correct 75 ms 13936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3079 ms 28368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12372 KB Output is correct
2 Correct 158 ms 12520 KB Output is correct
3 Correct 985 ms 12776 KB Output is correct
4 Correct 12 ms 12372 KB Output is correct
5 Correct 200 ms 12352 KB Output is correct
6 Correct 33 ms 12376 KB Output is correct
7 Correct 13 ms 12372 KB Output is correct
8 Correct 93 ms 13924 KB Output is correct
9 Correct 78 ms 13864 KB Output is correct
10 Correct 232 ms 14176 KB Output is correct
11 Correct 989 ms 14468 KB Output is correct
12 Correct 89 ms 13904 KB Output is correct
13 Correct 82 ms 14088 KB Output is correct
14 Correct 77 ms 14068 KB Output is correct
15 Correct 89 ms 14128 KB Output is correct
16 Correct 246 ms 14284 KB Output is correct
17 Correct 76 ms 14028 KB Output is correct
18 Correct 81 ms 14284 KB Output is correct
19 Correct 86 ms 14116 KB Output is correct
20 Correct 148 ms 14308 KB Output is correct
21 Correct 270 ms 14412 KB Output is correct
22 Correct 125 ms 14116 KB Output is correct
23 Correct 80 ms 13968 KB Output is correct
24 Correct 78 ms 13900 KB Output is correct
25 Correct 79 ms 13888 KB Output is correct
26 Correct 75 ms 13936 KB Output is correct
27 Execution timed out 3079 ms 28368 KB Time limit exceeded
28 Halted 0 ms 0 KB -