Title Description
A password machine generates a password as follows: First enter a series of numbers into the machine, then take out some of them, and then get a new number as the password. Now please simulate the operation of such a machine, the user through the input Control command to generate the password. A sequence is stored in the cipher machine and is initially empty. There are 3 types of control commands for the cipher machine:
ADD < number >
Put < number > to the end of the series.
REMOVE < number >
Find the first number in the series that equals < # >, and remove it from the sequence.
XOR between < Number1 > and < Number2 >
For each sequence of values greater than or equal to < Number1 > and less than or equal to < Number2 >, the output is the final result as a password. If only one number satisfies the condition, output this number. If no number satisfies the condition, the output is 0.
You can assume that the user does not remove a number that does not exist in the series, and that all inputs do not exceed 20000. Input Format
Includes a series of control commands. Each control command occupies a single row. There are no extra blank lines in the input file. The file does not exceed 60000 lines. output Format
For each XOR command, the output line, in turn, includes the password generated by your password machine. The output file should not contain any extra characters sample data Sample input
ADD 5
ADD 6
XOR between 1 and 10
REMOVE 5
XOR between 6 and 8 sample output
3
6 Topic Analysis
Because the XOR inverse is itself, the addition and subtraction of the operation is a truth, can be different or complete.
for query operations, you might want to use a tree array to maintain the sequence, just change the addition of the tree array to an XOR source code
#include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include < cstdlib> #include <vector> #include <cstdio> #include <cmath> #include <queue> using
namespace Std;
inline const int Get_int () {int num=0,bj=1;
Char X=getchar (); while (x< ' 0 ' | |
X> ' 9 ') {if (x== '-') bj=-1;
X=getchar ();
} while (x>= ' 0 ' &&x<= ' 9 ') {num=num*10+x-' 0 ';
X=getchar ();
} return NUM*BJ;
} const int maxn=500005;
struct BIT {int N,C[MAXN];
inline int lowbit (int x) {//Low operation return x& (-X);
} void init (int n) {this->n=n;
Memset (C,0,sizeof (c));
} void Add (int x,int v) {for (int i=x; i<=n; i+=lowbit (i)) c[i]^=v;
} int sum (int x) {int s=0;
for (int i=x; i; i-=lowbit (i)) s^=c[i];
return s;
}} bit;
int main () {Ios::sync_with_stdio (false);
string order; Bit.init (20005); while (Cin>>order) {if (order== "ADD" | |
order== "REMOVE") {int A;
cin>>a;
Bit.add (A,a);
} else {string mdzz;
int left,right;
cin>>mdzz>>left>>mdzz>>right;
if (left>right) puts ("0");
else printf ("%d\n", (Bit.sum (right) ^bit.sum (Left-1)));
}} return 0; }