답안 #144315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
144315 2019-08-16T15:45:57 Z SamAnd Tenis (COI19_tenis) C++17
100 / 100
256 ms 8176 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 100005;
struct ban
{
    int laz;
    int i, minu;
    ban(){}
    ban(int i, int minu)
    {
        laz = 0;
        this->i = i;
        this->minu = minu;
    }
};

int n, q;
int a[N][4];

int maxu(int i)
{
    int ans = 0;
    for (int k = 1; k <= 3; ++k)
        ans = max(ans, a[i][k]);
    return ans;
}

ban t[N * 4];

ban mer(const ban& l, const ban& r)
{
    if (l.minu < r.minu)
        return l;
    if (l.minu > r.minu)
        return r;
    if (l.i < r.i)
        return l;
    return r;
}

void bil(int tl, int tr, int pos)
{
    if (tl == tr)
    {
        t[pos] = ban(tl, tl);
        return;
    }
    int m = (tl + tr) / 2;
    bil(tl, m, pos * 2);
    bil(m + 1, tr, pos * 2 + 1);
    t[pos] = mer(t[pos * 2], t[pos * 2 + 1]);
}

void shi(int pos)
{
    if (t[pos].laz == 0)
        return;
    t[pos * 2].minu += t[pos].laz;
    t[pos * 2 + 1].minu += t[pos].laz;
    t[pos * 2].laz += t[pos].laz;
    t[pos * 2 + 1].laz += t[pos].laz;
    t[pos].laz = 0;
}

void ubd(int tl, int tr, int l, int r, int y, int pos)
{
    if (tl == l && tr == r)
    {
        t[pos].minu += y;
        t[pos].laz += y;
        return;
    }
    shi(pos);
    int m = (tl + tr) / 2;
    if (r <= m)
        ubd(tl, m, l, r, y, pos * 2);
    else if (l > m)
        ubd(m + 1, tr, l, r, y, pos * 2 + 1);
    else
    {
        ubd(tl, m, l, m, y, pos * 2);
        ubd(m + 1, tr, m + 1, r, y, pos * 2 + 1);
    }
    t[pos] = mer(t[pos * 2], t[pos * 2 + 1]);
    t[pos].laz = 0;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d%d", &n, &q);
    for (int k = 1; k <= 3; ++k)
    {
        for (int i = 1; i <= n; ++i)
        {
            int x;
            scanf("%d", &x);
            a[x][k] = i;
        }
    }
    bil(1, n, 1);
    for (int i = 1; i <= n; ++i)
        ubd(1, n, maxu(i), n, -1, 1);
    while (q--)
    {
        int ty;
        scanf("%d", &ty);
        if (ty == 1)
        {
            int x;
            scanf("%d", &x);
            if (maxu(x) <= t[1].i)
                printf("DA\n");
            else
                printf("NE\n");
        }
        else
        {
            int p, x, y;
            scanf("%d%d%d", &p, &x, &y);
            ubd(1, n, maxu(x), n, 1, 1);
            ubd(1, n, maxu(y), n, 1, 1);
            swap(a[x][p], a[y][p]);
            ubd(1, n, maxu(x), n, -1, 1);
            ubd(1, n, maxu(y), n, -1, 1);
        }
    }
    return 0;
}

Compilation message

tenis.cpp: In function 'int main()':
tenis.cpp:92:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~
tenis.cpp:98:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
tenis.cpp:108:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &ty);
         ~~~~~^~~~~~~~~~~
tenis.cpp:112:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
tenis.cpp:121:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d%d", &p, &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 368 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 368 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 100 ms 6720 KB Output is correct
14 Correct 103 ms 6720 KB Output is correct
15 Correct 102 ms 6724 KB Output is correct
16 Correct 101 ms 6652 KB Output is correct
17 Correct 101 ms 6648 KB Output is correct
18 Correct 95 ms 6648 KB Output is correct
19 Correct 153 ms 6648 KB Output is correct
20 Correct 111 ms 6904 KB Output is correct
21 Correct 97 ms 6672 KB Output is correct
22 Correct 102 ms 6772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 5240 KB Output is correct
2 Correct 132 ms 5240 KB Output is correct
3 Correct 136 ms 5276 KB Output is correct
4 Correct 126 ms 5368 KB Output is correct
5 Correct 128 ms 5240 KB Output is correct
6 Correct 129 ms 5264 KB Output is correct
7 Correct 129 ms 5252 KB Output is correct
8 Correct 148 ms 5264 KB Output is correct
9 Correct 125 ms 5240 KB Output is correct
10 Correct 123 ms 5240 KB Output is correct
11 Correct 127 ms 5372 KB Output is correct
12 Correct 128 ms 5356 KB Output is correct
13 Correct 128 ms 5336 KB Output is correct
14 Correct 140 ms 5248 KB Output is correct
15 Correct 128 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 368 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 100 ms 6720 KB Output is correct
14 Correct 103 ms 6720 KB Output is correct
15 Correct 102 ms 6724 KB Output is correct
16 Correct 101 ms 6652 KB Output is correct
17 Correct 101 ms 6648 KB Output is correct
18 Correct 95 ms 6648 KB Output is correct
19 Correct 153 ms 6648 KB Output is correct
20 Correct 111 ms 6904 KB Output is correct
21 Correct 97 ms 6672 KB Output is correct
22 Correct 102 ms 6772 KB Output is correct
23 Correct 129 ms 5240 KB Output is correct
24 Correct 132 ms 5240 KB Output is correct
25 Correct 136 ms 5276 KB Output is correct
26 Correct 126 ms 5368 KB Output is correct
27 Correct 128 ms 5240 KB Output is correct
28 Correct 129 ms 5264 KB Output is correct
29 Correct 129 ms 5252 KB Output is correct
30 Correct 148 ms 5264 KB Output is correct
31 Correct 125 ms 5240 KB Output is correct
32 Correct 123 ms 5240 KB Output is correct
33 Correct 127 ms 5372 KB Output is correct
34 Correct 128 ms 5356 KB Output is correct
35 Correct 128 ms 5336 KB Output is correct
36 Correct 140 ms 5248 KB Output is correct
37 Correct 128 ms 5212 KB Output is correct
38 Correct 252 ms 8076 KB Output is correct
39 Correct 157 ms 7800 KB Output is correct
40 Correct 253 ms 8064 KB Output is correct
41 Correct 173 ms 8056 KB Output is correct
42 Correct 174 ms 8048 KB Output is correct
43 Correct 245 ms 8056 KB Output is correct
44 Correct 156 ms 7940 KB Output is correct
45 Correct 186 ms 7920 KB Output is correct
46 Correct 162 ms 7892 KB Output is correct
47 Correct 171 ms 7864 KB Output is correct
48 Correct 156 ms 7808 KB Output is correct
49 Correct 180 ms 8056 KB Output is correct
50 Correct 152 ms 7848 KB Output is correct
51 Correct 178 ms 7924 KB Output is correct
52 Correct 256 ms 8064 KB Output is correct
53 Correct 164 ms 7944 KB Output is correct
54 Correct 168 ms 7928 KB Output is correct
55 Correct 180 ms 8176 KB Output is correct
56 Correct 173 ms 7928 KB Output is correct
57 Correct 151 ms 8080 KB Output is correct
58 Correct 199 ms 7968 KB Output is correct