답안 #1015169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1015169 2024-07-06T06:58:59 Z deera 늑대인간 (IOI18_werewolf) C++14
49 / 100
338 ms 61332 KB
#include "werewolf.h"
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2e5 + 1, LG = 19; //(int)log2(MAX_N);
int mx[LG][MAX_N], mn[LG][MAX_N];

int getMN(int l, int r)
{
    int i = 0, p2 = 1;
    while (p2 <= r - l + 1)
        ++i, p2 <<= 1;
    --i, p2 >>= 1;
    return min(mn[i][l], mn[i][r - p2 + 1]);
}

int getMX(int l, int r)
{
    int i = 0, p2 = 1;
    while (p2 <= r - l + 1)
        ++i, p2 <<= 1;
    --i, p2 >>= 1;
    return max(mx[i][l], mx[i][r - p2 + 1]);
}

vector<int> check_validity(int N, vector<int> X, vector<int> Y,
                           vector<int> S, vector<int> E,
                           vector<int> L, vector<int> R)
{
    int M = X.size(), Q = S.size();
    vector<int> A(Q);

    if (N <= 3000 && M <= 6000 && Q <= 3000)
    { 
        vector<vector<int>> g(N);
        for (int i = 0; i < M; ++i)
        {
            g[X[i]].push_back(Y[i]);
            g[Y[i]].push_back(X[i]);
        }
        for (int qq = 0; qq < Q; ++qq)
        {
            int s = S[qq], e = E[qq], l = L[qq], r = R[qq];

            vector<bool> canHuman(N);
            queue<int> q;
            q.push(s), canHuman[s] = true;
            while (!q.empty())
            {
                int x = q.front();
                q.pop();
                for (int y : g[x])
                {
                    if (!canHuman[y] && y >= l)
                        q.push(y), canHuman[y] = true;
                }
            }

            vector<bool> canWolf(N);
            q.push(e), canWolf[e] = true;
            while (!q.empty())
            {
                int x = q.front();
                q.pop();
                for (int y : g[x])
                {
                    if (!canWolf[y] && y <= r)
                        q.push(y), canWolf[y] = true;
                }
            }

            for (int i = 0; i < N; ++i)
            {
                if (canHuman[i] && canWolf[i] && l <= i && i <= r)
                    A[qq] = 1;
            }
        }
    }
    else
    { 
        vector<vector<int>> g(N);
        for (int i = 0; i < M; ++i)
        {
            g[X[i]].push_back(Y[i]);
            g[Y[i]].push_back(X[i]);
        }

        int endPoint = 0;
        for (int i = 0; i < N; ++i)
        {
            if (g[i].size() == 1)
            {
                endPoint = i;
                break;
            }
        }

        vector<int> id(N);
        id[0] = endPoint;
        for (int i = 1, cur = g[id[0]][0]; i < N; ++i)
        {
            id[i] = cur;
            cur = g[cur][0] + g[cur][1] - id[i - 1];
        }

        vector<int> linePos(N);
        for (int i = 0; i < N; ++i)
            linePos[id[i]] = i;

        for (int i = 0; i < N; ++i)
            mx[0][i] = mn[0][i] = id[i];
        for (int i = 1, p2 = 1; i < LG; ++i, p2 <<= 1)
        {
            for (int j = 0; j < N; ++j)
            {
                mx[i][j] = max(mx[i - 1][j], mx[i - 1][j + p2]);
                mn[i][j] = min(mn[i - 1][j], mn[i - 1][j + p2]);
            }
        }

        for (int qq = 0; qq < Q; ++qq)
        {
            int s = S[qq], e = E[qq], l = L[qq], r = R[qq];
            s = linePos[s], e = linePos[e];

            if (s < e)
            {
                int left = s - 1, right = e; 
                while (left + 1 < right)
                {
                    int mid = (left + right) / 2;
                    if (getMX(mid, e) > r)
                        left = mid;
                    else
                        right = mid;
                }
                int lastH = left;
                left = s, right = e + 1; 
                while (left + 1 < right)
                {
                    int mid = (left + right) / 2;
                    if (getMN(s, mid) < l)
                        right = mid;
                    else
                        left = mid;
                }
                int firstW = right;

                if (lastH + 1 < firstW)
                    A[qq] = 1;
            }
            else
            {
              
                int left = e - 1, right = s;
                while (left + 1 < right)
                {
                    int mid = (left + right) / 2;
                    if (getMN(mid, s) < l)
                        left = mid;
                    else
                        right = mid;
                }
                int lastW = left;
                left = e, right = s + 1; 
                while (left + 1 < right)
                {
                    int mid = (left + right) / 2;
                    if (getMX(e, mid) > r)
                        right = mid;
                    else
                        left = mid;
                }
                int firstH = right;

                if (lastW + 1 < firstH)
                    A[qq] = 1;
            }
        }
    }

    return A;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 198 ms 748 KB Output is correct
11 Correct 92 ms 760 KB Output is correct
12 Correct 17 ms 604 KB Output is correct
13 Correct 210 ms 600 KB Output is correct
14 Correct 116 ms 736 KB Output is correct
15 Correct 172 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 272 ms 52776 KB Output is correct
2 Correct 269 ms 61316 KB Output is correct
3 Correct 268 ms 61268 KB Output is correct
4 Correct 298 ms 61264 KB Output is correct
5 Correct 284 ms 61268 KB Output is correct
6 Correct 304 ms 61332 KB Output is correct
7 Correct 280 ms 61196 KB Output is correct
8 Correct 229 ms 61268 KB Output is correct
9 Correct 175 ms 61268 KB Output is correct
10 Correct 182 ms 61264 KB Output is correct
11 Correct 181 ms 61076 KB Output is correct
12 Correct 205 ms 61264 KB Output is correct
13 Correct 284 ms 61192 KB Output is correct
14 Correct 282 ms 61264 KB Output is correct
15 Correct 251 ms 61264 KB Output is correct
16 Correct 261 ms 61076 KB Output is correct
17 Correct 338 ms 61268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 198 ms 748 KB Output is correct
11 Correct 92 ms 760 KB Output is correct
12 Correct 17 ms 604 KB Output is correct
13 Correct 210 ms 600 KB Output is correct
14 Correct 116 ms 736 KB Output is correct
15 Correct 172 ms 604 KB Output is correct
16 Correct 272 ms 52776 KB Output is correct
17 Correct 269 ms 61316 KB Output is correct
18 Correct 268 ms 61268 KB Output is correct
19 Correct 298 ms 61264 KB Output is correct
20 Correct 284 ms 61268 KB Output is correct
21 Correct 304 ms 61332 KB Output is correct
22 Correct 280 ms 61196 KB Output is correct
23 Correct 229 ms 61268 KB Output is correct
24 Correct 175 ms 61268 KB Output is correct
25 Correct 182 ms 61264 KB Output is correct
26 Correct 181 ms 61076 KB Output is correct
27 Correct 205 ms 61264 KB Output is correct
28 Correct 284 ms 61192 KB Output is correct
29 Correct 282 ms 61264 KB Output is correct
30 Correct 251 ms 61264 KB Output is correct
31 Correct 261 ms 61076 KB Output is correct
32 Correct 338 ms 61268 KB Output is correct
33 Runtime error 130 ms 53848 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -