2274: [Usaco2011 Feb]Generic Cow Protests Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 196  Solved: 122[Submit][Status] Description Farmer John's N (1 <= N <= 100,000) cows are lined up in a row and numbered 1..N. The cows are conducting another…
康托展开 裸的康托展开&逆康托展开 康托展开就是一种特殊的hash,且是可逆的…… 康托展开计算的是有多少种排列的字典序比这个小,所以编号应该+1:逆运算同理(-1). 序列->序号:(康托展开) 对于每个数a[i],数比它小的数有多少个在它之前没出现,记为b[i],$ans=1+\sum b[i]* (n-i)!$ 序号->序列:(逆康托展开) 求第x个排列所对应的序列,先将x-1,然后对于a[i],$\left\lfloor \frac{x}{(n-i)!} \right\rflo…
题目描述 Farmer John's N (1 <= N <= 100,000) cows are lined up in a row andnumbered 1..N. The cows are conducting another one of their strangeprotests, so each cow i is holding up a sign with an integer A_i(-10,000 <= A_i <= 10,000). FJ knows the…
[题解] 很容易可以写出朴素DP方程f[i]=sigma f[j] (sum[i]>=sum[j],1<=j<=i).  于是我们用权值树状数组优化即可. #include<cstdio> #include<algorithm> #define N 200010 #define rg register #define LL long long #define Mod (1e9+9) using namespace std; int n,n2; LL t[N],f[…
Description Farmer John's N (1 <= N <= 100,000) cows are lined up in a row and numbered 1..N. The cows are conducting another one of their strange protests, so each cow i is holding up a sign with an integer A_i (-10,000 <= A_i <= 10,000). FJ…
http://www.lydsy.com/JudgeOnline/problem.php?id=3301 其实这一题很早就a过了,但是那时候看题解写完也是似懂非懂的.... 听zyf神犇说是康托展开,然后拖到今天才来看看... sad.. 从不知道那里来的文档里边抄的: 康托展开就是一种特殊的哈希函数,它的使用范围是对于n个数的排列进行状态的压缩和存储.X=a[n]*(n-1)!+a[n-1]*(n-2)!+…+a[i]*(i-1)!+…+a[2]*1!+a[1]*0! 其中,a为整数,并且0<…
[题意]给定n个点的图,正权无向边,正负权有向边,保证对有向边(u,v),v无法到达u,求起点出发到达所有点的最短距离. [算法]拓扑排序+dijkstra [题解]因为有负权边,直接对原图进行spfa,加slf优化后可过,但是这道题就没意思了. 理论上,最短路问题用spfa是不能保证复杂度的,但dijkstra的问题是不能处理负权边. 因为题目保证不能返回,实际上有向边将全图分成了几个部分.如果把仅由无向边连接的连通块看成点,则原图变成DAG. 对连通块内部进行dijkstra,在DAG上用拓…
http://www.lydsy.com/JudgeOnline/problem.php?id=3052 题意:n个带颜色的点(m种),q次询问,每次询问x到y的路径上sum{w[次数]*v[颜色]},可以单点修改颜色.(n, m, q<=100000) #include <bits/stdc++.h> using namespace std; const int N=100005, M=100005; typedef long long ll; inline int getint()…
http://www.lydsy.com/JudgeOnline/problem.php?id=3319 题意:给一棵n节点的树(n<=1e6),m个操作(m<=1e6),每次操作有两种:1.查询u到根的第一条黑边的编号.2.将u到v的路径全部染成黑色 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream>…
http://www.lydsy.com/JudgeOnline/problem.php?id=3319 以为是模板题就复习了下hld............................. 然后nlg^2n被tle成翔了.............................. 然后看题解QAQ,,,这... 神题做法...待会再写...(upd:[BZOJ]3319: 黑白树) tle的hld: #include <cstdio> #include <cstring> #i…