比赛 防止浮躁的小练习v0.5 评测结果 AAAAAAAAAA
题目名称 罗伊德的防晒霜 最终得分 100
用户昵称 sxysxy 运行时间 1.251 s
代码语言 C++ 内存使用 11.73 MiB
提交时间 2016-10-15 16:33:18
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdarg>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 1000003
#define MOD 19283746    //woc? ???.jpg
struct goodgame
{
    int l, s;
    bool operator<(const goodgame &o) const 
    {
        return l < o.l;
    }
}ggs[MAXN];

int ans = 0;
int tmp[MAXN];
void msort(int l, int m, int r)
{
    int i = l;
    int j = m+1;
    int k = l;
    while(i <= m && j <= r)
    {
        if(ggs[i].s > ggs[j].s)
        {
            tmp[k++] = ggs[j++].s;
            ans = (ans+m-i+1)%MOD;
        }else
        {
            tmp[k++] = ggs[i++].s;
        }
    }
    while(i <= m)tmp[k++] = ggs[i++].s;
    while(j <= r)tmp[k++] = ggs[j++].s;
    for(int p = l; p <= r; p++)
        ggs[p].s = tmp[p];
}
void gg(int l, int r)
{
    if(l < r)
    {
        int m = (l+r)>>1;
        gg(l, m);
        gg(m+1, r);
        msort(l, m, r);
    }
}
int main()
{
    freopen("EOADtulad.in", "r", stdin);
    freopen("EOADtulad.out", "w", stdout);
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
        scanf("%d %d", &ggs[i].l, &ggs[i].s);
    sort(ggs+1, ggs+1+n);
    gg(1, n);    
    printf("%d\n", ans);
    return 0;
}