Submission #233251

# Submission time Handle Problem Language Result Execution time Memory
233251 2020-05-20T07:34:51 Z kartel Tenis (COI19_tenis) C++14
0 / 100
500 ms 21600 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;

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

    int i = 1;
    while (i <= n && mrk[i]) i++;

    return i > 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]].erase(g[a[t][i - 1]].find(x));
            if (i < n) g[x].erase(g[x].find(a[t][i + 1]));

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

            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]);
        }
    }
}

# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Runtime error 15 ms 10240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Runtime error 15 ms 10240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Runtime error 15 ms 10240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 21600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Runtime error 15 ms 10240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -