4 条题解

  • 0
    @ 2026-5-29 18:22:33

    注意到ai最大到1e20,开ull即可,看错了,2^20,使用int即可

    
    
    void solve() {
        int n,m;
        cin >> n >> m;
        vi a(n + 1),s(n + 1,0);
        for(int i = 1; i <= n ; i ++ ) {
            cin >> a[i];
            s[i] = s[i - 1] ^ a[i];
        }
        for(int i = 0 ; i < m ; i ++ ) {
            int l,r;
            cin >> l >> r;
            cout << (s[r]^s[l - 1]) << endl;
        }
    }
    
    
    • 0
      @ 2026-4-9 15:06:14

      import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer;

      public class Main { public static void main(String[] args) throws IOException { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out);

      	int n = fs.nextInt();
      	int m = fs.nextInt();
      	int[] s = new int[n + 1];
      	for(int i = 0;i < n;i++) {
      		s[i + 1] = s[i] ^ fs.nextInt();
      	}
      	while(m-- > 0) {
      		int l = fs.nextInt();
      		int r = fs.nextInt();
      		out.println(s[r] ^ s[l - 1]);
      	}
      	out.flush();
      }
      
      static class FastScanner {
      	BufferedReader br;
      	StringTokenizer st;
      
      	public FastScanner() {
      		br = new BufferedReader(new InputStreamReader(System.in));
      	}
      
      	boolean hasNext() throws IOException {
      		while (st == null || !st.hasMoreTokens()) {
      			String line = br.readLine();
      			if (line == null)
      				return false;
      			st = new StringTokenizer(line);
      		}
      		return true;
      	}
      
      	public String next() throws IOException {
      		hasNext();
      		return st.nextToken();
      	}
      
      	public int nextInt() throws IOException {
      		return Integer.parseInt(next());
      	}
      
      	public long nextLong() throws IOException {
      		return Long.parseLong(next());
      	}
      
      	public double nextDouble() throws IOException {
      		return Double.parseDouble(next());
      	}
      
      	public String readLine() throws IOException {
      		return br.readLine();
      	}
      }
      

      }

      • 0
        @ 2026-3-28 21:48:04
        #include<bits/stdc++.h>
        using namespace std;
        int a[200005];
        int s[200005];
        
        int main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
           
            int n,m;
            cin>>n>>m;
            for(int i=1;i<=n;++i)
            {
                cin>>a[i];
                s[i]=s[i-1]^a[i];
            }
            while(m--)
            {
                int l,r;
                cin>>l>>r;
                cout<<(s[r]^s[l-1])<<endl;
            }
        
         return 0;
        }
        
        • 0
          @ 2026-3-9 14:56:30
          import sys
          input = lambda:sys.stdin.readline().strip()
          
          n,m=map(int,input().split())
          a=[0]+list(map(int,input().split()))
          s=[0]*len(a)
          
          for i in range(1,n+1):
              s[i]=s[i-1]^a[i]
          
          for _ in range(m):
              l,r=map(int,input().split())
              print(s[r]^s[l-1])
          
          • 1

          信息

          ID
          825
          时间
          1000ms
          内存
          256MiB
          难度
          3
          标签
          递交数
          475
          已通过
          270
          上传者