Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <vector>
- #include <algorithm>
- #define LEFT(n) (2(n))
- #define RIGHT (n) (2(n)+1)
- #define NEUT 2147483647
- using namespace std;
- vector<int> numeros;
- int arbol[2000000];
- int oper(int a,int b)
- {
- if(!a)
- return b;
- return oper(b%a,a);
- }
- void constructor(int nodo,int izq,int der)
- {
- if(izq==der)
- {
- arbol[nodo]=numeros[izq];
- return;
- }
- int mitad=(izq+der)/2;
- constructor(2*nodo,izq,mitad);
- constructor(2*nodo+1,mitad+1,der);
- arbol[nodo]=oper(arbol[2*nodo],arbol[2*nodo+1]);
- }
- int consulta(int nodo,int izq,int der,int start,int end)
- {
- if(end<izq || start>der)
- return NEUT;
- if(start>=izq and end<=der)
- return arbol[nodo];
- int respuesta_izq=consulta(2*nodo,izq,(izq+der)/2,start,end);
- int respuesta_der=consulta(2*nodo+1,(izq+der)/2+1,der,start,end);
- return oper(respuesta_izq,respuesta_der);
- }
- void update(int nodo,int izq,int der,int pos,int valor)
- {
- if(pos<izq || pos>der)
- return;
- if(izq==der)
- {
- arbol[nodo]=numeros[izq]=valor;
- return;
- }
- int mitad=(izq+der)/2;
- if(pos<mitad)
- update(2*nodo,izq,mitad,pos,valor);
- else
- update(2*nodo+1,mitad+1,der,pos,valor);
- arbol[nodo]=oper(arbol[2*nodo],arbol[2*nodo+1]);
- }
- int main()
- {
- int N,aux;
- char aux2;
- scanf("%d",&N);
- for(int i=0;i<N;i++)
- {
- cin>>aux2>>aux;
- if(aux2=='+')
- numeros.push_back(aux);
- else
- {
- for(int j=0;j<numeros.size();j++)
- if(numeros[j]==aux)
- {
- numeros.erase(numeros.begin()+j);
- break;
- }
- }
- if(numeros.empty())
- {
- printf("1\n");
- continue;
- }
- constructor(0,0,numeros.size()-1);
- printf("%d\n",consulta(0,0,numeros.size()-1,0,numeros.size()-1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement