Submission #889269

# Submission time Handle Problem Language Result Execution time Memory
889269 2023-12-19T09:27:25 Z dimashhh Long Mansion (JOI17_long_mansion) C++17
25 / 100
301 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 12, MOD = 998244353;
typedef long long ll;

int n,q,c[N],b[N];
vector<array<int,3>> res(N);
vector<int> a[N];
int used[N],timer = 0;
unordered_map<int,int> is[N];
vector<pair<int,int>> all;
multiset<pair<int,pair<int,int>>> cur;
vector<int> L[N],R[N];
void go(int l,int r){
    if(l >= r) return;
    int mid = (l + r) >> 1;
    go(l,mid);
    go(mid + 1,r);
    timer++;
    int it = mid;
    for(int j:a[it]){
        used[j] = timer;
    }
    for(int i = mid + 1;i <= r;i++){
        for(int j:a[i]){
            used[j] = timer;
        }
        while(it >= l && used[c[it - 1]] == timer){
            it--;
            for(int j:a[it]){
                used[j] = timer;
            }
        }
        if(used[c[i]] == timer) continue;
        if(it >= l){
            L[it].push_back(i);
            R[i].push_back(it);
        }
    }
    timer++;
    it = mid + 1;
    for(int j:a[it]){
        used[j] = timer;
    }
    for(int i = mid;i >= l;i--){
        for(int j:a[i]){
            used[j] = timer;
        }
        while(it <= r && used[c[it]] == timer){
            it++;
            for(int j:a[it]){
                used[j] = timer;
            }
        }
        if(used[c[i - 1]] == timer) continue;
        if(it <= r){
            R[it].push_back(i);
            L[i].push_back(it);
        }
    }
}

void test(){
    cin >> n;
    for(int i = 1;i <= n - 1;i++){
        cin >> c[i];
    }
    for(int i = 1;i <= n;i++){
        cin >> b[i];
        for(int j = 1;j <=b[i];j++){
            int x;
            cin >> x;
            is[i][x] = 1;
            a[i].push_back(x);
        }
        if(!is[i].count(c[i]) && !is[i].count(c[i - 1])){
            array<int,3> f;
            f = {1,i,i};
            res[i] = f;
            L[i].push_back(i);
            R[i].push_back(i);
        }
    }
    L[1].push_back(n);
    R[n].push_back(1);
    go(1,n);

    for(int i = 1;i <=n;i++){
        for(int j:L[i]){
            cur.insert({j - i + 1,{i,j}});
        }
        if(!cur.empty()){
            res[i][1] = (*cur.begin()).second.first;
            res[i][2] = (*cur.begin()).second.second;
        }
        for(int j:R[i]){
            cur.erase(cur.find({i - j + 1,{j,i}}));
        }
    }
    int q;
    cin >> q;
    while(q--){
        int x,y;
        cin >> x >> y;
        cout << (y >= res[x][1] && y <= res[x][2] ? "YES\n":"NO\n");
    }
}
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1; // cin >> T;
    while (T--)
        test();
}

Compilation message

long_mansion.cpp:108:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  108 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 34 ms 142136 KB Output is correct
2 Correct 36 ms 142312 KB Output is correct
3 Correct 36 ms 142416 KB Output is correct
4 Correct 36 ms 141916 KB Output is correct
5 Correct 32 ms 141916 KB Output is correct
6 Correct 32 ms 142084 KB Output is correct
7 Correct 35 ms 142172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 142136 KB Output is correct
2 Correct 36 ms 142312 KB Output is correct
3 Correct 36 ms 142416 KB Output is correct
4 Correct 36 ms 141916 KB Output is correct
5 Correct 32 ms 141916 KB Output is correct
6 Correct 32 ms 142084 KB Output is correct
7 Correct 35 ms 142172 KB Output is correct
8 Correct 98 ms 143696 KB Output is correct
9 Correct 95 ms 143504 KB Output is correct
10 Correct 99 ms 143952 KB Output is correct
11 Correct 111 ms 144396 KB Output is correct
12 Correct 96 ms 143624 KB Output is correct
13 Correct 100 ms 143748 KB Output is correct
14 Correct 97 ms 143812 KB Output is correct
15 Correct 96 ms 143796 KB Output is correct
16 Correct 93 ms 144180 KB Output is correct
17 Correct 95 ms 143700 KB Output is correct
18 Correct 94 ms 143752 KB Output is correct
19 Correct 105 ms 143660 KB Output is correct
20 Correct 93 ms 143956 KB Output is correct
21 Correct 92 ms 143948 KB Output is correct
22 Correct 108 ms 143664 KB Output is correct
23 Correct 99 ms 143700 KB Output is correct
24 Correct 95 ms 143696 KB Output is correct
25 Correct 109 ms 143712 KB Output is correct
26 Correct 101 ms 143836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 268 ms 178776 KB Output is correct
2 Correct 273 ms 177660 KB Output is correct
3 Correct 272 ms 175100 KB Output is correct
4 Correct 279 ms 178256 KB Output is correct
5 Correct 288 ms 178004 KB Output is correct
6 Correct 190 ms 166236 KB Output is correct
7 Correct 181 ms 165676 KB Output is correct
8 Correct 164 ms 165716 KB Output is correct
9 Correct 169 ms 165760 KB Output is correct
10 Correct 191 ms 165720 KB Output is correct
11 Correct 165 ms 165628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 142136 KB Output is correct
2 Correct 36 ms 142312 KB Output is correct
3 Correct 36 ms 142416 KB Output is correct
4 Correct 36 ms 141916 KB Output is correct
5 Correct 32 ms 141916 KB Output is correct
6 Correct 32 ms 142084 KB Output is correct
7 Correct 35 ms 142172 KB Output is correct
8 Correct 98 ms 143696 KB Output is correct
9 Correct 95 ms 143504 KB Output is correct
10 Correct 99 ms 143952 KB Output is correct
11 Correct 111 ms 144396 KB Output is correct
12 Correct 96 ms 143624 KB Output is correct
13 Correct 100 ms 143748 KB Output is correct
14 Correct 97 ms 143812 KB Output is correct
15 Correct 96 ms 143796 KB Output is correct
16 Correct 93 ms 144180 KB Output is correct
17 Correct 95 ms 143700 KB Output is correct
18 Correct 94 ms 143752 KB Output is correct
19 Correct 105 ms 143660 KB Output is correct
20 Correct 93 ms 143956 KB Output is correct
21 Correct 92 ms 143948 KB Output is correct
22 Correct 108 ms 143664 KB Output is correct
23 Correct 99 ms 143700 KB Output is correct
24 Correct 95 ms 143696 KB Output is correct
25 Correct 109 ms 143712 KB Output is correct
26 Correct 101 ms 143836 KB Output is correct
27 Correct 268 ms 178776 KB Output is correct
28 Correct 273 ms 177660 KB Output is correct
29 Correct 272 ms 175100 KB Output is correct
30 Correct 279 ms 178256 KB Output is correct
31 Correct 288 ms 178004 KB Output is correct
32 Correct 190 ms 166236 KB Output is correct
33 Correct 181 ms 165676 KB Output is correct
34 Correct 164 ms 165716 KB Output is correct
35 Correct 169 ms 165760 KB Output is correct
36 Correct 191 ms 165720 KB Output is correct
37 Correct 165 ms 165628 KB Output is correct
38 Runtime error 301 ms 262144 KB Execution killed with signal 9
39 Halted 0 ms 0 KB -