import java.util.*;
import java.lang.*;
import java.io.*;

class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;


        st =  new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int Q = Integer.parseInt(st.nextToken());


        
        int[] arr = new int[N+1];

        int totalXor = 0;

        List<Integer> active = new ArrayList<>();

        StringBuilder sb = new StringBuilder();

        for (int i=0; i<Q; i++) {
            st =  new StringTokenizer(br.readLine());
            int c = Integer.parseInt(st.nextToken());
            if(c==1) {
                int x = Integer.parseInt(st.nextToken());

                //Xor제거를 한다.
                totalXor ^= arr[x]; 

                if(arr[x] == 0) {
                    active.add(x);
                }
                
                arr[x] ++;
                totalXor ^= arr[x];
                
            } else {
                // 여기서 배열 전 구간에서 -를 하면 Q회쿼리 x N회 순회로 시간초과가 되니..
                //근데 어떻게 ... 0인 값은 더 이상 안내려간다.. 0이 아닌 값을 별도의 리스트이 등록해서 이 값만 처리한다.
                // 아니 별도의 리스트보다 더 좋은 방법이 있나....
                List<Integer> nextActive = new ArrayList<>();

                for (int x: active) {
                    totalXor ^= arr[x];

                    arr[x] --;

                    totalXor ^= arr[x];

                    if(arr[x] > 0) {
                        nextActive.add(x);
                    }
                }

                active = nextActive;
            }
            sb.append(totalXor).append("\n");
        }
        System.out.println(sb);
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: