怕不是我再不写题解这题就该成没人做也没人会的千古谜题了......

T1:


仔细分析题面,发现相同就是广义SAM上节点相同,相似就是广义SAM上为从根到某个点路径的前缀。、
直接SAM上跑从根开始,每个点下界为1的最小流即可。
代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<map>
  6. #include<queue>
  7. #define debug cout
  8. using namespace std;
  9. const int maxn=5e3+1e2;
  10. const int inf=0x3f3f3f3f;
  11.  
  12. int in[maxn],n,ans,sum;
  13.  
  14. namespace NetworkFlow {
  15. int s[maxn<<],t[maxn<<],nxt[maxn<<],f[maxn<<],dep[maxn<<],deg[maxn<<],cnt=;
  16. int bak[maxn<<],bcnt;
  17. int st,ed,_s,_t;
  18. inline void coredge(int from,int to,int flow) {
  19. t[++cnt] = to , f[cnt] = flow ,
  20. nxt[cnt] = s[from] , s[from] = cnt;
  21. }
  22. inline void singledge(int from,int to,int flow) {
  23. coredge(from,to,flow) , coredge(to,from,);
  24. }
  25. inline bool bfs() {
  26. memset(dep,-,sizeof(dep)) , dep[st] = ;
  27. queue<int> q; q.push(st);
  28. while( q.size() ) {
  29. const int pos = q.front(); q.pop();
  30. for(int at=s[pos];at;at=nxt[at])
  31. if( f[at] && !~dep[t[at]] ) {
  32. dep[t[at]] = dep[pos] + , q.push(t[at]);
  33. }
  34. }
  35. return ~dep[ed];
  36. }
  37. inline int dfs(int pos,int flow) {
  38. if( pos == ed ) return flow;
  39. int ret = , now = ;
  40. for(int at=s[pos];at;at=nxt[at])
  41. if( f[at] && dep[t[at]] > dep[pos] ) {
  42. now = dfs(t[at],min(flow,f[at])) ,
  43. ret += now , flow -= now ,
  44. f[at] -= now , f[at^] += now;
  45. if( !flow ) return ret;
  46. }
  47. if( !ret ) dep[pos] = -;
  48. return ret;
  49. }
  50. inline int dinic() {
  51. int ret = , now = ;
  52. while( bfs() ) {
  53. while( ( now = dfs(st,inf) ) )
  54. ret += now;
  55. }
  56. return ret;
  57. }
  58. inline int findflow() {
  59. for(int at=s[_t];at;at=nxt[at])
  60. if( t[at] == _s ) return f[at^];
  61. }
  62. inline void backup() {
  63. memcpy(bak,s,sizeof(s)) , bcnt = cnt;
  64. }
  65. inline void restore() {
  66. memcpy(s,bak,sizeof(bak)) , cnt = bcnt;
  67. }
  68. }
  69.  
  70. namespace SAM {
  71. map<int,int> ch[maxn<<];
  72. int fa[maxn<<],len[maxn<<],root,last,cnt;
  73.  
  74. inline int NewNode(int ll) {
  75. len[++cnt] = ll;
  76. return cnt;
  77. }
  78. inline void extend(int x) {
  79. int p = last;
  80. int np = NewNode(len[p]+);
  81. while( p && ch[p].find(x) == ch[p].end() ) ch[p][x] = np , p = fa[p];
  82. if( !p ) fa[np] = root;
  83. else {
  84. int q = ch[p][x];
  85. if( len[q] == len[p] + ) fa[np] = q;
  86. else {
  87. int nq = NewNode(len[p]+);
  88. ch[nq] = ch[q] , fa[nq] = fa[q];
  89. fa[np] = fa[q] = nq;
  90. while( p && ch[p][x] == q ) ch[p][x] = nq , p = fa[p];
  91. }
  92. }
  93. last = np;
  94. }
  95. inline void Ex_extend(int* sou,int li) {
  96. last = root;
  97. for(int i=;i<=li;i++) {
  98. if( ch[last].find(sou[i]) != ch[last].end() ) last = ch[last][sou[i]];
  99. else extend(sou[i]);
  100. }
  101. }
  102. }
  103.  
  104. inline void build() {
  105. using SAM::ch;using SAM::cnt;
  106. using namespace NetworkFlow;
  107. _s = cnt * + , _t = _s + , st = _t + , ed = st + ;
  108. #define cov(x) (x+cnt)
  109. for(int i=;i<=cnt;i++) {
  110. if( i != ) ++deg[i] , --deg[cov(i)];
  111. for(map<int,int>::iterator it=ch[i].begin();it!=ch[i].end();it++) {
  112. const int tar = it->second;
  113. if( i == ) singledge(_s,tar,);
  114. else singledge(cov(i),tar,);
  115. }
  116. if( i != ) singledge(cov(i),_t,);
  117. }
  118. backup();
  119. for(int i=;i<=_t;i++) {
  120. if( !deg[i] ) continue;
  121. if( deg[i] > ) singledge(i,ed,deg[i]) , sum += deg[i];
  122. else singledge(st,i,-deg[i]);
  123. }
  124. singledge(_t,_s,inf);
  125. }
  126. inline int getans() {
  127. using namespace NetworkFlow;
  128. int d = dinic();
  129. if( d != sum ) return -; // No solution .
  130. int ret = findflow();
  131. restore();
  132. st = _t , ed = _s;
  133. int dd = dinic();
  134. return ret - dd;
  135. }
  136.  
  137. int main() {
  138. static int m;
  139. SAM::root = SAM::NewNode();
  140. scanf("%d",&m);
  141. while(m--) {
  142. scanf("%d",&n);
  143. for(int i=;i<=n;i++) scanf("%d",in+i);
  144. SAM::Ex_extend(in,n);
  145. }
  146. build();
  147. ans = getans();
  148. printf("%d\n",ans);
  149. return ;
  150. }

T2:


观察操作数量特点,发现可持久化块状数组可过。
代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. using namespace std;
  6. const int maxn=1e6+1e2,maxb=1e3,maxu=1e4+1e2,maxr=1e5+1e2;
  7.  
  8. inline int* NewArray() {
  9. static const int maxu = 1e4 + 1e3 + ;
  10. static int dat[maxu][maxb],cnt;
  11. return dat[cnt++];
  12. }
  13.  
  14. struct PersistentBlockedArray {
  15. int* p[maxb];
  16. inline void insert(int pos,int x) { // insert into this array .
  17. if( !p[pos/maxb] ) p[pos/maxb] = NewArray();
  18. p[pos/maxb][pos%maxb] = x;
  19. }
  20. inline void modify(int pos,int x) {
  21. int* t = NewArray();
  22. memcpy(t,p[pos/maxb],sizeof(int)*maxb);
  23. t[pos%maxb] = x , p[pos/maxb] = t;
  24. }
  25. inline int query(int pos) {
  26. return p[pos/maxb][pos%maxb];
  27. }
  28. }dat[maxu];
  29.  
  30. int ptr[maxu+maxr],now,cnt;
  31.  
  32. inline void roll(int tar) {
  33. ptr[++now] = ptr[tar];
  34. }
  35. inline void modify(int pos,int x) {
  36. dat[++cnt] = dat[ptr[now]] , ptr[now] = cnt;
  37. dat[ptr[now]].modify(pos,x);
  38. }
  39. inline int query(int pos) {
  40. return dat[ptr[now]].query(pos);
  41. }
  42.  
  43. namespace IO {
  44. const int BS = << ;
  45. char ibuf[BS],obuf[BS],*ist,*ied,*oed=obuf;
  46. inline char nextchar() {
  47. if( ist == ied ) ied = ibuf + fread(ist=ibuf,,BS,stdin);
  48. return ist == ied ? - : *ist++;
  49. }
  50. inline int getint() {
  51. int ret = , ch;
  52. while( !isdigit(ch=nextchar()) );
  53. do ret=ret*+ch-''; while( isdigit(ch=nextchar()) );
  54. return ret;
  55. }
  56. inline void getstr(char* s) {
  57. char ch;
  58. while( !isalpha(ch=nextchar()) ) ;
  59. do *s++=ch; while( isalpha(ch=nextchar()) );
  60. }
  61. inline void flush() {
  62. //cerr<<"in flush delta = "<<oed-obuf<<endl;
  63. fwrite(obuf,,oed-obuf,stdout) , oed = obuf;
  64. }
  65. inline void printchar(const char &x) {
  66. *oed++ = x;
  67. //cerr<<"delta = "<<oed-obuf<<endl;
  68. if( oed == obuf + BS ) flush();
  69. }
  70. inline void printint(int x) {
  71. //cerr<<"x = "<<x<<endl;
  72. static int stk[],top;
  73. if( !x ) printchar('');
  74. else {
  75. top = ;
  76. while(x) stk[++top] = x % , x /= ;
  77. while(top) printchar(''+stk[top--]);
  78. }
  79. printchar('\n');
  80. }
  81. }
  82. using IO::getint;
  83. using IO::printint;
  84. using IO::getstr;
  85. using IO::flush;
  86.  
  87. int main() {
  88. static int n,m,lastans,ope;
  89. static char o[];
  90. n = getint() , m = getint();
  91. for(int i=,x;i<n;i++) x = getint() , dat[].insert(i,x);
  92. for(int i=,p,x,t;i<=m;i++) {
  93. getstr(o);
  94. if( *o == 'Q' ) {
  95. p = ( getint() ^ lastans ) % n;
  96. printint(lastans=query(p));
  97. } else if( *o == 'M' ) {
  98. ++ope , p = ( getint() ^ lastans ) % n , x = getint();
  99. modify(p,x);
  100. } else if( *o == 'R' ) {
  101. ++ope , t = ( getint() ^ lastans ) % ope;
  102. roll(t);
  103. }
  104. }
  105. flush();
  106. return ;
  107. }

T3:


大力反演出phi,后面的sigma(i^k)显然是k+1次多项式,拉格朗日插值即可。
代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #define debug cout
  6. #define bool unsigned char
  7. typedef long long int lli;
  8. using namespace std;
  9. const int maxn=1e6+1e2,lim=1e6,maxk=1e3+1e1;
  10. const int mod=1e9+;
  11.  
  12. int n,k;
  13.  
  14. namespace Sieve {
  15. lli sum[maxn],mem[maxn];
  16. bool vis[maxn];
  17.  
  18. inline void pre() {
  19. static int prime[maxn/],cnt;
  20. static bool vis[maxn];
  21. sum[] = ;
  22. for(int i=;i<=lim;i++) {
  23. if( !vis[i] ) prime[++cnt] = i , sum[i] = i - ;
  24. for(int j=;j<=cnt&&(lli)i*prime[j]<=lim;j++) {
  25. const int tar = i * prime[j];
  26. vis[tar] = ;
  27. if( i % prime[j] ) sum[tar] = sum[i] * ( prime[j] - );
  28. else {
  29. sum[tar] = sum[i] * prime[j];
  30. break;
  31. }
  32. }
  33. }
  34. for(int i=;i<=lim;i++) sum[i] = ( sum[i] + sum[i-] ) % mod;
  35. }
  36. inline lli getphi(lli x) {
  37. if( x <= lim ) return sum[x];
  38. const lli t = n / x;
  39. if( vis[t] ) return mem[t];
  40. lli& ret = mem[t]; ret = x * ( x + ) >> , vis[t] = ;
  41. for(lli i=,j;i<=x;i=j+) {
  42. j = x / ( x / i );
  43. ret -= ( j - i + ) * getphi(x/i) % mod , ret %= mod;
  44. }
  45. return ret = ( ret % mod + mod ) % mod;
  46. }
  47. }
  48.  
  49. namespace Inter {
  50. lli in[maxk],fac[maxk],facrev[maxk],pprv[maxk],ssuf[maxk],*prv=pprv+,*suf=ssuf+;
  51. inline lli fastpow(lli base,int tim) {
  52. lli ret = ;
  53. while(tim) {
  54. if( tim & ) ret = ret * base % mod;
  55. if( tim >>= ) base = base * base % mod;
  56. }
  57. return ret;
  58. }
  59. inline void init() {
  60. for(int i=;i<k;i++) in[i] = fastpow(i,k-);
  61. for(int i=;i<k;i++) in[i] = ( in[i] + in[i-] ) % mod;
  62. }
  63. inline lli getmul(int p) {
  64. return p ? fac[p] * facrev[k-p-] % mod : facrev[k-];
  65. }
  66. inline lli getval(lli x) {
  67. lli ret = ;
  68. prv[-] = ;
  69. for(int i=;i<k;i++) prv[i] = prv[i-] * (x-i+mod) % mod;
  70. suf[k] = ;
  71. for(int i=k-;~i;i--) suf[i] = suf[i+] * (x-i+mod) % mod;
  72. for(int i=;i<k;i++) {
  73. lli now = prv[i-] * suf[i+] % mod;
  74. ret = ret + now * in[i] % mod * getmul(i) % mod , ret %= mod;
  75. }
  76. return ret;
  77. }
  78. inline void getinv() {
  79. static lli inv[maxn];
  80. *fac = ;
  81. for(int i=;i<=k;i++) fac[i] = fac[i-] * i % mod;
  82. inv[k] = fastpow(fac[k],mod-);
  83. for(int i=k;i;i--) inv[i-] = inv[i] * i % mod;
  84. for(int i=;i<=k;i++) inv[i] = inv[i] * fac[i-] % mod;
  85. for(int i=;i<=k;i++) fac[i] = fac[i-] * inv[i] % mod;
  86. facrev[] = ;
  87. for(int i=;i<=k;i++) facrev[i] = facrev[i-] * ( mod - inv[i] ) % mod;
  88. }
  89. }
  90. inline lli segphi(lli l,lli r) {
  91. return ( Sieve::getphi(r) - Sieve::getphi(l-) + mod ) % mod;
  92. }
  93.  
  94. inline lli calc(lli n) {
  95. lli ret = ;
  96. for(lli i=,j;i<=n;i=j+) {
  97. j = n / ( n / i );
  98. ret += segphi(i,j) % mod * Inter::getval(n/i) % mod , ret %= mod;
  99. }
  100. return ret;
  101. }
  102.  
  103. int main() {
  104. scanf("%d%d",&n,&k) , k += , Sieve::pre() , Inter::init() , Inter::getinv();
  105. printf("%lld\n",calc(n));
  106. return ;
  107. }

当然那个RYOI是什么意思?就不告诉你!

Cmd2001的毒瘤水题题解的更多相关文章

  1. 2019浙大校赛--J--Extended Twin Composite Number(毒瘤水题)

    毒瘤出题人,坑了我们好久,从基本的素数筛选,到埃氏筛法,到随机数快速素数判定,到费马小定理,好好的水题做成了数论题. 结果答案是 2*n=n+3*n,特判1,2. 以下为毒瘤题目: 题目大意: 输入一 ...

  2. World Finals 2017 (水题题解)

    看大佬做2017-WF,我这种菜鸡,只能刷刷水题,勉强维持生活. 赛后补补水题. 题目pdf链接,中文的,tls翻译的,链接在这里 个人喜欢在vjudge上面刷题. E Need for Speed ...

  3. bzoj usaco 金组水题题解(2)

    续.....TAT这回不到50题编辑器就崩了.. 这里塞40道吧= = bzoj 1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害 比较经典的最小割?..然而 ...

  4. bzoj usaco 金组水题题解(2.5)

    bzoj 2197: [Usaco2011 Mar]Tree Decoration 树形dp..f[i]表示处理完以i为根的子树的最小时间. 因为一个点上可以挂无数个,所以在点i上挂东西的单位花费就是 ...

  5. bzoj usaco 金组水题题解(1)

    UPD:我真不是想骗访问量TAT..一开始没注意总长度写着写着网页崩了王仓(其实中午的时候就时常开始卡了= =)....损失了2h(幸好长一点的都单独开了一篇)....吓得赶紧分成两坨....TAT. ...

  6. 2006-2007 ACM-ICPC | POJ3380 POJ3384 POJ3385 水题题解

    // CF比赛链接:http://codeforces.com/gym/101650 // POJ链接:http://poj.org/searchproblem?field=source&ke ...

  7. LOJ6303:水题——题解

    https://loj.ac/problem/6303 题目来自LOJ. 就记一个公式,设f(n,k)为n!里分解得到的k(k为质数)的个数,则f(n,k)=f(n/k,k)+n/k. 证明很好证,显 ...

  8. leetcode水题题解

    344. Reverse String Write a function that takes a string as input and returns the string reversed. E ...

  9. PAT甲题题解-1011. World Cup Betting (20)-误导人的水题。。。

    题目不严谨啊啊啊啊式子算出来结果是37.975样例输出的是37.98我以为是四舍五入的啊啊啊,所以最后输出的是sum+0.005结果告诉我全部错误啊结果直接保留两位小数就可以了啊啊啊啊 水题也不要这么 ...

随机推荐

  1. indeed招聘

    https://cn.indeed.com/%E5%B7%A5%E4%BD%9C-%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD%E5%85%AC%E5%8F%B8-%E5% ...

  2. 鸟哥的Linux私房菜——第十七章:Linux 账号与身份管理

    视频链接:http://www.bilibili.com/video/av10669732/ 1. Linux 的账号与群组1.1 使用者识别: UID 与 GID1.2 使用者账号:/etc/pas ...

  3. OpenGL ES 2.0 Shader 调试新思路(二): 做一个可用的原型

    OpenGL ES 2.0 Shader 调试新思路(二): 做一个可用的原型 目录 背景介绍 请参考前文OpenGL ES 2.0 Shader 调试新思路(一): 改变提问方式 优化 ledCha ...

  4. [iOS]@synthesize和@dynamic关键字

    首先讲@property, 这是iOS6以后出来的关键词. 用它声明一个属性之后, 编译器会自动给你生成setter和getter方法的声明以及实现还有一个以_xxx 的成员变量(xxx是你属性定义的 ...

  5. [转载]DOMContentLoaded与interactive

    http://www.cnblogs.com/muxrwc/archive/2011/01/13/1934379.html ie中inline script执行时竟然第一次进入页面,doc.ready ...

  6. 第二篇:服务消费者(rest + ribbon)

    一. ribbon简介 ribbon是一个负载均衡客户端,可以很好的控制http和tcp的一些行为,Feign也用到了ribbon,当你使用@ FeignClient,ribbon自动被应用. Rib ...

  7. 使用Docx4j创建word文档

    原文标题:Creating Word documents with Docx4j 原文链接:http://blog.iprofs.nl/2012/09/06/creating-word-documen ...

  8. JS脚本病毒调试脚本-Trojan[Downloader]:JS/Nemucod

    1.前言 遇到Trojan[Downloader]:JS/Nemucod需要分析,这款病毒主要为js运行.从网上各种找js调试方法.发现52的帖子还挺沾边的. TrojanDownloader:JS/ ...

  9. House Robber I & II & III

    House Robber You are a professional robber planning to rob houses along a street. Each house has a c ...

  10. shell中后台进程管理: ps -aux 详解

    常用 查找进程id方法:      ps -aux | grep "jupyter"                杀进程:   kill -9 具体的PID 1.ps命令 要对进 ...