1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;

    map<int, int> computer_status; 
    for (int i = 1; i <= n; i++) {
        computer_status[i] = 0; 
    }

    char type;
    int a, b;
    string result = "";

    for (int i = 0; i < q; i++) {

        cin >> type;
        if (type == '+') {
            cin >> a >> b;
            if (a == b) {

                computer_status[a] = 1;
            }
            else {
                if (computer_status[a] == 0 && computer_status[b] == 0) {

                    computer_status[a] = computer_status[b] = -1;
                }
                else if (computer_status[a] != 0) {

                    computer_status[b] = 1;
                }
                else if (computer_status[b] != 0) {

                    computer_status[a] = 1;
                }
            }
        }
        else if (type == '-') {

            cin >> a;
            computer_status[a] = 0; 
        }
        else if (type == '?') {

            cin >> a;
            if (computer_status[a] == 1) {

                result += '1';
            }
            else if (computer_status[a] == 0) {

                result += '0';
            }
            else {

                result += '?';
            }
        }
    }

    cout << result << endl;

    return 0;
}