fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. int n,q,j=1,a[300005],bit[300005],ans[300005];
  5. map <int,int> mp;
  6. pair <pair<int,int>,int> p[300005];
  7. void UPDATE(int i, int v)
  8. {
  9. while (i<=n) bit[i]^=v,i+=i&(-i);
  10. return;
  11. }
  12. int GET(int l, int r)
  13. {
  14. l--;
  15. int resl=0,resr=0;
  16. while (l>0) resl^=bit[l],l-=l&(-l);
  17. while (r>0) resr^=bit[r],r-=r&(-r);
  18. return (resr^resl);
  19. }
  20. signed main()
  21. {
  22. ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
  23. cin>>n>>q;
  24. for (int i=1;i<=n;i++) cin>>a[i];
  25. for (int i=1;i<=q;i++) cin>>p[i].first.second>>p[i].first.first,p[i].second=i;
  26. sort(p+1,p+q+1);
  27. for (int i=1;i<=n;i++)
  28. {
  29. if (!mp[a[i]]) UPDATE(i,a[i]),mp[a[i]]=i;
  30. else UPDATE(mp[a[i]],a[i]),UPDATE(i,a[i]),mp[a[i]]=i;
  31. while (p[j].first.first==i) ans[p[j].second]=GET(p[j].first.second,p[j].first.first),j++;
  32. }
  33. for (int i=1;i<=q;i++) cout<<ans[i]<<' ';
  34. return 0;
  35. }
Success #stdin #stdout 0s 5556KB
stdin
Standard input is empty
stdout
Standard output is empty