Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
34739 | A21μΘ_wjy | 【S】T3 | C++ | 通过 | 100 | 353 MS | 12560 KB | 1117 | 2024-11-14 14:27:54 |
#include<bits/stdc++.h> #define int long long #define PII pair<int,int> #define fir first #define sec second #define mp make_pair using namespace std; const int maxn=3e5+7; const int mod=998244353; int n,T; PII p[maxn]; int a[maxn],b[maxn]; int tmp[maxn]; bool vis[maxn]; inline void DFS(int i){ if(vis[i])return; vis[i]=1,DFS(b[i]); } signed main(){ #ifndef ONLINE_JUDGE freopen("sequence.in","r",stdin); freopen("sequence.out","w",stdout); #endif cin>>n>>T; for(int i=1;i<=n;i++)cin>>a[i]; for(int i=1;i<=n;i++)cin>>b[i]; for(int i=1;i<=n;i++)p[i]=mp(a[i],b[i]); sort(a+1,a+n+1);sort(b+1,b+n+1); int q1=0; for(int i=1;i<=n;i++)q1=(q1+(a[i]-b[i])*(a[i]-b[i])%mod)%mod; cout<<q1<<" "; if(!T)return 0; sort(p+1,p+n+1); for(int i=1;i<=n;i++)b[i]=p[i].sec,tmp[i]=p[i].sec; sort(tmp+1,tmp+n+1); int tot=unique(tmp+1,tmp+n+1)-tmp-1; for(int i=1;i<=n;i++)b[i]=lower_bound(tmp+1,tmp+tot+1,b[i])-tmp; int CYC=0; for(int i=1;i<=n;i++)if(!vis[i])DFS(i),CYC++; cout<<n-CYC<<endl; return 0; }