MSBOP 2015 Round3 register

Ended

Participants:978

Verdict:AC | AC
Submitted:2015-05-09 15:16:24

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = int(1e5) + 50, K = 20;
namespace s
{
int n, k, dt[N], pos[K][N], len[K], kcnt;
LL cnt[K][K];
void calc (int x, int y) // y's contrib. to x
{
    int *X = pos[x], *Y = pos[y];
    for (int i = 1, j = 1; i <= len[y]; ++i)
    {
        while (j <= len[x] && X[j] < Y[i]) ++j;
        if (j > len[x]) break;
        // Y[i] will affect X[j] .. X[len[x]]
        cnt[x][y] += len[x] - j + 1;
    }
}
void init ()
{
    for (int i = 1; i <= kcnt; ++i)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX