#include <iostream> #include <vector> #include <utility> #include <map> #include <string> using namespace std; int main() { string result; int numPersons; int numEvents; cin >> numPersons >> numEvents; pair<char, vector<int>> events[numEvents]; map<int, int> sure_elems; map<int, int> not_sure_elems; int amountOfPlusEventsRead = 0; int first, second; char character; for(int i = 0; i < numEvents; i++) { cin >> character; events[i].first = character; if(events[i].first == '+') { cin >> first >> second; events[i].second.push_back(first); events[i].second.push_back(second); } else { cin >> first; events[i].second.push_back(first); } } for(int i = 0; i < numEvents; i++) { if(not_sure_elems.size() == amountOfPlusEventsRead && amountOfPlusEventsRead > 0) { for ( const auto &p : not_sure_elems ) { sure_elems[p.first] = 1; } not_sure_elems.clear(); } if(events[i].first == '-') { sure_elems[events[i].second[0]] = 0; } else if(events[i].first == '+') { amountOfPlusEventsRead++; if(events[i].second[0] == events[i].second[1]) { sure_elems[events[i].second[0]] = 1; } else { not_sure_elems[events[i].second[0]]++; not_sure_elems[events[i].second[1]]++; } } else if(events[i].first == '?') { auto it = not_sure_elems.find(events[i].second[0]); if (it != not_sure_elems.end()) { result += "?"; } else { result += to_string(sure_elems[events[i].second[0]]); } } } cout << result << "\n"; 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 | #include <iostream> #include <vector> #include <utility> #include <map> #include <string> using namespace std; int main() { string result; int numPersons; int numEvents; cin >> numPersons >> numEvents; pair<char, vector<int>> events[numEvents]; map<int, int> sure_elems; map<int, int> not_sure_elems; int amountOfPlusEventsRead = 0; int first, second; char character; for(int i = 0; i < numEvents; i++) { cin >> character; events[i].first = character; if(events[i].first == '+') { cin >> first >> second; events[i].second.push_back(first); events[i].second.push_back(second); } else { cin >> first; events[i].second.push_back(first); } } for(int i = 0; i < numEvents; i++) { if(not_sure_elems.size() == amountOfPlusEventsRead && amountOfPlusEventsRead > 0) { for ( const auto &p : not_sure_elems ) { sure_elems[p.first] = 1; } not_sure_elems.clear(); } if(events[i].first == '-') { sure_elems[events[i].second[0]] = 0; } else if(events[i].first == '+') { amountOfPlusEventsRead++; if(events[i].second[0] == events[i].second[1]) { sure_elems[events[i].second[0]] = 1; } else { not_sure_elems[events[i].second[0]]++; not_sure_elems[events[i].second[1]]++; } } else if(events[i].first == '?') { auto it = not_sure_elems.find(events[i].second[0]); if (it != not_sure_elems.end()) { result += "?"; } else { result += to_string(sure_elems[events[i].second[0]]); } } } cout << result << "\n"; return 0; } |