#include <iostream> #include <vector> #include <algorithm> using namespace std; vector<pair<int, int>> pv; int main() { int q, n, a, b, c, d; char cm; bool flag = false; cin >> q >> n; vector<char> bv(q); vector<char> otp; for (int i = 0; i < n; i++) { cin >> cm; if (cm == '+') { cin >> a >> b; if (a < b) { pv.push_back({a, b}); } else { pv.push_back({b, a}); } } if (cm == '-') { cin >> c; bv[c - 1] = 0; } if (cm == '?') { cin >> d; for (int j = 0; j < pv.size(); j++) { if (pv[j].first == d || pv[j].second == d) { flag == true; if (pv[j + 1].first == d || pv[j + 1].second == d) { otp.push_back('1'); break; } } } if (flag == true) { otp.push_back('?'); } else { otp.push_back('0'); } flag = false; } sort(pv.begin(), pv.end(), [](const auto &a, const auto &b) { return a.first < b.first; }); } for (int i = 0; i < otp.size(); i++) { cout << otp[i]; } return 0; }
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; vector<pair<int, int>> pv; int main() { int q, n, a, b, c, d; char cm; bool flag = false; cin >> q >> n; vector<char> bv(q); vector<char> otp; for (int i = 0; i < n; i++) { cin >> cm; if (cm == '+') { cin >> a >> b; if (a < b) { pv.push_back({a, b}); } else { pv.push_back({b, a}); } } if (cm == '-') { cin >> c; bv[c - 1] = 0; } if (cm == '?') { cin >> d; for (int j = 0; j < pv.size(); j++) { if (pv[j].first == d || pv[j].second == d) { flag == true; if (pv[j + 1].first == d || pv[j + 1].second == d) { otp.push_back('1'); break; } } } if (flag == true) { otp.push_back('?'); } else { otp.push_back('0'); } flag = false; } sort(pv.begin(), pv.end(), [](const auto &a, const auto &b) { return a.first < b.first; }); } for (int i = 0; i < otp.size(); i++) { cout << otp[i]; } return 0; } |