1. 程式人生 > >【洛谷八連測R5】whzzt-Confidence

【洛谷八連測R5】whzzt-Confidence

-s lose int splay include size col 空間 ast

題目描述

題目難度不一定按照題目順序遞增

請註意本題的空間限制為2333-2500KB!(前三個測試點的空間限制為2500KB)

給定兩個長度相同的序列,這兩個序列至多有 1 處不同。你的任務是找出這處不同。

輸入輸出格式

技術分享

說明

技術分享

代碼

標程

技術分享
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int mo=998244353;
template<class
T> inline void read(T &x){ x=0; char ch=getchar(); while(ch<0||ch>9) ch=getchar(); while(ch>=0&&ch<=9){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} } ll ksm(ll a,int p){ ll res=1; for(;p;p>>=1,a=a*a%mo) if(p&1) res=res*a%mo; return
res; } int T,n,m; ll a,b,x; int main(){ read(T); while(T--){ read(n); a=b=0; for(int i=1;i<=n;++i){ read(x); a=(a+x*i)%mo; b=(b+(ll)i*i%mo*x)%mo; } for(int i=1;i<=n;++i){ read(x); a=(a-x*i)%mo; b=(b-(ll)i*i%mo*x)%mo; }
if(!a) printf("0\n"); else printf("1 %lld\n",(b*ksm(a,mo-2)%mo+mo)%mo); } return 0; }
View Code

異或做法

技術分享
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
template<class T>
inline void read(T &x){
    x=0; char ch=getchar();
    while(ch<0||ch>9) ch=getchar();
    while(ch>=0&&ch<=9){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
}
int T,n; ll x,a;
int f[33],cur,last;
inline void solve(){
    for(int i=1;i<=n;++i){
        read(x); a^=x; cur=0;
        while(x){
            if(x&1) f[cur]^=i;
            ++cur; x>>=1;
        }
    }
}
int main(){
    read(T);
    while(T--){
        read(n); a=0;
        memset(f,0,sizeof(f));
        solve(); solve();
        if(!a) printf("0\n");
        else {
            cur=0; printf("1 ");
            while(a){
                if(a&1){printf("%d\n",f[cur]); break;}
                ++cur; a>>=1;
            }
        }
    }
    return 0;
}
View Code

【洛谷八連測R5】whzzt-Confidence