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
#include <bits/stdc++.h>
#include <cmath>
#include <stdlib.h>
using namespace std;
const long long mod = 1000000007;
class Miesz
{
public:
    int hasCom = 0;
};
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    Miesz m;
    int cnt = 0;
    vector<int> vec;
    vector<Miesz> miesz(n + 1, m);
    for (int i = 0; i < q; i++)
    {
        char c;
        cin >> c;
        if (c == '+')
        {
            int a, b;
            cin >> a >> b;
            if (std::find(vec.begin(), vec.end(), a) == vec.end())
            {
                vec.push_back(a);
            }
            if (std::find(vec.begin(), vec.end(), b) == vec.end())
            {
                vec.push_back(b);
            }
            cnt++;
            if (a != b)
            {
                miesz[a].hasCom = 1;
                miesz[b].hasCom = 1;
            }
            else
            {
                miesz[a].hasCom = 2;
            }
        }
        else if (c == '-')
        {
            int c;
            cin >> c;
            vec.erase(find(vec.begin(), vec.end(), c));
            cnt--;
            miesz[c].hasCom = 0;
        }
        else if (c == '?')
        {
            int d;
            cin >> d;
            if (miesz[d].hasCom == 0)
            {
                cout << '0';
            }
            else if (miesz[d].hasCom == 1)
            {
                if (vec.size() == cnt)
                {
                    cout << '1';
                }
                else
                {
                    cout << '?';
                }
            }
            else if (miesz[d].hasCom == 2)
            {
                cout << '1';
            }
        }
    }
    cout << '\n';
    return 0;
}