답안 #647497

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647497 2022-10-03T01:17:52 Z LeonaRaging Experimental Charges (NOI19_charges) C++14
32 / 100
44 ms 8464 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define ll long long
#define pb push_back
#define db(val) "[" #val " = " << (val) << "] "

const ll mod = 1e9 + 7;
const int maxn = 1e5 + 4;
const int INF = 1e9;

int n, q, sign[maxn];

struct DisjointSet {
    int par[maxn];
    vector<int> mySet[maxn];
    DisjointSet(int n) {
        for (int i = 1; i <= n; i++)
            par[i] = i, mySet[i].pb(i);
    }
    int find(int x) {
        if (x != par[x]) par[x] = find(par[x]);
        return par[x];
    }
    bool join(int u, int v, int type) {
        u = find(u); v = find(v);
        if (u == v) return 0;
        if (mySet[v].size() > mySet[u].size())
            swap(mySet[u], mySet[v]);
        for (int x : mySet[v]) {
            if (type == 1) sign[x] ^= 1;
            mySet[u].pb(x);
        }
        mySet[v].clear();
        par[v] = u;
        return 1;
    }
};

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen(".INP", "r", stdin);
    //freopen(".OUT", "w", stdout);
    cin >> n >> q;
    memset(sign, 1, sizeof sign);
    DisjointSet Dsu(n);
    for (int i = 1; i <= q; i++) {
        char type; int u, v; cin >> type >> u >> v;
        if (type == 'Q') {
            if (Dsu.find(u) != Dsu.find(v)) cout << '?';
            else cout << (sign[u] == sign[v] ? 'R' : 'A');
            cout << '\n';
        }
        else Dsu.join(u, v, (type == 'R' ? 0 : 1));
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3448 KB Output is correct
3 Correct 2 ms 3448 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 3 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 7624 KB Output is correct
2 Correct 39 ms 7668 KB Output is correct
3 Correct 33 ms 7636 KB Output is correct
4 Correct 33 ms 7740 KB Output is correct
5 Correct 29 ms 7752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 8180 KB Output is correct
2 Correct 38 ms 8136 KB Output is correct
3 Correct 36 ms 8136 KB Output is correct
4 Correct 44 ms 8412 KB Output is correct
5 Correct 39 ms 8464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 8088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3448 KB Output is correct
3 Correct 2 ms 3448 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 3 ms 3412 KB Output is correct
6 Incorrect 3 ms 3448 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3448 KB Output is correct
3 Correct 2 ms 3448 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 3 ms 3412 KB Output is correct
6 Correct 42 ms 7624 KB Output is correct
7 Correct 39 ms 7668 KB Output is correct
8 Correct 33 ms 7636 KB Output is correct
9 Correct 33 ms 7740 KB Output is correct
10 Correct 29 ms 7752 KB Output is correct
11 Correct 29 ms 8180 KB Output is correct
12 Correct 38 ms 8136 KB Output is correct
13 Correct 36 ms 8136 KB Output is correct
14 Correct 44 ms 8412 KB Output is correct
15 Correct 39 ms 8464 KB Output is correct
16 Incorrect 28 ms 8088 KB Output isn't correct
17 Halted 0 ms 0 KB -