#define _USE_MATH_DEFINES #include #include #include #include #include #include //#include #include #include #include #include #include #include ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define P(p) cout<<(p)< ///////// typedef long long LL; typedef long double LD; ///////// using namespace::std; ///////// const int nmax = 100000; int bell( const vector& in,vector* out){ int count=0; int f=-10,b=-10; rep( i, in.size() ){ if(b+1==in[i] ){ b = in[i]; }else{ if(f!=-10){ out->push_back( PII(f,b) ); ++count; } f = in[i]; b = in[i]; } } out->push_back( PII(f,b) ); ++count; return count; } int main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;// //cout << setprecision(16);// vector Aodd,Aeven,Bodd,Beven; vector Aoddvar,Aevenvar,Boddvar,Bevenvar; int L,M,N; cin>>L>>M>>N; Aodd.resize(L); Aeven.resize(L); Bodd.resize(M); Beven.resize(M); int ae=0; int ao=0; int be=0; int bo=0; int temp; rep(i,L){ cin>>temp; if(temp%2 != 0){ Aodd[ao] = temp/2; ++ao; }else{ Aeven[ae] = temp/2; ++ae; } } rep(i,M){ cin>>temp; if(temp%2 != 0){ Bodd[bo] = temp/2; ++bo; }else{ Beven[be] = temp/2; ++be; } } Aodd.resize(ao); Aeven.resize(ae); Bodd.resize(bo); Beven.resize(be); sort( Aodd.begin(), Aodd.end() ); sort( Aeven.begin(), Aeven.end() ); sort( Bodd.begin(), Bodd.end() ); sort( Beven.begin(), Beven.end() ); /////////// Aoddvar.reserve( Aodd.size() ); Aevenvar.reserve( Aeven.size() ); Boddvar.reserve( Bodd.size() ); Bevenvar.reserve( Beven.size() ); //////////// ao = bell( Aodd, &Aoddvar); ae = bell( Aeven, & Aevenvar); bo = bell( Bodd, &Boddvar ); be = bell( Beven, &Bevenvar ); /////////// vector::iterator Aitr,Bitr,Aend,Bend; int Q,ans=0,i2; int A_first,A_second,B_first,B_second; int As_Bf,Bs_Af; cin>>Q; stringstream ansSS; rep(i,Q){ ans=0; rep(oe,2) { if(i%2 == 0){ if( oe == 0){ Aitr = Aevenvar.begin(); Bitr = Bevenvar.begin(); Aend = Aevenvar.end(); Bend = Bevenvar.end(); }else{ Aitr = Aoddvar.begin(); Bitr = Boddvar.begin(); Aend = Aoddvar.end(); Bend = Boddvar.end(); } i2 = i/2; }else{ if( oe == 0){ Aitr = Aevenvar.begin(); Bitr = Boddvar.begin(); Aend = Aevenvar.end(); Bend = Boddvar.end(); i2 = i/2 + 1; }else{ Aitr = Aoddvar.begin(); Bitr = Bevenvar.begin(); Aend = Aoddvar.end(); Bend = Bevenvar.end(); i2 = i/2; } } while( Aitr != Aend && Bitr != Bend ){ A_first = Aitr->first; A_second = Aitr->second; B_first = Bitr->first + i2; B_second = Bitr->second + i2; As_Bf = Aitr->second - (Bitr->first + i2); Bs_Af = (Bitr->second + i2) - Aitr->first; if( As_Bf < 0 ){ ++Aitr; } else if( Bs_Af < 0){ ++Bitr; } else if( 0 <= B_first - A_first ){ if( 0 <= B_second - A_second ){ ans += As_Bf + 1; ++Aitr; }else{ ans += B_second - B_first + 1; ++Bitr; } }else{ if( 0 <= A_second - B_second ){ ans += Bs_Af + 1; ++Bitr; }else{ ans += A_second - A_first + 1; ++Aitr; } } } } ansSS << ans << '\n'; } cout << ansSS.str(); return 0; }