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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <vector>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);                                           
    cin.tie(NULL);

    int n,q;
    cin >> n >> q;
    vector< vector<bool> > outcomes;
        vector<bool> begin;
        for (int i = 0; i < n; i++) {
            begin.push_back(false);
        }
        outcomes.push_back(begin);
        
    for (int c = 0; c < q; c++) {
        char act;
        cin >> act;
        if (act == '+') {
            int a,b;
            cin >> a >> b;
            --a; --b;
            if (a == b) {
                for (long unsigned int i = 0; i < outcomes.size(); i++) {
                    vector<bool> &chance = outcomes[i];
                    if (chance[a]) {
                        outcomes.erase(outcomes.begin() + i);
                        --i;
                    } else {
                        chance[a] = true;
                    }
                }
            } else {
                long unsigned int size = outcomes.size();
                for (long unsigned int i = 0; i < size; i++) {
                    vector<bool> &chance = outcomes[i];
                    if (chance[a] && chance[b]) {
                        outcomes.erase(outcomes.begin() + i);
                        --size;
                        --i;
                    } else if (chance[a]) {
                        chance[b] = true;
                    } else if (chance[b]) {
                        chance[a] = true;
                    } else {
                        outcomes.push_back(chance);
                        vector<bool> &duplicate = outcomes[outcomes.size() - 1];
                        outcomes[i][a] = true;
                        duplicate[b] = true;
                    }
                }
            }
            
        } else if (act == '-') {
            int a;
            cin >> a;
            --a;
            for (long unsigned int i = 0; i < outcomes.size(); i++) {
                vector<bool> &chance = outcomes[i];
                if (chance[a]) {
                    chance[a] = false;
                } else {
                    outcomes.erase(outcomes.begin() + i);
                    --i;
                }
            }
        } else if (act == '?') {
            int a;
            long unsigned int y,n;
            y = n = 0;
            cin >> a;
            --a;
            for (long unsigned int i = 0; i < outcomes.size(); i++) {
                vector<bool> &chance = outcomes[i];
                if (chance[a]) {
                    ++y;
                } else {
                    ++n;
                }
            }
            if (y > 0 && n > 0) {
                cout << '?';
            } else if (y > 0) {
                cout << '1';
            } else {
                cout << '0';
            }
        }
        
        
    }
    
}