Submission #1020200

# Submission time Handle Problem Language Result Execution time Memory
1020200 2024-07-11T16:46:30 Z Issa Werewolf (IOI18_werewolf) C++17
49 / 100
272 ms 78420 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 3e3 + 100;

int n;
int pref[maxn][maxn];
int suf[maxn][maxn];
vector<int> g[200100];

int get(int v, int p[]){
    if(p[v] == v) return v;
    return p[v] = get(p[v], p);
}

void join(int a, int b, int p[]){
    p[get(a, p)] = get(b, p);
}

void add(vector<int> &v){
    for(int &x: v) x++;
}

int mx[22][200100];
int mn[22][200100];
int b[200100], t;
int lg[200100];

void dfs(int v, int p = 0){
    t++; b[v] = t;
    mx[0][t] = mn[0][t] = v;
    for(int to: g[v]){
        if(to == p) continue;
        dfs(to, v);
    }
}

int getmn(int l, int r){
    int k = lg[r - l + 1];
    return min(mn[k][l], mn[k][r-(1<<k)+1]);
}

int getmx(int l, int r){
    int k = lg[r - l + 1];
    return max(mx[k][l], mx[k][r-(1<<k)+1]);
}

vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y,
                                std::vector<int> S, std::vector<int> E,
                                std::vector<int> L, std::vector<int> R){
    add(X); add(Y); add(S); add(E); add(L); add(R); n = N;
    for(int i = 0; i < X.size(); i++){
        g[X[i]].push_back(Y[i]);
        g[Y[i]].push_back(X[i]);
    }
    if(n <= 3000){
        for(int i = 1; i <= n; i++){
            pref[0][i] = suf[n+1][i] = i;
        }
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                pref[i][j] = pref[i-1][j];
            }
            for(int to: g[i]){
                if(to < i) join(to, i, pref[i]);
            }
        }
        for(int i = n; i > 0; i--){
            for(int j = 1; j <= n; j++){
                suf[i][j] = suf[i+1][j];
            }
            for(int to: g[i]){
                if(to > i) join(to, i, suf[i]);
            }
        }
        vector<int> ans;
        for(int i = 0; i < S.size(); i++){
            int s = S[i], e = E[i];
            int l = L[i], r = R[i];
            int res = 0;
            for(int k = l; k <= r; k++){
                if(get(s, suf[l]) == get(k, suf[l]) && get(k, pref[r]) == get(e, pref[r])){
                    res = 1;
                }
            }
            ans.push_back(res);
        }
        return ans;
    } else{
        for(int i = 1; i <= n; i++){
            if(g[i].size() == 1){
                dfs(i);
                break;
            }
        }
        for(int i = 2; i <= n; i++){
            lg[i] = lg[i >> 1] + 1;
        }
        for(int k = 1; k <= lg[n]; k++){
            for(int i = 1; i + (1<<k) - 1 <= n; i++){
                mx[k][i] = max(mx[k-1][i], mx[k-1][i+(1<<(k-1))]);
                mn[k][i] = min(mn[k-1][i], mn[k-1][i+(1<<(k-1))]);
            }
        }
        vector<int> ans;
        for(int i = 0; i < S.size(); i++){
            int s = S[i], e = E[i];
            int l = L[i], r = R[i];
            s = b[s]; e = b[e];
            int res = 0;
            if(s <= e){
                int tr = s - 1, tl = e + 1;
                for(int bl = s, br = e; bl <= br;){
                    int mid = (bl + br) >> 1;
                    if(getmn(s, mid) < l) br = mid - 1;
                    else bl = mid + 1, tr = mid;
                }
                for(int bl = s, br = e; bl <= br;){
                    int mid = (bl + br) >> 1;
                    if(getmx(mid, e) > r) bl = mid + 1;
                    else br = mid - 1, tl = mid;
                }
                if(tl <= tr) res = 1;
            } else{
                int tr = e - 1, tl = s + 1;
                for(int bl = e, br = s; bl <= br;){
                    int mid = (bl + br) >> 1;
                    if(getmn(mid, s) < l) bl = mid + 1;
                    else br = mid - 1, tl = mid;
                }
                for(int bl = e, br = s; bl <= br;){
                    int mid = (bl + br) >> 1;
                    if(getmx(e, mid) > r) br = mid - 1;
                    else bl = mid + 1, tr = mid;
                }
                if(tl <= tr) res = 1;
            }
            ans.push_back(res);
        }
        return ans;
    }
}

Compilation message

werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i = 0; i < X.size(); i++){
      |                    ~~^~~~~~~~~~
werewolf.cpp:77:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for(int i = 0; i < S.size(); i++){
      |                        ~~^~~~~~~~~~
werewolf.cpp:106:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         for(int i = 0; i < S.size(); i++){
      |                        ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5980 KB Output is correct
2 Correct 2 ms 5916 KB Output is correct
3 Correct 3 ms 5212 KB Output is correct
4 Correct 2 ms 5212 KB Output is correct
5 Correct 3 ms 5980 KB Output is correct
6 Correct 3 ms 5980 KB Output is correct
7 Correct 3 ms 5980 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Correct 2 ms 5980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5980 KB Output is correct
2 Correct 2 ms 5916 KB Output is correct
3 Correct 3 ms 5212 KB Output is correct
4 Correct 2 ms 5212 KB Output is correct
5 Correct 3 ms 5980 KB Output is correct
6 Correct 3 ms 5980 KB Output is correct
7 Correct 3 ms 5980 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Correct 2 ms 5980 KB Output is correct
10 Correct 82 ms 78164 KB Output is correct
11 Correct 85 ms 78164 KB Output is correct
12 Correct 64 ms 78160 KB Output is correct
13 Correct 78 ms 78160 KB Output is correct
14 Correct 67 ms 78164 KB Output is correct
15 Correct 79 ms 78420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 255 ms 67420 KB Output is correct
2 Correct 223 ms 67536 KB Output is correct
3 Correct 224 ms 67528 KB Output is correct
4 Correct 250 ms 67528 KB Output is correct
5 Correct 249 ms 67528 KB Output is correct
6 Correct 260 ms 67528 KB Output is correct
7 Correct 272 ms 67556 KB Output is correct
8 Correct 226 ms 67572 KB Output is correct
9 Correct 181 ms 67480 KB Output is correct
10 Correct 187 ms 67444 KB Output is correct
11 Correct 187 ms 67528 KB Output is correct
12 Correct 196 ms 67532 KB Output is correct
13 Correct 247 ms 67532 KB Output is correct
14 Correct 257 ms 67564 KB Output is correct
15 Correct 246 ms 67432 KB Output is correct
16 Correct 257 ms 67560 KB Output is correct
17 Correct 264 ms 67532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5980 KB Output is correct
2 Correct 2 ms 5916 KB Output is correct
3 Correct 3 ms 5212 KB Output is correct
4 Correct 2 ms 5212 KB Output is correct
5 Correct 3 ms 5980 KB Output is correct
6 Correct 3 ms 5980 KB Output is correct
7 Correct 3 ms 5980 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Correct 2 ms 5980 KB Output is correct
10 Correct 82 ms 78164 KB Output is correct
11 Correct 85 ms 78164 KB Output is correct
12 Correct 64 ms 78160 KB Output is correct
13 Correct 78 ms 78160 KB Output is correct
14 Correct 67 ms 78164 KB Output is correct
15 Correct 79 ms 78420 KB Output is correct
16 Correct 255 ms 67420 KB Output is correct
17 Correct 223 ms 67536 KB Output is correct
18 Correct 224 ms 67528 KB Output is correct
19 Correct 250 ms 67528 KB Output is correct
20 Correct 249 ms 67528 KB Output is correct
21 Correct 260 ms 67528 KB Output is correct
22 Correct 272 ms 67556 KB Output is correct
23 Correct 226 ms 67572 KB Output is correct
24 Correct 181 ms 67480 KB Output is correct
25 Correct 187 ms 67444 KB Output is correct
26 Correct 187 ms 67528 KB Output is correct
27 Correct 196 ms 67532 KB Output is correct
28 Correct 247 ms 67532 KB Output is correct
29 Correct 257 ms 67564 KB Output is correct
30 Correct 246 ms 67432 KB Output is correct
31 Correct 257 ms 67560 KB Output is correct
32 Correct 264 ms 67532 KB Output is correct
33 Incorrect 251 ms 58220 KB Output isn't correct
34 Halted 0 ms 0 KB -