#include using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template bool chmax(T &a, const T &b) { if(a bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N,A[101010]; int Q; ll L,R,ret; int cnt[101010]; template class SegTree_1 { public: vector>> val; SegTree_1(){val.resize(NV*2);}; int getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i p=val[k][pos]; if(p.second V, int l=0,int r=NV,int k=1) { int m=(l+r)/2; int VL=V.size(); int i,c=0,CR=0; FOR(i,VL) { while(CR1) { vector LV,RV; FORR(v,V) { if(A[v] st1; SegTree_1<2,1<<20> st2; SegTree_1<3,1<<20> st3; void solve() { int i,j,k,l,r,x,y; string s; cin>>N; vector V; FOR(i,N) { cin>>A[i]; V.push_back(i); } st1.build(V); st2.build(V); st3.build(V); cin>>Q; while(Q--) { cin>>L>>R; L=(L^ret)-1; R=(R^ret); int a=st1.getval(L,R); int b=st2.getval(L,R); int c=st3.getval(L,R); ret=min(a+b+c,(int)(R-L-(a==0)-(b==0)-(c==0))); cout<