답안 #680783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680783 2023-01-11T19:07:51 Z BhavayGoyal Experimental Charges (NOI19_charges) C++14
100 / 100
23 ms 1560 KB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T> using oset = 
            tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ld long double
#define ar array
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define endl "\n"

const int MOD = 1e9+7;
const int inf = 1e9;
const ll linf = 1e18;

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};


// -------------------------------------------------- Main Code --------------------------------------------------

const int N = 1e5+5;
pii par[N];
int sz[N];

pii find(int v) {
    if (par[v].f == v) return par[v];
    pii pr = find(par[v].f);
    return par[v] = {pr.f, pr.s^par[v].s};
}

void Union(int a, int b, bool f) {
    pii aa = find(a); pii bb = find(b);
    if (aa.f == bb.f) return;
    if (sz[aa.f] < sz[bb.f]) swap(aa, bb);
    par[bb.f] = {aa.f, aa.s^bb.s^f};
    sz[aa.f] += sz[bb.f];
}

void sol() {
    int n, q; cin >> n >> q;
    for (int i = 0; i <= n; i++) par[i] = {i, 0}, sz[i] = 1;
    while (q--) {
        char x; cin >> x;
        int a, b; cin >> a >> b;
        if (x == 'Q') {
            pii aa = find(a); pii bb = find(b);
            if (aa.f != bb.f) cout << "?" << endl;
            else cout << (aa.s!=bb.s?"A":"R") << endl;
        }
        else Union(a, b, (x=='A'));
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t; 
    while (t--) {
        sol();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1492 KB Output is correct
2 Correct 17 ms 1492 KB Output is correct
3 Correct 18 ms 1460 KB Output is correct
4 Correct 19 ms 1468 KB Output is correct
5 Correct 22 ms 1512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1528 KB Output is correct
2 Correct 21 ms 1480 KB Output is correct
3 Correct 21 ms 1536 KB Output is correct
4 Correct 23 ms 1492 KB Output is correct
5 Correct 22 ms 1560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1492 KB Output is correct
2 Correct 20 ms 1488 KB Output is correct
3 Correct 19 ms 1428 KB Output is correct
4 Correct 20 ms 1532 KB Output is correct
5 Correct 20 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 356 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 17 ms 1492 KB Output is correct
7 Correct 17 ms 1492 KB Output is correct
8 Correct 18 ms 1460 KB Output is correct
9 Correct 19 ms 1468 KB Output is correct
10 Correct 22 ms 1512 KB Output is correct
11 Correct 21 ms 1528 KB Output is correct
12 Correct 21 ms 1480 KB Output is correct
13 Correct 21 ms 1536 KB Output is correct
14 Correct 23 ms 1492 KB Output is correct
15 Correct 22 ms 1560 KB Output is correct
16 Correct 20 ms 1492 KB Output is correct
17 Correct 20 ms 1488 KB Output is correct
18 Correct 19 ms 1428 KB Output is correct
19 Correct 20 ms 1532 KB Output is correct
20 Correct 20 ms 1492 KB Output is correct
21 Correct 1 ms 356 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 23 ms 1476 KB Output is correct
27 Correct 20 ms 1460 KB Output is correct
28 Correct 19 ms 1428 KB Output is correct
29 Correct 20 ms 1484 KB Output is correct
30 Correct 23 ms 1496 KB Output is correct