Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #define _CRT_SECURE_NO_WARNINGS
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- #include <vector>
- #include <stdio.h>
- #include <cmath>
- #include <math.h>
- #include <queue>
- #include <stack>
- #include <climits>
- #include <deque>
- #include <ctime>
- #include <iomanip>
- #include <bitset>
- #include <unordered_map>
- #include <unordered_set>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef unsigned int ui;
- #define mh() make_heap()
- #define poph() pop_heap()
- #define pushh() push_heap()
- #define sor(n) n.begin(), n.end()
- #define rsor(n) n.rbegin(), n.rend()
- #define mp make_pair
- #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
- #define p(T) pair<T,T>
- #define toch(x) cout.precision(x), cout.setf(ios::fixed)
- #define znac(l) abs(l)/l
- #define IOS ios::sync_with_stdio(false)
- #define IOSB cin.tie(0), cout.tie(0);
- const ll ok = ll(1e9 + 7);
- int t[131073*2];
- int n = 131072;
- ll gcd(ll a, ll b) {
- if (a == 0 || b == 0)
- {
- return max(a, b);
- }
- if (a == 1 || b == 1)
- return min(a, b);
- if (!b)
- return a;
- else return gcd(b, a%b);
- }
- void add(int pos, int new_val) {
- pos += n;
- t[pos] = new_val;
- for (pos = pos >> 1; pos; pos = pos >> 1)
- {
- int p = t[pos];
- t[pos] = gcd(t[(pos << 1 )+ 1], t[pos << 1]);
- if (p == t[pos])
- break;
- }
- }
- void del(int pos) {
- pos += n;
- t[pos] = 0;
- for (pos= pos >> 1;pos; pos = pos >> 1)
- {
- int p = t[pos];
- t[pos] = gcd(t[(pos << 1) + 1], t[pos << 1]);
- if (p == t[pos])
- break;
- }
- }
- int main()
- {
- IOSB;
- IOS;
- #ifdef TheCompiler
- files;
- #endif
- ll q;
- cin >> q;
- ll mxpos = 1;
- unordered_map<ll, vector<ll>>pos;
- for (int i = 1; i <= q; i++)
- {
- char a;
- ll b;
- cin >> a;
- if (a == '+')
- {
- cin >> b;
- pos[b].push_back(mxpos);
- add(mxpos, b);
- mxpos++;
- if (t[1] == 0)
- cout << 1 << endl;
- else
- cout << t[1] << endl;
- }
- else
- if (a == '-')
- {
- cin >> b;
- ll p= pos[b].back();
- del(p);
- pos[b].pop_back();
- if (t[1] == 0)
- cout << 1 << endl;
- else
- cout << t[1] << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement