[关闭]
@baobaobear 2020-04-05T11:17:50.000000Z 字数 5864 阅读 209

Contest 22

contest


A lnkkerst

  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. int main() {
  5. string n;
  6. cin >> n;
  7. cout << (char)*max_element(n.begin(), n.end());
  8. return 0;
  9. }

B djddskkekk

  1. #include <iostream>
  2. using namespace std;
  3. long long a , sum;
  4. int main ( void )
  5. {
  6. ios::sync_with_stdio ( false ); cin.tie ( 0 ); cout.tie ( 0 );
  7. cin >> a;
  8. for ( int i = 1 ; i <= a ; i++ ) {
  9. sum += i - 1;
  10. }
  11. cout << sum << endl;
  12. return 0;
  13. }

C lnkkerst

  1. #include <iostream>
  2. #define int long long
  3. using namespace std;
  4. int n, a[11], b[11];
  5. signed main() {
  6. while(cin >> n) {
  7. for(int i = 1; i <= n; ++i)
  8. cin >> a[i] >> b[i];
  9. int ans = b[1], t = a[1];
  10. for(int i = 2; i <= n; ++i) {
  11. while(ans % a[i] != b[i])
  12. ans += t;
  13. t *= a[i];
  14. }
  15. cout << ans << endl;
  16. }
  17. return 0;
  18. }

D djddskkekk

  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. const int maxn = 2e7 + 5;
  5. int a [ maxn ];
  6. int n , t;
  7. int main ( void )
  8. {
  9. ios::sync_with_stdio ( false ); cin.tie ( 0 ); cout.tie ( 0 );
  10. for ( int i = 1 ; i <= 2e7 ; i++ ) {
  11. if ( a [ i + 1 ] == 0 ) {
  12. a [ i + 1 ] = a [ i ] + 1;
  13. } else {
  14. a [ i + 1 ] = min ( a [ i ] + 1 , a [ i + 1 ] );
  15. }
  16. if ( i * 2 <= 2e7 ) {
  17. if ( a [ 2 * i ] == 0 ) {
  18. a [ 2 * i ] = a [ i ] + 1;
  19. } else {
  20. a [ 2 * i ] = min ( a [ 2 * i ] , a [ i ] + 1 );
  21. }
  22. }
  23. if ( i * 3 <= 2e7 ) {
  24. if ( a [ 3 * i ] == 0 ) {
  25. a [ 3 * i ] = a [ i ] + 1;
  26. } else {
  27. a [ 3 * i ] = min ( a [ 3 * i ] , a [ i ] + 1 );
  28. }
  29. }
  30. }
  31. cin >> t;
  32. int cnt = 1;
  33. while ( t-- ) {
  34. cin >> n;
  35. cout << "Case " << cnt << ": " << a [ n ] << endl;
  36. cnt++;
  37. }
  38. return 0;
  39. }

E lnkkerst

  1. #include <iostream>
  2. #define int long long
  3. using namespace std;
  4. signed main() {
  5. int t;
  6. cin >> t;
  7. while(t--) {
  8. int x;
  9. cin >> x;
  10. cout << (x >> 1) * (x - (x >> 1)) << endl;
  11. }
  12. return 0;
  13. }

F yingyingying777

  1. //#pragma GCC optimize(2)
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<string>
  5. #include<algorithm>
  6. using namespace std;
  7. typedef long long ll;
  8. const int INF=0x3f3f3f3f;
  9. int phi(int n)
  10. {
  11. int ans=n;
  12. for(int i=2;i*i<=n;i++)
  13. {
  14. if(n%i==0)
  15. {
  16. ans=ans/i*(i-1);
  17. while(n%i==0)
  18. n/=i;
  19. }
  20. }
  21. if(n>1)
  22. ans=ans/n*(n-1);
  23. return ans;
  24. }
  25. int main()
  26. {
  27. int n;
  28. while(scanf("%d",&n)!=EOF)
  29. {
  30. printf("%d\n",phi(n));
  31. }
  32. return 0;
  33. }

G lnkkerst

  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <algorithm>
  4. #include <queue>
  5. using namespace std;
  6. struct Node {
  7. int h, v, ind;
  8. bool vis;
  9. } a[200010];
  10. struct Edge {
  11. int to, nex;
  12. } e[2000010];
  13. int n, ans, cnt = 0, no = 0;
  14. string xs, nm, fa, tmp;
  15. unordered_map<string, int> id;
  16. void addedge(int u, int v) {
  17. e[++cnt] = (Edge){v, a[u].h};
  18. a[u].h = cnt;
  19. ++a[v].ind;
  20. }
  21. void topo() {
  22. queue<int > q;
  23. for(int i = 1; i <= no; ++i)
  24. if(!a[i].ind) q.push(i);
  25. while(!q.empty()) {
  26. int u = q.front();
  27. a[u].vis = 1;
  28. q.pop();
  29. for(int i = a[u].h; i; i = e[i].nex) {
  30. int v = e[i].to;
  31. --a[v].ind;
  32. a[v].v = max(a[v].v, a[u].v + 1);
  33. ans = max(ans, a[v].v);
  34. if(!a[v].ind) q.push(v);
  35. }
  36. }
  37. }
  38. void dfs(int u, int &val, int &dep) {
  39. a[u].vis = 1;
  40. val = max(val, a[u].v);
  41. ++dep;
  42. for(int i = a[u].h; i; i = e[i].nex)
  43. if(!a[e[i].to].vis)
  44. dfs(e[i].to, val, dep);
  45. }
  46. int main() {
  47. cin >> n;
  48. for(int i = 1; i <= n; ++i) {
  49. cin >> xs >> nm >> tmp >> tmp >> fa;
  50. nm = xs + ' ' + nm;
  51. fa = xs + ' ' + fa;
  52. if(!id[nm]) id[nm] = ++no;
  53. if(!id[fa]) id[fa] = ++no;
  54. addedge(id[nm], id[fa]);
  55. } topo();
  56. for(int i = 1; i <= no; ++i)
  57. if(!a[i].vis) {
  58. int val = 0, dep = 0;
  59. dfs(i, val, dep);
  60. ans = max(ans, val + dep);
  61. }
  62. cout << ans;
  63. return 0;
  64. }

H djddskkekk

  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. const int maxn = 1e5 + 10;
  6. int row , col , n ,top , f [ maxn ] , x_1 , y_1 , x_2 , y_2;
  7. bool vis [ maxn ];
  8. vector < pair < int , int > > v [ 4 ];
  9. inline bool check ( int a , int b )
  10. {
  11. if ( a == 0 || a == row || b == 0 || b == col ) {
  12. return true;
  13. }
  14. return false;
  15. }
  16. inline int read ( )
  17. {
  18. int s = 0 , t = 1; char ch = getchar ( );
  19. while ( ch < '0' || ch > '9' ) { if ( ch == '-' ) t = -1; ch = getchar ( ); }
  20. while ( ch >= '0' && ch <= '9' ) { s = s * 10 + ch - '0'; ch = getchar ( ); }
  21. return s * t;
  22. }
  23. void get_in ( int Row , int Col , int flag )
  24. {
  25. if ( !Row ) {
  26. v [ 0 ].emplace_back ( make_pair ( Col , flag ) );
  27. } else if ( col == Col ) {
  28. v [ 1 ].emplace_back ( make_pair ( Row , flag ) );
  29. } else if ( row == Row ) {
  30. v [ 2 ].emplace_back ( make_pair ( col - Col , flag ) );
  31. } else {
  32. v [ 3 ].emplace_back ( make_pair ( row - Row , flag ) );
  33. }
  34. }
  35. int main ( void )
  36. {
  37. row = read ( ); col = read ( ); n = read ( );
  38. for ( int i = 1 ; i <= n ; i++ ) {
  39. x_1 = read ( ); y_1 = read ( ); x_2 = read ( ); y_2 = read ( );
  40. if ( check ( x_1 , y_1 ) && check ( x_2 , y_2 ) ) {
  41. get_in ( x_1 , y_1 , i );
  42. get_in ( x_2 , y_2 , i );
  43. }
  44. }
  45. for ( int i = 0 ; i < 4 ; i++ ) {
  46. sort ( v [ i ].begin ( ) , v [ i ].end ( ) );
  47. for ( vector < pair < int , int > >::iterator x = v [ i ].begin ( ) ; x != v [ i ].end ( ) ; x++ ) {
  48. int flag = x->second;
  49. if ( !vis [ flag ] ) {
  50. f [ ++top ] = flag;
  51. vis [ flag ] = 1;
  52. } else if ( !top || f [ top ] != flag ) {
  53. puts ( "NO" );
  54. return 0;
  55. } else {
  56. --top;
  57. }
  58. }
  59. }
  60. puts ( "YES" );
  61. return 0;
  62. }

I 6109118071

  1. #include<iostream>
  2. #include<set>
  3. #include<string.h>
  4. #include<cmath>
  5. #include<queue>
  6. #include<algorithm>
  7. using namespace std;
  8. typedef long long ll;
  9. typedef pair<int, int> P;
  10. const int N = 100005;
  11. int num[100005];
  12. struct ac_atom{
  13. int trie[N][26], ct[N], fail[N], tot;
  14. void init()
  15. {
  16. memset(trie, 0, sizeof(trie));
  17. memset(ct, 0, sizeof(ct));
  18. memset(fail, 0, sizeof(fail));
  19. tot = 0;
  20. }
  21. void insert(char *s)
  22. {
  23. int rt = 0;
  24. int len = strlen(s);
  25. for (int i = 0; i < len; i++)
  26. {
  27. int od = s[i] - 'a';
  28. if (!trie[rt][od])
  29. {
  30. trie[rt][od] = ++tot;
  31. }
  32. rt = trie[rt][od];
  33. }
  34. ct[rt] = len;
  35. }
  36. void get_fail()
  37. {
  38. int rt = 0;
  39. fail[0] = 0;
  40. queue<int> q;
  41. for (int i = 0; i < 26; i++)
  42. {
  43. if (trie[rt][i])
  44. {
  45. fail[trie[rt][i]] = 0;
  46. q.push(trie[rt][i]);
  47. }
  48. }
  49. while (!q.empty())
  50. {
  51. int e = q.front();
  52. q.pop();
  53. for (int i = 0; i < 26; i++)
  54. {
  55. if (trie[e][i])
  56. {
  57. fail[trie[e][i]] = trie[fail[e]][i];
  58. q.push(trie[e][i]);
  59. }
  60. else
  61. trie[e][i] = trie[fail[e]][i];
  62. }
  63. }
  64. }
  65. void query(char *s)
  66. {
  67. int rt = 0, ans = 0;
  68. int len = strlen(s);
  69. for (int i = 0; i < len; i++)
  70. {
  71. int od = s[i] - 'a';
  72. rt = trie[rt][od];
  73. int mx = 0;
  74. for (int j = rt; j; j = fail[j])
  75. {
  76. if (ct[j])
  77. {
  78. mx = ct[j];
  79. }
  80. }
  81. if (mx)
  82. num[i] = i - mx + 2;
  83. else
  84. num[i] = 0;
  85. }
  86. }
  87. }tmp;
  88. int n;
  89. char s[155];
  90. char str[100005];
  91. int main()
  92. {
  93. while (~scanf("%s", str)){
  94. scanf("%d", &n);
  95. int l = 0, ans = 0;
  96. memset(num, 0, sizeof(num));
  97. tmp.init();
  98. for (int i = 1; i <= n; i++)
  99. {
  100. scanf("%s", s);
  101. tmp.insert(s);
  102. }
  103. tmp.get_fail();
  104. tmp.query(str);
  105. int len = strlen(str);
  106. for (int i = 0; i < len; i++)
  107. {
  108. if (num[i] > l)
  109. {
  110. l = num[i];
  111. }
  112. ans = max(ans, i - l + 1);
  113. }
  114. printf("%d\n", ans);
  115. }
  116. }

J

K

L _Wallace_

  1. #include<cstdio>
  2. using namespace std;
  3. const int N=6e5+5;
  4. int root[N];
  5. namespace PerTrie
  6. {
  7. const int SZ=N<<5;
  8. int ch[SZ][2];
  9. int cnt[SZ];
  10. int total=0;//ver. count
  11. int size=0;//node count
  12. void insert(int num)
  13. {
  14. root[++total]=++size;
  15. int l=root[total-1],r=root[total];
  16. for(register int i=24;i>=0;i--)
  17. {
  18. int c=(num>>i)&1;
  19. ch[r][!c]=ch[l][!c];
  20. ch[r][c]=++size;
  21. l=ch[l][c],r=ch[r][c];
  22. cnt[r]=cnt[l]+1;
  23. }
  24. }
  25. int query(int num,int l,int r)
  26. {
  27. int ret=0;
  28. l=root[l],r=root[r];
  29. for(register int i=24;i>=0;i--)
  30. {
  31. int c=(num>>i)&1;
  32. if(cnt[ch[r][!c]]>cnt[ch[l][!c]])
  33. ret|=(1<<i),c^=1;
  34. l=ch[l][c],r=ch[r][c];
  35. }
  36. return ret;
  37. }
  38. }
  39. signed main()
  40. {
  41. int n,m,sum=0;
  42. scanf("%d%d",&n,&m);
  43. PerTrie::insert(0);
  44. for(register int a,i=1;i<=n;i++)
  45. scanf("%d",&a),PerTrie::insert(sum^=a);
  46. while(m--)
  47. {
  48. char op[10];
  49. int l,r,x;
  50. scanf("%s",op);
  51. if(op[0]=='A')
  52. {
  53. scanf("%d",&x);
  54. PerTrie::insert(sum^=x);
  55. }
  56. else
  57. {
  58. scanf("%d%d%d",&l,&r,&x);
  59. printf("%d\n",PerTrie::query(x^sum,l-1,r));
  60. }
  61. }
  62. return 0;
  63. }//艹这题卡常
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注