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
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool find (vector<int> val, int a) {
	for (int i = 0;i < val.size();i++) {
		if (val[i] == a) {
			return true;
		}
	}

	return false;
}

int main () {
	ios_base::sync_with_stdio(0);

	int n = 0;
	int q = 0;

	cin >> n >> q;

	char c = 0;
	int a = 0;
	int b = 0;

	vector<int> moze;
	vector<int> pewno;
	vector<int> nie;

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

		switch (c) {
			case '+':
				cin >> a >> b;
				if (a == b) {
					pewno.push_back(a);
				} else {
					if (!find(moze, a) || !find(moze, b)) {
						moze.push_back(a);
						moze.push_back(b);
					} else {
						moze.erase(remove(moze.begin(), moze.end(), a), moze.end());
						moze.erase(remove(moze.begin(), moze.end(), b), moze.end());
						pewno.push_back(a);
						pewno.push_back(b);
					}
				}
				break;
			case '-':
				cin >> a;
				moze.erase(remove(moze.begin(), moze.end(), a), moze.end());
				pewno.erase(remove(pewno.begin(), pewno.end(), a), pewno.end());
				break;
			case '?':
				cin >> a;

				if (find(pewno, a)) {
					cout << '1';
				} else if (find(moze, a)) {
					cout << '?';
				} else {
					cout << '0';
				}

				break;
		}
	}

	return 0;
}