【做题记录】Luogu 1366 有序表的合并

发布时间 2023-07-14 15:36:26作者: SHOJYS

Luogu 1366 有序表的合并

link

做法:双指针
注意:这两个数列都有序

代码:

#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cctype>
typedef long long LL;
typedef unsigned long long ULL;
namespace FastIo{
    typedef __uint128_t ULLL;
    static char buf[100000],*p1=buf,*p2=buf,fw[100000],*pw=fw;
    #define gc p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++
    inline void pc(const char &ch){
    	if(pw-fw==100000)fwrite(fw,1,100000,stdout),pw=fw;
    	*pw++=ch;
	}
    #define fsh fwrite(fw,1,pw-fw,stdout),pw=fw 
	struct FastMod{
        FastMod(ULL b):b(b),m(ULL((ULLL(1)<<64)/b)){}
        ULL reduce(ULL a){
            ULL q=(ULL)((ULLL(m)*a)>>64);
            ULL r=a-q*b;
            return r>=b?r-b:r;
        }
        ULL b,m;
    }HPOP(10);
    struct QIO{
    	char ch;
    	int st[40];
    	template<class T>inline void read(T &x){
    		x=0,ch=gc;
    		while(!isdigit(ch))ch=gc;
    		while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=gc;}
		}
		template<class T>inline void write(T a){
			do{st[++st[0]]=HPOP.reduce(a);a/=10;}while(a);
			while(st[0])pc(st[st[0]--]^48);
			pc('\n');
		}
	}qrw;
}
using namespace FastIo;
#define NUMBER1 10000000
#define P(A) A=-~A
#define fione(i,a,b) for(register int i=a;i<=b;P(i))
ULL a[NUMBER1+5],b[NUMBER1+5],ans;
signed main(){
	int T,n,m,p,cnt;
	qrw.read(T);
	while(T--){
		p=1,ans=0;
		qrw.read(n);
		qrw.read(m);
		fione(i,1,n)qrw.read(a[i]);
		fione(i,1,m)qrw.read(b[i]);
		fione(i,1,n){
			cnt=0;
			while(a[i]>=b[p]&&p<=m){
				if(a[i]==b[p])P(cnt);
				P(p);
			}
			ans^=cnt;
		}
		qrw.write(ans);
	}
	fsh;
    exit(0);
    return 0;
}