답안 #233259

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233259 2020-05-20T07:43:59 Z kartel Tenis (COI19_tenis) C++14
30 / 100
500 ms 21756 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +100500
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
#define pii pair <int, int>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

int n, q, a[4][N], ps[4][N], i, j, t, x, y, v;
bool mrk[N];
multiset <int> g[N];

bool bfs(int start)
{
    queue <int> qu;

    qu.push(start);
    mrk[start] = 1;
    int kl = 1;

    while (sz(qu))
    {
        int v = qu.front(); qu.pop();
        for (auto u : g[v])
        {
            if (mrk[u]) continue;
            qu.push(u);
            mrk[u] = 1;
            kl++;
        }
    }

    return kl == n;
}

int main()
{
    srand(time(0));
    ios_base::sync_with_stdio(0);
    iostream::sync_with_stdio(0);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

//    in("input.txt");
//    out("output.txt");

    cin >> n >> q;
    for (j = 1; j <= 3; j++)
    {
        for (i = 1; i <= n; i++)
        {
            cin >> a[j][i];
            ps[j][a[j][i]] = i;
            if (i > 1) g[a[j][i - 1]].insert(a[j][i]);
        }
    }

    while (q--)
    {
        cin >> t;
        if (t == 1)
        {
            cin >> v;
            for (i = 1; i <= n; i++) mrk[i] = 0;
            cout << ((bfs(v)) ? "DA" : "NE") << el;
        }
        else
        {
            cin >> t >> x >> y;
            i = ps[t][x];
            if (i > 1 && g[a[t][i - 1]].find(x) != g[a[t][i - 1]].end()) g[a[t][i - 1]].erase(g[a[t][i - 1]].find(x));
            if (i < n && g[x].find(a[t][i + 1]) != g[x].end()) g[x].erase(g[x].find(a[t][i + 1]));

            i = ps[t][y];
            if (i > 1 && g[a[t][i - 1]].find(y) != g[a[t][i - 1]].end()) g[a[t][i - 1]].erase(g[a[t][i - 1]].find(y));
            if (i < n && g[y].find(a[t][i + 1]) != g[y].end()) g[y].erase(g[y].find(a[t][i + 1]));

            swap(a[t][ps[t][x]], a[t][ps[t][y]]);
            swap(ps[t][x], ps[t][y]);

            i = ps[t][x];
            if (i > 1) g[a[t][i - 1]].insert(x);
            if (i < n) g[x].insert(a[t][i + 1]);

            i = ps[t][y];
            if (i > 1) g[a[t][i - 1]].insert(y);
            if (i < n) g[y].insert(a[t][i + 1]);
        }
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
7 Correct 8 ms 5248 KB Output is correct
8 Correct 7 ms 5248 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 8 ms 5248 KB Output is correct
11 Correct 8 ms 5248 KB Output is correct
12 Correct 8 ms 5248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
7 Correct 8 ms 5248 KB Output is correct
8 Correct 7 ms 5248 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 8 ms 5248 KB Output is correct
11 Correct 8 ms 5248 KB Output is correct
12 Correct 8 ms 5248 KB Output is correct
13 Correct 158 ms 21496 KB Output is correct
14 Correct 164 ms 21624 KB Output is correct
15 Correct 148 ms 21564 KB Output is correct
16 Correct 163 ms 21400 KB Output is correct
17 Correct 198 ms 21496 KB Output is correct
18 Correct 166 ms 21756 KB Output is correct
19 Correct 170 ms 21496 KB Output is correct
20 Correct 128 ms 21752 KB Output is correct
21 Correct 178 ms 21500 KB Output is correct
22 Correct 166 ms 21752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1097 ms 21624 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
7 Correct 8 ms 5248 KB Output is correct
8 Correct 7 ms 5248 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 8 ms 5248 KB Output is correct
11 Correct 8 ms 5248 KB Output is correct
12 Correct 8 ms 5248 KB Output is correct
13 Correct 158 ms 21496 KB Output is correct
14 Correct 164 ms 21624 KB Output is correct
15 Correct 148 ms 21564 KB Output is correct
16 Correct 163 ms 21400 KB Output is correct
17 Correct 198 ms 21496 KB Output is correct
18 Correct 166 ms 21756 KB Output is correct
19 Correct 170 ms 21496 KB Output is correct
20 Correct 128 ms 21752 KB Output is correct
21 Correct 178 ms 21500 KB Output is correct
22 Correct 166 ms 21752 KB Output is correct
23 Execution timed out 1097 ms 21624 KB Time limit exceeded
24 Halted 0 ms 0 KB -