Lang:G++
Edit12345678910111213141516171819202122232425262728293031#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)