题目链接   Codeforces Educational Round 33

Problem A

按照题目模拟,中间发现不对就直接输出NO。

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define rep(i, a, b) for (int i(a); i <= (b); ++i)
  6. #define dec(i, a, b) for (int i(a); i >= (b); --i)
  7. #define MP make_pair
  8. #define fi first
  9. #define se second
  10.  
  11. typedef long long LL;
  12.  
  13. int a, b, c, n;
  14.  
  15. int main(){
  16.  
  17. a = 1, b = 2, c = 3;
  18. scanf("%d", &n);
  19. rep(i, 1, n){
  20. int x;
  21. scanf("%d", &x);
  22. if (x != a && x != b) return 0 * puts("NO");
  23. if (x == a) swap(b, c); else swap(a, c);
  24. }
  25.  
  26. puts("YES");
  27. return 0;
  28. }

Problem B

打表然后塞到set里面,然后查找一下。

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define rep(i, a, b) for (int i(a); i <= (b); ++i)
  6. #define dec(i, a, b) for (int i(a); i >= (b); --i)
  7. #define MP make_pair
  8. #define fi first
  9. #define se second
  10.  
  11. typedef long long LL;
  12.  
  13. int c[20];
  14. int a[100010];
  15. int n;
  16. int cnt, et;
  17. set <int> s;
  18.  
  19. int main(){
  20.  
  21. rep(i, 1, 10){
  22. int a = (1 << i) - 1;
  23. int b = (1 << (i - 1));
  24. s.insert(a * b);
  25. }
  26.  
  27. rep(i, 1, et) printf("%d\n", c[i]);
  28.  
  29. scanf("%d", &n);
  30. rep(i, 1, n) if (n % i == 0) a[++cnt] = i;
  31. dec(i, cnt, 1) if (s.count(a[i])) return 0 * printf("%d\n", a[i]);;
  32. return 0;
  33. }

Problem C

在每个连通块里面找个权值最小的然后加起来即可。

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define rep(i, a, b) for (int i(a); i <= (b); ++i)
  6. #define dec(i, a, b) for (int i(a); i >= (b); --i)
  7. #define MP make_pair
  8. #define fi first
  9. #define se second
  10.  
  11. typedef long long LL;
  12.  
  13. const int N = 1e6 + 10;
  14.  
  15. LL a[N];
  16. LL now;
  17. LL ans = 0;
  18. int vis[N];
  19. vector <int> v[N];
  20. int n, m;
  21.  
  22. void dfs(int x){
  23. vis[x] = 1;
  24. now = min(now, a[x]);
  25. for (auto u : v[x]){
  26. if (!vis[u]) dfs(u);
  27. }
  28. }
  29.  
  30. int main(){
  31.  
  32. scanf("%d%d", &n, &m);
  33. rep(i, 1, n) scanf("%lld", a + i);
  34.  
  35. rep(i, 1, m){
  36. int x, y;
  37. scanf("%d%d", &x, &y);
  38. v[x].push_back(y);
  39. v[y].push_back(x);
  40. }
  41.  
  42. rep(i, 1, n) if (!vis[i]){
  43. now = 1e10;
  44. dfs(i);
  45. ans += now;
  46. }
  47.  
  48. printf("%lld\n", ans);
  49. return 0;
  50. }

Problem D

考虑每一天的时候,记录min和max,分别表示钱的下限值和上限值。

如果min都超过d了那肯定不行了,输出-1。

check的时候根据mx是否非负来决定是否更新答案。

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define rep(i, a, b) for (int i(a); i <= (b); ++i)
  6. #define dec(i, a, b) for (int i(a); i >= (b); --i)
  7.  
  8. int n, d;
  9. int x;
  10. int mi = 0, mx = 0;
  11. int ans;
  12.  
  13. int main(){
  14.  
  15. scanf("%d%d", &n, &d);
  16. rep(i, 1, n){
  17. scanf("%d", &x);
  18. if (x){
  19. mi += x, mx += x;
  20. if (mi > d) return 0 * puts("-1");
  21. mx = min(mx, d);
  22. }
  23.  
  24. else{
  25. if (mx >= 0) mi = max(mi, 0);
  26. else ++ans, mx = d, mi = 0;
  27. }
  28. }
  29.  
  30. printf("%d\n", ans);
  31. return 0;
  32. }

Problem E

首先来个预处理,把所有的数的质因子以及指数求出来。

然后对于每一个质因子c,找到他的指数d。

转化成盒子里面放小球的问题。

(盒子不同,小球相同,允许空盒子的情况)

那么当前质因子c对答案的贡献即为$C(y + d - 1, d)$

由于各质因子之间是独立的,所以直接相乘即可。

最后还有-1的情况,对整个ans乘上$2^{y - 1}$即可。

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define rep(i, a, b) for (int i(a); i <= (b); ++i)
  6. #define dec(i, a, b) for (int i(a); i >= (b); --i)
  7. #define MP make_pair
  8. #define fi first
  9. #define se second
  10.  
  11. typedef long long LL;
  12. typedef pair <int, int> PII;
  13.  
  14. const int N = 2e6 + 10;
  15. const int mod = 1e9 + 7;
  16.  
  17. int fac[N];
  18. int c[N];
  19. int val[N];
  20. int ret, q, x, y;
  21. int inv[N];
  22. vector <PII> pri[N];
  23.  
  24. inline int Pow(int a, int b, int mod){
  25. int ret = 1;
  26. for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) ret = 1ll * ret * a % mod;
  27. return ret;
  28. }
  29.  
  30. inline int C(int n, int k){ return 1ll * fac[n] * inv[k] % mod * inv[n - k] % mod; }
  31.  
  32. void init(){
  33. fac[0] = 1;
  34. rep(i, 1, 2e6 + 3) fac[i] = 1ll * fac[i - 1] * i % mod;
  35. rep(i, 0, 2e6 + 3) inv[i] = Pow(fac[i], mod - 2, mod);
  36. rep(i, 1, 1e6 + 3) val[i] = i;
  37. rep(i, 2, 1e6 + 3) if (!c[i]){
  38. for (int j = i * 2; j <= 1e6 + 3; j += i){
  39. c[j] = 1;
  40. int cnt = 0;
  41. while (val[j] % i == 0) val[j] /= i, ++cnt;
  42. pri[j].push_back(MP(i, cnt));
  43. }
  44. }
  45.  
  46. rep(i, 2, 1e6 + 3) if (val[i] > 1)
  47. pri[i].push_back(MP(i, 1));
  48. }
  49.  
  50. int main(){
  51.  
  52. init();
  53. scanf("%d", &q);
  54. while (q--){
  55. int x, y;
  56. scanf("%d%d", &x, &y);
  57. ret = Pow(2, y - 1, mod);
  58. for (auto u : pri[x]){
  59. int d = u.se;
  60. ret = 1ll * ret * C(y + d - 1, d) % mod;
  61. }
  62. printf("%d\n", ret);
  63. }
  64.  
  65. return 0;
  66. }

Problem F

对于每一个结点,维护以他为根的子树中深度在[l, r]范围内的所有点的权值的最小值。

一开始每个点在空树的基础上在自己这个深度插入自己的权值。

每个点的插入复杂度为$O(logn)$,因为要开$logn$棵线段树。

然后dfs一遍,做$n$次线段树合并即可。

查询的时候对询问的距离$d$加上当前结点的深度$deep$,这样就构成了一个询问区间$[1, d + deep]$。

为什么左端点是$1$呢,因为当前结点代表的线段树在$[1, deep - 1]$内都没有信息,那么$[1, d + deep]$就可以等效题目的询问区间。

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define rep(i, a, b) for (int i(a); i <= (b); ++i)
  6. #define dec(i, a, b) for (int i(a); i >= (b); --i)
  7. #define MP make_pair
  8. #define fi first
  9. #define se second
  10.  
  11. typedef long long LL;
  12.  
  13. const int N = 1e5 + 10;
  14. const int M = 2e7 + 10;
  15.  
  16. int father[N], deep[N];
  17. int n, r;
  18. vector <int> v[N];
  19. int a[N];
  20. int t[M], ls[M], rs[M];
  21. int tot = 0;
  22. int val[M];
  23. int m;
  24. int ans;
  25.  
  26. void dfs(int x, int fa, int dep){
  27. deep[x] = dep;
  28. father[x] = fa;
  29. for (auto u : v[x]){
  30. if (u == fa) continue;
  31. dfs(u, x, dep + 1);
  32. }
  33. }
  34.  
  35. int ins(int x, int a, int b, int c, int p){
  36. int y = ++tot;
  37. val[y] = min(val[x], p);
  38. if (a == b) return y;
  39. int mid = (a + b) >> 1;
  40. if (c <= mid) ls[y] = ins(ls[x], a, mid, c, p), rs[y] = rs[x];
  41. else ls[y] = ls[x], rs[y] = ins(rs[x], mid + 1, b, c, p);
  42. return y;
  43. }
  44.  
  45. int ask(int x, int a, int b, int d){
  46. if (b <= d) return val[x];
  47. int mid = (a + b) >> 1, t = ask(ls[x], a, mid, d);
  48. if (d > mid) t = min(t, ask(rs[x], mid + 1, b, d));
  49. return t;
  50. }
  51.  
  52. int merge1(int x, int y, int a, int b){
  53. if (!x || !y) return x + y;
  54. int z = ++tot;
  55. val[z] = min(val[x], val[y]);
  56. if (a == b) return z;
  57. int mid = (a + b) >> 1;
  58. ls[z] = merge1(ls[x], ls[y], a, mid);
  59. rs[z] = merge1(rs[x], rs[y], mid + 1, b);
  60. return z;
  61. }
  62.  
  63. void work(int x, int fa){
  64. for (auto u : v[x]){ if (u == fa) continue; work(u, x); }
  65. for (auto u : v[x]){
  66. if (u == fa) continue;
  67. t[x] = merge1(t[x], t[u], 1, n);
  68. }
  69. }
  70.  
  71. int main(){
  72.  
  73. scanf("%d%d", &n, &r);
  74. rep(i, 1, n) scanf("%d", a + i);
  75. rep(i, 0, 2e7) val[i] = 2147000000;
  76.  
  77. rep(i, 2, n){
  78. int x, y;
  79. scanf("%d%d", &x, &y);
  80. v[x].push_back(y);
  81. v[y].push_back(x);
  82. }
  83.  
  84. dfs(r, 0, 1);
  85. rep(i, 1, n) t[i] = ins(0, 1, n, deep[i], a[i]);
  86. work(r, 0);
  87. ans = 0;
  88. scanf("%d", &m);
  89. while (m--){
  90. int x, y;
  91. scanf("%d%d", &x, &y);
  92. x = ((x + ans) % n) + 1;
  93. y = ((y + ans) % n);
  94. y += deep[x];
  95. if (y > n) y = n;
  96. printf("%d\n", ans = ask(t[x], 1, n, y));
  97. }
  98.  
  99. return 0;
  100. }

Codeforces Educational Round 33 题解的更多相关文章

  1. Codeforces Educational Round 92 赛后解题报告(A-G)

    Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...

  2. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

  3. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  4. [CodeForces]Educational Round 52

    幸好我没有打这场,我VP的时候在C题就卡死了,我果然还是太菜了. A Vasya and Chocolate 题意:一个巧克力\(c\)元,买\(a\)赠\(b\),一共有\(n\)元,问能买几个巧克 ...

  5. Codeforces Educational Round 37

    Solved   CodeForces 920A Water The Garden   Solved   CodeForces 920B Tea Queue   Solved   CodeForces ...

  6. Codeforces Educational Round 57

    这场出题人好像特别喜欢998244353,每个题里都放一个 A.Find Divisible 考察选手对输入输出的掌握 输出l 2*l即可(为啥你要放这个题,凑字数吗 #include<cstd ...

  7. Codeforces Educational Round 21

    A =w= B qwq C wvw D(multiset) 题意: 有n(n<=1e5)个数,希望通过把一个位置y的数字放到位置x上这个操作,使得新序列的某个前缀和等于总和的一半,问这样的操作是 ...

  8. Codeforces Global Round 3 题解

    这场比赛让我上橙了. 前三题都是大水题,不说了. 第四题有点难想,即使想到了也不能保证是对的.(所以说下面D的做法可能是错的) E的难度是 $2300$,但是感觉很简单啊???说好的歪果仁擅长构造的呢 ...

  9. Educational Round 64 题解

    前言: 这场太难了……我一个紫名只打出两题……(虽说感觉的确发挥不够好) 一群蓝绿名的dalao好像只打了两题都能升分的样子…… 庆幸的是最后A出锅然后unr了>///< 写一波题解纪念这 ...

随机推荐

  1. jvm架构以及Tomcat优化

      JVM栈 JVM栈是线程私有的,每个线程创建的同时都会创建JVM栈,JVM栈中存放的为当前线程中局部基本类型的变量(java中定义的八种基本类型:boolean.char.byte.short.i ...

  2. markdown快捷键

    分组 功能 操作 快捷键 设置标题 一级标题 Heading1 Ctrl+1 二级标题 Heading2 Ctrl+2 三级标题 Heading3 Ctrl+3 四级标题 Heading4 Ctrl+ ...

  3. Linux网络编程:客户端/服务器的简单实现

    一. Socket的基本知识 1. socket功能 Socket层次 Socket实质上提供了进程通信的端点,进程通信之前,双方必须首先各自创建一个端点,否则是没有办法建立联系并相互通信的. 每一个 ...

  4. myeclipse中hibernate生成映射文件

    在hibernate中,每个数据表对应的其实是一个实体类,每个实体类有一个对应的hbm.xml配置文件匹配,myeclipse中有个MyEclipse Database Explorer视图,它提供了 ...

  5. MIME类型-服务端验证上传文件的类型

    MIME的作用 : 使客户端软件,区分不同种类的数据,例如web浏览器就是通过MIME类型来判断文件是GIF图片,还是可打印的PostScript文件. web服务器使用MIME来说明发送数据的种类, ...

  6. webdriver高级应用- 改变一个页面对象的属性值

    适用于一些无法操作的元素,可以直接改他的属性从而操作,代码如下: #encoding=utf-8 from selenium import webdriver import unittest impo ...

  7. 初学-BeautifulSoup爬取豆瓣页面

    # -*- coding: utf-8 -*-import osimport urllibimport urllib2from bs4 import BeautifulSoup headers = { ...

  8. day01_14.遍历数组

    <?php $a = array('a','b','c'); print_r($a); ?> 输出结果:Array ( [0] => a [1] => b [2] => ...

  9. 《Effective Java》笔记 :(一)创建和销毁对象

    一 .考虑用静态工厂方法代替构造器 1. 静态工厂方法与设计模式中的工厂方法模式不同,注意不要混淆 例子: public static Boolean valueOf(boolean b){ retu ...

  10. [svn学习篇]svn使用教程

    http://www.cnblogs.com/longshiyVip/p/4905901.html http://blog.csdn.net/dily3825002/article/details/6 ...