Submission #374483

# Submission time Handle Problem Language Result Execution time Memory
374483 2021-03-07T10:29:57 Z vishesh312 Experimental Charges (NOI19_charges) C++17
44 / 100
37 ms 3436 KB
#include "bits/stdc++.h"
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/

#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()

using ll = long long;
const int mod = 1e9+7;

struct UFDS {
    vector<int> siz, link;
    UFDS(int n) {
        siz.resize(n, 1);
        link.resize(n);
        for (int i = 0; i < n; ++i) link[i] = i;
    }
    int find(int x) {
        while (x != link[x]) x = link[x];
        return x;
    }
    bool same(int a, int b) {
        return find(a) == find(b);
    }
    void unite(int a, int b) {
        a = find(a);
        b = find(b);
        if (a == b) return;
        if (siz[a] < siz[b]) swap(a, b);
        siz[a] += siz[b];
        link[b] = a;
    }
};

void solve(int tc) {
    int n, q;
    cin >> n >> q;
    UFDS ufds(2*n);
    while (q--) {
        char x;
        int a, b;
        cin >> x >> a >> b;
        if (x == 'Q') {
            if (ufds.same(a, b)) cout << 'R' << '\n';
            else if (ufds.same(a+n, b)) cout << 'A' << '\n';
            else cout << '?' << '\n';
        } else {
            if (x == 'R') {
                ufds.unite(a, b);
                ufds.unite(a+n, b+n);
            } else {
                ufds.unite(a+n, b);
                ufds.unite(a, b+n);
            }
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int tc = 1;
    //cin >> tc;
    for (int i = 1; i <= tc; ++i) solve(i);
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 2796 KB Output is correct
2 Correct 25 ms 2796 KB Output is correct
3 Correct 28 ms 2796 KB Output is correct
4 Correct 27 ms 2796 KB Output is correct
5 Correct 24 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3308 KB Output is correct
2 Correct 27 ms 3308 KB Output is correct
3 Correct 37 ms 3308 KB Output is correct
4 Correct 32 ms 3308 KB Output is correct
5 Correct 30 ms 3308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3180 KB Output is correct
2 Correct 29 ms 3308 KB Output is correct
3 Correct 30 ms 3052 KB Output is correct
4 Correct 31 ms 3436 KB Output is correct
5 Correct 30 ms 3180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Runtime error 1 ms 492 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 25 ms 2796 KB Output is correct
7 Correct 25 ms 2796 KB Output is correct
8 Correct 28 ms 2796 KB Output is correct
9 Correct 27 ms 2796 KB Output is correct
10 Correct 24 ms 2796 KB Output is correct
11 Correct 27 ms 3308 KB Output is correct
12 Correct 27 ms 3308 KB Output is correct
13 Correct 37 ms 3308 KB Output is correct
14 Correct 32 ms 3308 KB Output is correct
15 Correct 30 ms 3308 KB Output is correct
16 Correct 27 ms 3180 KB Output is correct
17 Correct 29 ms 3308 KB Output is correct
18 Correct 30 ms 3052 KB Output is correct
19 Correct 31 ms 3436 KB Output is correct
20 Correct 30 ms 3180 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Runtime error 1 ms 492 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -