1 # include <math. h> 2 # include <algorithm> 3 # include <string. h> 4 # include <string> 5 # include <ctime> 6 # include <queue> 7 # include <list> 8 # include <map> 9 # include <set> 10 # include <vector> 11 # include <stack> 12 # include <iostream> 13 # define INF 999999999 14 # define N 80010 15 using namespace std; 16 struct Nod 17 {18 int l, r; 19 int flag; 20} node [N <2]; // mark the Left and Right nodes with 21 22 void buildingTree (int l, int r, Int p) // build 23 {24 Nod & nd = node [p]; 25 nd. l = l; 26 nd. r = r; 27 nd. flag = 0; 28 if (l = r) 29 return; 30 int mid = (l + r)> 1; 31 buildingTree (l, mid, p * 2 ); 32 buildingTree (mid + 1, r, p * 2 + 1); 33} 34 35 void change (int p) // change the flag 36 {37 Nod & nd = node [p]; 38 nd. flag = 1-nd.flag; 39} 40 41 void updateTree (int l, int r, int p) 42 {43 Nod & nd = node [p]; 44 if (nd. l = l & nd. r = r) 45 {46 change (p); 47 return; 48} 49 if (nd. f Lag) // if the parent node is marked, 50 {51 change (2 * p); 52 change (2 * p + 1 ); 53 nd. flag = 1-nd.flag; // after the transfer is complete, change the flag back 54} 55 int mid = (nd. l + nd. r)> 1; 56 if (r <= mid) 57 updateTree (l, r, p * 2); 58 else if (l> mid) 59 updateTree (l, r, p * 2 + 1); 60 else 61 {62 updateTree (l, mid, p * 2); 63 updateTree (mid + 1, r, p * 2 + 1); 64} 65} 66 67 int queryTree (int idx, int p) // query 68 {69 Nod & nd = node [p]; 70 if (nd. l = idx & nd. r = idx) 71 retur N nd. flag; 72 if (nd. flag) // same as 73 {74 change (p * 2); 75 change (p * 2 + 1); 76 nd. flag = 1-nd.flag; 77} 78 int mid = (nd. l + nd. r)> 1; 79 if (mid> = idx) 80 return queryTree (idx, p * 2); 81 else if (mid <idx) 82 return queryTree (idx, p * 2 + 1); 83} 84 85 int main () 86 {87 int n, m; 88 while (~ Scanf ("% d", & n, & m) 89 {90 char str [4]; 91 buildingTree (1, n, 1 ); 92 while (m --) 93 {94 scanf ("% s", str); 95 int x, y; 96 if (str [0] ='s ') 97 {98 scanf ("% d", & x, & y); 99 updateTree (x, y, 1 ); 100} 101 else102 {103 scanf ("% d", & x); 104 printf ("% d \ n", queryTree (x, 1 )); 105} 106} 107} 108 return 0; 109}