C - Snuke Festival

对于每个B二分求出几个A比它小记为sum

然后对于每个C就是比它小的B的sum的和

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

D - Small Multiple

一开始记了一个位数,结果开到了2000多位都WA

其实发现答案不会超过5 * 9

直接设\(dp[i][j]\)为现在答案是\(i\),\(%K\)意义下是\(j\)

每次转移往后加一位就行,就是如果加了一位\(h\),第二维是\((10j + h) % K\)

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define pdi pair<db,int>
  6. #define mp make_pair
  7. #define pb push_back
  8. #define enter putchar('\n')
  9. #define space putchar(' ')
  10. #define eps 1e-8
  11. #define mo 974711
  12. #define MAXN 100005
  13. //#define ivorysi
  14. using namespace std;
  15. typedef long long int64;
  16. typedef double db;
  17. template<class T>
  18. void read(T &res) {
  19. res = 0;char c = getchar();T f = 1;
  20. while(c < '0' || c > '9') {
  21. if(c == '-') f = -1;
  22. c = getchar();
  23. }
  24. while(c >= '0' && c <= '9') {
  25. res = res * 10 + c - '0';
  26. c = getchar();
  27. }
  28. res *= f;
  29. }
  30. template<class T>
  31. void out(T x) {
  32. if(x < 0) {x = -x;putchar('-');}
  33. if(x >= 10) {
  34. out(x / 10);
  35. }
  36. putchar('0' + x % 10);
  37. }
  38. int K;
  39. bool dp[55][100005];
  40. queue<int> Q;
  41. void Solve() {
  42. read(K);
  43. for(int i = 1 ; i <= 9 ; ++i) dp[i][i % K] = 1;
  44. for(int i = 1 ; i <= 50 ; ++i) {
  45. for(int a = 0 ; a < K ; ++a) {
  46. if(dp[i][a]) Q.push(a);
  47. }
  48. while(!Q.empty()) {
  49. int v = Q.front();Q.pop();
  50. if(!dp[i][v * 10 % K]) {
  51. dp[i][v * 10 % K] = 1;
  52. Q.push(v * 10 % K);
  53. }
  54. }
  55. for(int a = 0 ; a < K ; ++a) {
  56. if(!dp[i][a]) continue;
  57. for(int j = 1 ; j <= 9 ; ++j) {
  58. if(i + j > 50) break;
  59. int h = (a * 10 + j) % K;
  60. dp[i + j][h] = 1;
  61. }
  62. }
  63. }
  64. for(int i = 1 ; i <= 50 ; ++i) {
  65. if(dp[i][0]) {
  66. out(i);enter;return;
  67. }
  68. }
  69. }
  70. int main() {
  71. #ifdef ivorysi
  72. freopen("f1.in","r",stdin);
  73. #endif
  74. Solve();
  75. return 0;
  76. }

E - Finite Encyclopedia of Integer Sequences

如果K是偶数的话,答案是K / 2,K,K,K,K.....

如果K是奇数构造一个数列

K / 2 +1,K / 2 + 1,K / 2 + 1,K / 2 + 1.....

长度为N

发现一个序列

\(a_i\)映射到\(K - a_i + 1\)如果\(a_i\)不是构造出的这个序列的一个前缀,那么肯定这两个序列中,一个在这个序列前,一个在这个序列后

所以这个序列的排名是\((S + N) / 2\)

往前倒退\(N / 2\)个即可

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

F - XorShift

就是考虑两个多项式,它们互相消,肯定会消成0,这个消成0之前的,就是他们的gcd

所有的数肯定都是这个gcd的倍数

所以我们设gcd长度为a,x长度为b

这个数前\(b - a +1\)随便填,后面的位数可以唯一确定,所以答案就是\(x\)的前\(b - a +1\)位二进制构成的数+1

但是有个特殊的,就是如果前面恰好等于\(x\)的情况,可能后面确定好的数就超过了x,这个特判一下减掉就好

  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 100005
  10. #define eps 1e-10
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef double db;
  15. template<class T>
  16. void read(T &res) {
  17. res = 0;T f = 1;char c = getchar();
  18. while(c < '0' || c > '9') {
  19. if(c == '-') f = -1;
  20. c = getchar();
  21. }
  22. while(c >= '0' && c <= '9') {
  23. res = res * 10 + c - '0';
  24. c = getchar();
  25. }
  26. res *= f;
  27. }
  28. template<class T>
  29. void out(T x) {
  30. if(x < 0) {x = -x;putchar('-');}
  31. if(x >= 10) {
  32. out(x / 10);
  33. }
  34. putchar('0' + x % 10);
  35. }
  36. const int MOD = 998244353;
  37. vector<int> num[7],x,g,t;
  38. int N;
  39. char s[4005];
  40. vector<int> gcd(vector<int> a,vector<int> b) {
  41. if(a.size() < b.size()) swap(a,b);
  42. if(b.size() == 1 && b[0] == 0) return a;
  43. vector<int> d(a.size());
  44. int t = a.size() - 1;
  45. for(int i = b.size() - 1 ; i >= 0 ; --i) {
  46. d[t] = a[t] ^ b[i];
  47. --t;
  48. }
  49. for(int i = t ; i >= 0 ; --i) d[i] = a[i];
  50. while(d.size() > 1) {
  51. if(d.back() == 0) d.pop_back();
  52. else break;
  53. }
  54. return gcd(b,d);
  55. }
  56. void Init() {
  57. read(N);
  58. scanf("%s",s + 1);
  59. int len = strlen(s + 1);
  60. for(int i = len ; i >= 1 ; --i) {
  61. x.pb(s[i] - '0');
  62. }
  63. for(int i = 1 ; i <= N ; ++i) {
  64. scanf("%s",s + 1);
  65. len = strlen(s + 1);
  66. for(int j = len ; j >= 1 ; --j) num[i].pb(s[j] - '0');
  67. }
  68. g = num[1];
  69. for(int i = 2 ; i <= N ; ++i) g = gcd(g,num[i]);
  70. }
  71. void Solve() {
  72. t = x;
  73. if(g.size() > x.size()) {out(1);enter;return;}
  74. int l = x.size() - g.size() + 1;
  75. int d = x.size() - 1;
  76. int ans = 0;
  77. for(int i = 0 ; i < l ; ++i) {
  78. ans = (1LL * ans * 2 + x[d - i]) % MOD;
  79. }
  80. ans = (ans + 1) % MOD;
  81. for(int i = l ; i < x.size() ; ++i) t[d - i] = 0;
  82. for(int i = 0 ; i < l ; ++i) {
  83. if(t[d - i] == 1) {
  84. int k = g.size() - 1;
  85. for(int j = 0 ; j < g.size() ; ++j) {
  86. t[d - i - j] = t[d - i - j] ^ g[k - j];
  87. }
  88. }
  89. }
  90. for(int i = l ; i < x.size() ; ++i) {
  91. if(t[d - i] != x[d - i]) {
  92. if(t[d - i] > x[d - i]) ans = (ans + MOD - 1) % MOD;
  93. break;
  94. }
  95. }
  96. out(ans);enter;
  97. }
  98. int main() {
  99. #ifdef ivorysi
  100. freopen("f1.in","r",stdin);
  101. #endif
  102. Init();
  103. Solve();
  104. }

【AtCoder】ARC084的更多相关文章

  1. 【Atcoder】ARC084 Small Multiple

    [题意]求一个k的倍数使其数位和最小,输出数位和,k<=10^5. [算法]最短路 [题解]考虑极端情况数字是可能爆long long的(例如k*num=100...000),所以确定基本方向是 ...

  2. 【AtCoder】ARC092 D - Two Sequences

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. oracle 获取当前用户下的所有表名与字段信息

     select *from user_col_commentswhere substr(table_name,1,3)<>'BIN' 

  2. MT【100】经典计数之分配问题

    注意:此讲适合联赛一试学生,以及参加清华北大等名校的自主招生的学生. 经典计数之分配问题:把n个球放进k个盒子.考虑分配方法有三类:1.无限制 2.每个盒子至多一个(f 单的)3.每个盒子至少一个(f ...

  3. 51nod1134——(最长上升子序列)

    给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10.   Input 第1行:1个 ...

  4. UiAutomator2.0入门

    总是听说UiAutomator这个框架,但从来没有使用过.找了篇入门,实践一下.实践之后感觉,uiautomator写测试代码,还是有点费劲.接口名比较多,比较长.网易的atx里使用的uiautoma ...

  5. linux c 编程 ------ 程序入口参数,即 main 参数

    #include <stdio.h> int main(int argc, char *argv[]) { printf(]); int i = argc; printf("th ...

  6. win32 ini

    原文:https://www.cnblogs.com/qq78292959/archive/2012/06/10/2544389.html Windows操作系统专门为此提供了6个API函数来对配置设 ...

  7. Java访问权限控制

    访问权限控制           java提供了访问权限修饰词,以供类库开发人员向客户端程序员指明哪些是可用的,哪些是不可用的.访问权限控制的等级,从最大权限到最小权限依次是:public.prote ...

  8. SQL记录-PLSQL触发器

    PL/SQL触发器 触发器是存储程序,它会自动执行或发射当一些事件发生.触发器,事实上,写入响应于以下任一事件将被执行: 数据库操作(DML)语句(DELETE,INSERT,UPDATE或) 数据库 ...

  9. JQuery 对表格的详细操作

    <%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding=& ...

  10. CString 与其它数据类型转换问题

    CString 头文件#include <afx.h> string 头文件#include <string.h> CString 转char * CString cstr; ...