Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <math.h>
- #include <algorithm>
- #include <vector>
- #include <set>
- #include <map>
- using namespace std;
- long long prom3(long long a, long long b) {
- long long nod = 1L;
- long long tmp;
- if (a == 0L)
- return b;
- if (b == 0L)
- return a;
- if (a == b)
- return a;
- if (a == 1L || b == 1L)
- return 1L;
- while (a != 0 && b != 0) {
- if (((a & 1L) | (b & 1L)) == 0L) {
- nod <<= 1L;
- a >>= 1L;
- b >>= 1L;
- continue;
- }
- if (((a & 1L) == 0L) && (b & 1L)) {
- a >>= 1L;
- continue;
- }
- if ((a & 1L) && ((b & 1L) == 0L)) {
- b >>= 1L;
- continue;
- }
- if (a > b) {
- tmp = a;
- a = b;
- b = tmp;
- }
- tmp = a;
- a = (b - a) >> 1L;
- b = tmp;
- }
- if (a == 0)
- return nod * b;
- else
- return nod * a;
- }
- long long NOD(map <long long, int> sc)
- {
- auto prom1=sc.begin();
- long long prom2 = prom1->first;
- for (auto i = sc.begin(); i != sc.end(); i++)
- {
- prom2 = prom3(prom2, i->first);
- }
- return prom2;
- }
- int main()
- {
- int n, prom2 = 0;
- map <long long, int> sc;
- vector <int> answer;
- cin >> n;
- for (int i = 1; i <= n; i++)
- {
- int prom;
- string h;
- cin >> h;
- cin >> prom;
- if (h == "+")
- {
- if (sc.find(prom) != sc.end())
- {
- sc[prom]++;
- if (sc.size() != 0)
- cout << prom2 << endl;
- else
- cout << 1 << endl;
- }
- else
- {
- sc.insert(pair <long long, int>(prom, 1));
- prom2 = prom3(prom2, prom);
- cout << prom2 << endl;
- }
- }
- else
- if (sc.find(prom) != sc.end())
- if (sc[prom] == 1)
- {
- sc.erase(prom);
- if (sc.size() != 0)
- {
- prom2 = NOD(sc);
- cout << prom2 << endl;
- }
- else
- cout << 1 << endl;
- }
- else
- {
- sc[prom]--;
- if (sc.size() != 0)
- cout << prom2 << endl;
- else
- cout << 1 << endl;
- }
- else
- if (sc.size() != 0)
- cout << prom2 << endl;
- else
- cout << 1 << endl;
- }
- /*if (answer.size() != 0)
- for (auto i = answer.begin(); i != answer.end(); i++)
- cout << *i << endl;
- else
- cout << 1;*/
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment