C - pushpush

如果是按下标说的话

如果是偶数个

那么是

\(N,N - 2,N - 4...1,3,5...N - 1\)

如果是奇数个

\(N,N - 2,N - 4...2,4,6...N - 1\)

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define mp make_pair
  6. #define pb push_back
  7. #define space putchar(' ')
  8. #define enter putchar('\n')
  9. #define eps 1e-10
  10. #define MAXN 200005
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef unsigned int u32;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;T f = 1;char c = getchar();
  19. while(c < '0' || c > '9') {
  20. if(c == '-') f = -1;
  21. c = getchar();
  22. }
  23. while(c >= '0' && c <= '9') {
  24. res = res * 10 +c - '0';
  25. c = getchar();
  26. }
  27. res *= f;
  28. }
  29. template<class T>
  30. void out(T x) {
  31. if(x < 0) {x = -x;putchar('-');}
  32. if(x >= 10) {
  33. out(x / 10);
  34. }
  35. putchar('0' + x % 10);
  36. }
  37. int N;
  38. int a[MAXN];
  39. void Solve() {
  40. read(N);
  41. for(int i = 1 ; i <= N ; ++i) read(a[i]);
  42. if(N & 1) {
  43. for(int i = N ; i >= 1 ; i -= 2) {out(a[i]);space;}
  44. for(int i = i = 2 ; i <= N ; i += 2) {out(a[i]);space;}
  45. enter;
  46. }
  47. else {
  48. for(int i = N ; i >= 1 ; i -= 2) {out(a[i]);space;}
  49. for(int i = 1 ; i <= N ; i += 2) {out(a[i]);space;}
  50. enter;
  51. }
  52. }
  53. int main() {
  54. #ifdef ivorysi
  55. freopen("f1.in","r",stdin);
  56. #endif
  57. Solve();
  58. }

D - 11

就相当于只有两个位置相同,那么即为

\(...1 .... 1....\)

算所有位置不同的子序列

如果这个序列只包括其中一个1,剩下的数不在两个1之间,那么这个序列就被重复计算了,很简单的计数

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define mp make_pair
  6. #define pb push_back
  7. #define space putchar(' ')
  8. #define enter putchar('\n')
  9. #define eps 1e-10
  10. #define MAXN 100005
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef unsigned int u32;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;T f = 1;char c = getchar();
  19. while(c < '0' || c > '9') {
  20. if(c == '-') f = -1;
  21. c = getchar();
  22. }
  23. while(c >= '0' && c <= '9') {
  24. res = res * 10 +c - '0';
  25. c = getchar();
  26. }
  27. res *= f;
  28. }
  29. template<class T>
  30. void out(T x) {
  31. if(x < 0) {x = -x;putchar('-');}
  32. if(x >= 10) {
  33. out(x / 10);
  34. }
  35. putchar('0' + x % 10);
  36. }
  37. const int MOD = 1000000007;
  38. int N,a[MAXN],fac[MAXN],invfac[MAXN];
  39. int pos[MAXN],p;
  40. int inc(int a,int b) {
  41. return a + b >= MOD ? a + b - MOD : a + b;
  42. }
  43. int mul(int a,int b) {
  44. return 1LL * a * b % MOD;
  45. }
  46. int fpow(int x,int c) {
  47. int t = x,res = 1;
  48. while(c) {
  49. if(c & 1) res = mul(res,t);
  50. t = mul(t,t);
  51. c >>= 1;
  52. }
  53. return res;
  54. }
  55. int C(int n,int m) {
  56. if(n < m) return 0;
  57. return mul(fac[n],mul(invfac[m],invfac[n - m]));
  58. }
  59. void Solve() {
  60. read(N);
  61. for(int i = 1 ; i <= N + 1; ++i) read(a[i]);
  62. for(int i = 1 ; i <= N + 1; ++i) {
  63. if(pos[a[i]]) p = i;
  64. else pos[a[i]] = i;
  65. }
  66. fac[0] = 1;
  67. for(int i = 1 ; i <= N + 1 ; ++i) {
  68. fac[i] = mul(fac[i - 1],i);
  69. }
  70. invfac[N + 1] = fpow(fac[N + 1],MOD - 2);
  71. for(int i = N ; i >= 0 ; --i) {
  72. invfac[i] = mul(invfac[i + 1],i + 1);
  73. }
  74. for(int i = 1 ; i <= N + 1 ; ++i) {
  75. int res = C(N + 1,i);
  76. res = inc(res,MOD - C(pos[a[p]] - 1 + N + 1 - p,i - 1));
  77. out(res);enter;
  78. }
  79. }
  80. int main() {
  81. #ifdef ivorysi
  82. freopen("f1.in","r",stdin);
  83. #endif
  84. Solve();
  85. }

E - guruguru

显然如果不按第二个按钮,只用第一种情况增加,增加的方式不能改变,把每次增加的段画在数轴上,会发现每次增加对于一段区间相当于如果选了x当喜爱按钮,那么费用会减少y,这个y在数轴上是个等差数列,用线段树维护一下就好

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define mp make_pair
  6. #define pb push_back
  7. #define space putchar(' ')
  8. #define enter putchar('\n')
  9. #define eps 1e-10
  10. #define MAXN 100005
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef unsigned int u32;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;T f = 1;char c = getchar();
  19. while(c < '0' || c > '9') {
  20. if(c == '-') f = -1;
  21. c = getchar();
  22. }
  23. while(c >= '0' && c <= '9') {
  24. res = res * 10 +c - '0';
  25. c = getchar();
  26. }
  27. res *= f;
  28. }
  29. template<class T>
  30. void out(T x) {
  31. if(x < 0) {x = -x;putchar('-');}
  32. if(x >= 10) {
  33. out(x / 10);
  34. }
  35. putchar('0' + x % 10);
  36. }
  37. int N,M;
  38. int a[MAXN];
  39. int64 ans,res;
  40. struct node {
  41. int L,R;
  42. int64 a,d;
  43. }tr[MAXN * 4];
  44. void build(int u,int L,int R) {
  45. tr[u].L = L;tr[u].R = R;
  46. tr[u].a = tr[u].d = 0;
  47. if(L == R) return;
  48. int mid = (L + R) >> 1;
  49. build(u << 1,L,mid);
  50. build(u << 1 | 1,mid + 1,R);
  51. }
  52. void addlz(int u,int64 a,int64 d) {
  53. tr[u].a += a;tr[u].d += d;
  54. }
  55. void pushdown(int u) {
  56. int l = tr[u].L,m = (tr[u].L + tr[u].R) >> 1,r = tr[u].R;
  57. addlz(u << 1,tr[u].a,tr[u].d);
  58. addlz(u << 1 | 1,tr[u].a + (m + 1 - l) * tr[u].d,tr[u].d);
  59. tr[u].a = tr[u].d = 0;
  60. }
  61. void Add(int u,int ql,int qr,int64 a,int64 d) {
  62. if(ql > qr) return;
  63. if(ql == tr[u].L && qr == tr[u].R) {addlz(u,a,d);return;}
  64. int mid = (tr[u].L + tr[u].R) >> 1;
  65. pushdown(u);
  66. if(qr <= mid) Add(u << 1,ql,qr,a,d);
  67. else if(ql > mid) Add(u << 1 | 1,ql,qr,a,d);
  68. else {Add(u << 1,ql,mid,a,d),Add(u << 1 | 1,mid + 1,qr,a + (mid + 1 - ql) * d,d);}
  69. }
  70. void Getans(int u) {
  71. if(tr[u].L == tr[u].R) {res = max(tr[u].a,res);return;}
  72. pushdown(u);
  73. Getans(u << 1);Getans(u << 1 | 1);
  74. }
  75. void Solve() {
  76. read(N);read(M);
  77. build(1,1,M);
  78. for(int i = 1 ; i <= N ; ++i) {
  79. read(a[i]);
  80. }
  81. for(int i = 2 ; i <= N ; ++i) {
  82. if(a[i] > a[i - 1]) {
  83. ans += a[i] - a[i - 1];
  84. Add(1,a[i - 1] + 1,a[i],0,1);
  85. }
  86. else {
  87. ans += M - a[i - 1] + a[i];
  88. Add(1,a[i - 1] + 1,M,0,1);
  89. Add(1,1,a[i],M - a[i - 1],1);
  90. }
  91. }
  92. Getans(1);
  93. out(ans - res);enter;
  94. }
  95. int main() {
  96. #ifdef ivorysi
  97. freopen("f1.in","r",stdin);
  98. #endif
  99. Solve();
  100. }

F - SS

先把原始的字符串变成两个相同的字符串的形式

设为\(SS\),如果\(S\)最后一位的next是\(k\),那么显然要在后边加\(S\)的后N-k和\(S\)的前N-k位

设\(S\)的后\(N - k\)位为\(T\),且\(k\)最大,那么

\(f(SS) = STST\)

设\(g(S) = ST\)

显然\(f(SS) = g(S) + g(S)\)

我们实际上只要求一个足够长的\(g(S)\)就行

\(g(S) = ST\)

当\(|T|\)是\(|S|\)的约数,可以得到\(g(ST) = STT\)

如果\(|T|\)不是\(|S|\)的约数,那么\(g(ST) = STS\)

然后第一种情况\(g^{\infty}(S) = STTTTTTT....\)

第二种情况\(g^{i + 2}(S) = g^{i + 1}(S) + g^{i}(S)\)

然后可以直接模拟,从第二种情况开始递推,如果出现第一种情况就可以记录退出,第二种情况增长速度是指数级的,递推100个左右就行

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define mp make_pair
  6. #define pb push_back
  7. #define space putchar(' ')
  8. #define enter putchar('\n')
  9. #define MAXN 200005
  10. #define eps 1e-10
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef unsigned int u32;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;T f = 1;char c = getchar();
  19. while(c < '0' || c > '9') {
  20. if(c == '-') f = -1;
  21. c = getchar();
  22. }
  23. while(c >= '0' && c <= '9') {
  24. res = res * 10 + c - '0';
  25. c = getchar();
  26. }
  27. res *= f;
  28. }
  29. template<class T>
  30. void out(T x) {
  31. if(x < 0) {x = -x;putchar('-');}
  32. if(x >= 10) {
  33. out(x / 10);
  34. }
  35. putchar('0' + x % 10);
  36. }
  37. struct node {
  38. int64 c[26],len;
  39. node() {memset(c,0,sizeof(c));len = 0;}
  40. friend node operator + (const node &a,const node &b) {
  41. node r;
  42. r.len = a.len + b.len;
  43. for(int i = 0 ; i < 26 ; ++i) r.c[i] = a.c[i] + b.c[i];
  44. return r;
  45. }
  46. friend node operator - (const node &a,const node &b) {
  47. node r;
  48. r.len = a.len - b.len;
  49. for(int i = 0 ; i < 26 ; ++i) r.c[i] = a.c[i] - b.c[i];
  50. return r;
  51. }
  52. friend node operator * (const node &a,const int64 &d) {
  53. node r = a;
  54. for(int i = 0 ; i < 26 ; ++i) {
  55. r.c[i] = r.c[i] * d;
  56. }
  57. return r;
  58. }
  59. }g[MAXN];
  60. char s[MAXN * 2],t[MAXN * 2];
  61. int nxt[MAXN],N;
  62. int st,all;
  63. node Calc(int64 R) {
  64. if(R > g[all].len && st) {
  65. node res;
  66. res = g[st];
  67. int64 t = (R - g[st].len) / g[st - 1].len;
  68. res = res + g[st - 1] * t;
  69. return res + Calc(R - g[st].len - g[st - 1].len * t);
  70. }
  71. else if(R <= g[1].len){
  72. node res;res.len = R;
  73. for(int i = 1 ; i <= R ; ++i) {
  74. res.c[s[i] - 'a']++;
  75. }
  76. return res;
  77. }
  78. else {
  79. for(int i = all ; i >= 0 ; --i) {
  80. if(g[i].len <= R) {
  81. return g[i] + Calc(R - g[i].len);
  82. }
  83. }
  84. }
  85. }
  86. void Solve() {
  87. scanf("%s",s + 1);
  88. int64 r,l;
  89. read(l);read(r);
  90. N = strlen(s + 1);
  91. for(int i = 2 ; i <= N ; ++i) {
  92. int p = nxt[i - 1];
  93. while(p && s[i] != s[p + 1]) p = nxt[p];
  94. if(s[i] == s[p + 1]) nxt[i] = p + 1;
  95. else nxt[i] = 0;
  96. }
  97. int p = nxt[N];
  98. while(p > (N - 1) / 2) p = nxt[p];
  99. int L = N;
  100. for(int i = p + 1 ; i <= N - p ; ++i) {
  101. s[++L] = s[i];
  102. }
  103. for(int i = 1 ; i <= L / 2; ++i) {
  104. g[1].c[s[i] - 'a']++;
  105. }
  106. g[1].len = L / 2;
  107. p = nxt[L / 2];
  108. g[0].len = L / 2 - p;
  109. for(int i = 1 ; i <= L / 2 - p ; ++i) {
  110. t[i] = s[i];
  111. g[0].c[t[i] - 'a']++;
  112. }
  113. for(int i = 2 ; i <= 100 ; ++i) {
  114. if(g[i - 1].len % (g[i - 1].len - g[i - 2].len) == 0) {all = i - 1;st = i - 1;break;}
  115. if(g[i - 1].len + g[i - 2].len <= 1e18) g[i] = g[i - 1] + g[i - 2];
  116. else {all = i - 1;break;}
  117. }
  118. if(!all) all = 100;
  119. node ans = Calc(r) - Calc(l - 1);
  120. for(int i = 0 ; i < 26 ; ++i) {
  121. out(ans.c[i]);space;
  122. }
  123. enter;
  124. }
  125. int main() {
  126. #ifdef ivorysi
  127. freopen("f1.in","r",stdin);
  128. #endif
  129. Solve();
  130. }

【AtCoder】ARC077的更多相关文章

  1. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  2. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  3. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  4. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...

  5. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  6. 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分

    [题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...

  7. 【AtCoder】ARC095 E - Symmetric Grid 模拟

    [题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...

  8. 【Atcoder】AGC022 C - Remainder Game 搜索

    [题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...

  9. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...

随机推荐

  1. $Django 路飞之课程下的分类,用户登陆成功前端存cookie,

    一 课程分类显示 宗旨:总的再次过滤 二 Cookie # export default new Vuex.Store({ state: { name:'', token:'', }, mutatio ...

  2. 修改JDK版本配置

    我使用的maven是3.0.5版本的,在创建项目的时候,默认使用的jdk为1.5版本 在项目的pom.xml中添加如下配置可修改使用的jdk版本. <properties> <!-- ...

  3. 前端 ----关于DOM的操作的相关实例

    关于DOM操作的相关案例   1.模态框案例 需求: 打开网页时有一个普通的按钮,点击当前按钮显示一个背景图,中心并弹出一个弹出框,点击X的时候会关闭当前的模态框 代码如下: <!DOCTYPE ...

  4. 关于socket.io获取客户端真实IP地址

    1 前言 由于使用了CDN加速,导致了socket.handshake.address拿到值都是服务器的,而没有使用CDN加速时,可以拿到客户端真实IP. 2 代码 if(socket.handsha ...

  5. Day7--------------IP地址配置

    ifconfig 查看网卡 ifconfig eth0 查看网卡eth0 配置网络地址: 临时配置: ifconfig eth0 192.168.10.100 netmask 255.255.255. ...

  6. ionic3 使用html2canvas将数据导出为图片,并下载本地

    1.安装html2canvas npm install --save html2canvas 官方网站 https://html2canvas.hertzen.com/ 2.在需要的组件中引入html ...

  7. spring boot 配置文件

    spring boot使用一个全局配置文件:主要是以下两种类型 application.properties  :例:server.port=9998 application.yml(YAML)  : ...

  8. LeetCode(66): 加一

    Easy! 题目描述: 给定一个非负整数组成的非空数组,在该数的基础上加一,返回一个新的数组. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会 ...

  9. python+selenium十四:xpath和contains模糊匹配

    xpath可以以标签定位,也可以@任意属性: 如:以input标签定位:driver.find_element_by_xpath("//input[@id='kw']") 如:@t ...

  10. Nginx详解四:Nginx基础篇之目录和配置语法

    一.安装目录 命令:rpm -ql nginx 二.编译参数 命令:nginx -V 三.Nginx基本配置语法 修改主配置文件 当Nginx读配置文件读到include /etc/nginx/con ...