比赛 防止浮躁的小练习v0.4 评测结果 AAAAAAAAAA
题目名称 罗伊德的防晒霜 最终得分 100
用户昵称 Fmuckss 运行时间 1.221 s
代码语言 C++ 内存使用 14.02 MiB
提交时间 2016-10-13 18:53:02
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e6 + 10; 
const int lcy = 19283746; 

struct People {
	int v, lon;
	
	bool operator < (const People &b) const {
		return v < b.v;
	}
} ps[maxn];
int mst[maxn];
int s[maxn];
int ans;
int n;

inline void read() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d", &ps[i].v, &ps[i].lon);
	}
}

void merge_sort(int l, int r) {
	if(l >= r) return;
	int mid = (l + r) >> 1;
	
	merge_sort(l, mid);
	merge_sort(mid + 1, r);
	
	int i = l, j = mid + 1, now = l;
	
	while(i <= mid and j <= r) {
		if(s[i] > s[j]) mst[now++] = s[j++], ans += mid - i + 1;
		else mst[now++] = s[i++];
		
		if(ans >= lcy) ans -= lcy;
	}
	
	while(i <= mid) mst[now++] = s[i++];
	while(j <= r)   mst[now++] = s[j++];
	
	for(int k = l; k <= r; k++) s[k] = mst[k];
}

inline void solve() {
	sort(ps + 1, ps + n + 1);
	for (int i = 1; i <= n; i++) s[i] = ps[i].lon;
	
	merge_sort(1, n);
	printf("%d\n", ans);
}

int main() {
	freopen("EOADtulad.in","r",stdin); 
	freopen("EOADtulad.out","w",stdout); 
	read();
	solve();
	return 0;
}