比赛 防止浮躁的小练习v0.5 评测结果 AWWWWWWWWW
题目名称 罗伊德的防晒霜 最终得分 10
用户昵称 rewine 运行时间 0.256 s
代码语言 C++ 内存使用 4.89 MiB
提交时间 2016-10-15 16:47:01
显示代码纯文本
#pragma warning(disable: 4786)
#pragma G++ optimize ("O2")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm> 
#include <cctype>
#include <iostream>
 
#define Max(a,b) (a>b ? a:b)
#define Min(a,b) (a<b ? a:b)
#define Rep(_i,x,y) for(int _i = x; _i <= y;_i++)
 
using namespace std;
typedef unsigned int lg;
#define MAXX 100009
#define int long long
#define mod 99999997;
 
inline bool read(int &x){
	char c=getchar();
	while(c!=EOF&&!isdigit(c)) c=getchar();
	if(c==EOF) return 0; x=0;
	while(isdigit(c)) {
		x=x*10+c-'0';
		c=getchar();
	}
	return 1;
}
 
int n,ans = 0;
 
struct data{
	int x,v;
	bool operator < (const data &lhs) const {
	  return this->v < lhs.v;
	}
}a[MAXX],b[MAXX];
 
int t[MAXX],f[MAXX];
 
void Msort(int l,int r) {
	if(l == r) return;
	int m = (l+r) >> 1;
	Msort(l,m);Msort(m+1,r);
	int i = l,j = m+1,top = 0;
	while(i <= m && j <= r) {
		if(f[i] < f[j]) t[++top] = f[i++];
		else t[++top] = f[j++],ans = (ans+m-i+1)%mod;
	}
	while(i <= m) t[++top] = f[i++];
	while(j <= r) t[++top] = f[j++];
	memcpy(f+l,t+1,sizeof(int)*top);
}
 
signed main(void) {
	freopen("EOADtulad.in","r",stdin);
    freopen("EOADtulad.out","w",stdout);
    read(n);
    Rep(i,1,n) read(a[i].v),a[i].x = i;
    Rep(i,1,n) read(b[i].v),b[i].x = i;
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    Rep(i,1,n)
     f[b[i].x] = a[i].x;
    Msort(1,n);
    printf("%d",ans);
    fclose(stdin);fclose(stdout);
    return 0;
}