比赛 |
防止浮躁的小练习v0.4 |
评测结果 |
AAAAAAAAAA |
题目名称 |
罗伊德的防晒霜 |
最终得分 |
100 |
用户昵称 |
BillAlen |
运行时间 |
1.347 s |
代码语言 |
C++ |
内存使用 |
11.76 MiB |
提交时间 |
2016-10-13 21:23:59 |
显示代码纯文本
#include <fstream>
#include <algorithm>
#define MAX_N 1000000
#define MOD 19283746
using namespace std;
struct Line {
int a,b;
} lines[MAX_N];
int n, tmp[MAX_N], ans;
int cmp(const Line &x, const Line &y){
return x.a < y.a;
}
void Merge(int l, int m, int r){
int i = l, j = m + 1, k = l;
while(i <= m && j <= r){
if(lines[i].b > lines[j].b){
tmp[k++] = lines[j++].b;
ans = (ans + m - i + 1) % MOD;
} else tmp[k++] = lines[i++].b;
}
while(i <= m) tmp[k++] = lines[i++].b;
while(j <= r) tmp[k++] = lines[j++].b;
for(int i = l; i <= r; ++i)
lines[i].b = tmp[i];
}
void Merge_sort(int l, int r){
if(l < r){
int m = (l + r) >> 1;
Merge_sort(l, m);
Merge_sort(m + 1, r);
Merge(l, m, r);
}
}
int main(){
fstream in("EOADtulad.in", ios::in), out("EOADtulad.out", ios::out);
in >> n;
for(int i = 0; i < n; ++i)
in >> lines[i].a >> lines[i].b;
sort(lines, lines + n, cmp);
Merge_sort(0, n - 1);
out << (ans % MOD) << endl;
}