# 随笔

 stack[++top][1] = 1; stack[top][0] = 0;
for (int i = 2; i <= l; i++)
{
while (top && height[i] < stack[top][0]) ri[stack[top--][1]] = i;
le[i] = stack[top][1]; stack[++top][1] = i; stack[top][0] = height[i];
}
while (top) ri[stack[top--][1]] = l + 1;


SA插入特殊值的时候最好插1

$T$组询问，每次给定$n$$m$，求$\sum_{i = 1}^{n} \sum_{j = 1}^{m} f_{gcd(i, j)}$

$g = \mu \ast f$

$g$的方法

void get_g_3(int N, const int *f, int *g) {
for (int i = 1; i <= N; i++) g[i] = f[i];
for (int i = 0; i < prime_count; i++)
for (int j = N / prime[i]; j >= 1; j--)
g[j * prime[i]] = (g[j * prime[i]] - g[j]) % mod;
} // Magic! O(nloglogn)


$f_p(n)=\begin{cases}f(n)&n=p^k\\0&otherwise\end{cases}$

$f=\prod_{p\ is\ prime}f_p$

$f\ast g(n)=\sum_{xy=n}f(x)g(y)$

$F(z)=\sum_{n\geq 1}\frac{f(n)}{n^z}=\prod_{p\ is\ prime}\sum_{k\geq 0}\frac{f(p^k)}{p^k}$

\begin{aligned}&\sum_{p\ is\ prime}\sum_{k\geq 1}\left\lfloor\frac{n}{p^k}\right\rfloor\\=&O\left(\sum_{p\leq n}\sum_{k\geq 1}\frac{n}{p^k}\right)\\=&O\left(\sum_{p\leq n}\frac{n}{p-1}\right)\\=&O(n\log\log n)\end{aligned}

$\frac{w}{x'} + 1 = \frac{w}{\frac{w}{gcd(w, h)}} + 1 = gcd(w, h) + 1$

      void Qm(int &x) { if (x >= MOD) x -= MOD; return; }


      void Qm(int &x) { x += x >> 31 & MOD; return; }


inline char nc(){
#define SIZE 1000000+3
static char buf[SIZE],*p1 = buf+SIZE,*p2 = buf+SIZE;
if(p1 == p2){
if(p1 == p2) return -1;
}
return *p1++;
#undef SIZE
}

template <typename T>
x = 0;int flag = 0;char ch = nc();
while(!isdigit(ch)){
if(ch == '-') flag = 1;
ch = nc();
}
while(isdigit(ch)){
x = (x<<1) + (x<<3) + (ch^'0');
ch = nc();
}
if(flag) x = -x;
}


$ZLOJ$的降智题目

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define MP std::make_pair
#define PII std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define CL(a, b) memset(a, b, sizeof a)
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define per(i, r, l) for (int i = (r); i >= (l); --i)
#define PE(x, a) for (int x = head[a]; x; x = edge[x].next)

typedef long long ll;

template <class T>
inline void rd(T &x) {
char c = getchar(), f = 0;
x = 0;
while (!isdigit(c)) f = (c == '-'), c = getchar();
while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
x = f ? -x : x;
}

const int MAXN = 1000 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int n, m, k;
std::vector<int> set[MAXN * 3];
int c[MAXN * 3], tp[MAXN * 3], sm[MAXN * 3];
ll del[MAXN][MAXN * 3], f[MAXN][MAXN * 3];
int sc[MAXN][MAXN * 3], cost[MAXN * 3];

int main() {
rd(n);
rd(m);
rd(k);
rep(i, 1, n) {
int b, a;
rd(a);
rd(b);
rd(c[i]);
set[c[i]].pb(a);
}
rep(i, 1, m) rd(cost[i]);

ll tot = 0;
rep(i, 1, m) {
std::sort(all(set[i]));

for (int j = 0, jj; j < set[i].size(); j = jj) {
jj = j;
while (jj < set[i].size() && set[i][j] == set[i][jj]) jj++;
sc[i][++tp[i]] = jj - j;
}

sm[i] = set[i].size();
std::sort(sc[i] + 1, sc[i] + tp[i] + 1);
std::reverse(sc[i] + 1, sc[i] + tp[i] + 1);//找出每个斜率的直线个数并从大到小排序。
int pres = 0;
ll prod = 0, sum = 0;
rep(j, 1, tp[i]) {
rep(jj, 1, sc[i][j]) del[i][pres + jj] = prod, tot += prod;//当最后的这些删去的时候只能影响到更靠后的了，就是这个prod，即从前面的中任选两条直线。

pres += sc[i][j];
prod += 1ll * sum * sc[i][j];//更新从一些直线里面任选两条。
sum += sc[i][j];//更新sum。
}
std::sort(del[i] + 1, del[i] + sm[i] + 1);
std::reverse(del[i] + 1, del[i] + sm[i] + 1);
rep(j, 1, sm[i]) del[i][j] += del[i][j - 1];//从大到小排序，前缀和算出删掉j条直线能去掉的三角形数量。
}

ll mx = 0;

CL(f, ~0x3f);
f[0][0] = 0;
rep(i, 1, m) {
rep(j, 0, k) for (int jj = 0; jj * cost[i] <= j && jj <= sm[i]; jj++)
f[i][j] = std::max(f[i][j], f[i - 1][j - jj * cost[i]] + del[i][jj]);
}//跑分组背包。
rep(i, 0, k) mx = std::max(mx, f[m][i]);

printf("%lld\n", tot - mx);
return 0;
}


posted @ 2020-06-12 10:29  Tian-Xing  阅读(105)  评论(0编辑  收藏  举报