题目链接   Codeforces Educational Round 33

Problem A

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

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; int a, b, c, n; int main(){ a = 1, b = 2, c = 3;
scanf("%d", &n);
rep(i, 1, n){
int x;
scanf("%d", &x);
if (x != a && x != b) return 0 * puts("NO");
if (x == a) swap(b, c); else swap(a, c);
} puts("YES");
return 0;
}

Problem B

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

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; int c[20];
int a[100010];
int n;
int cnt, et;
set <int> s; int main(){ rep(i, 1, 10){
int a = (1 << i) - 1;
int b = (1 << (i - 1));
s.insert(a * b);
} rep(i, 1, et) printf("%d\n", c[i]); scanf("%d", &n);
rep(i, 1, n) if (n % i == 0) a[++cnt] = i;
dec(i, cnt, 1) if (s.count(a[i])) return 0 * printf("%d\n", a[i]);;
return 0;
}

Problem C

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

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; const int N = 1e6 + 10; LL a[N];
LL now;
LL ans = 0;
int vis[N];
vector <int> v[N];
int n, m; void dfs(int x){
vis[x] = 1;
now = min(now, a[x]);
for (auto u : v[x]){
if (!vis[u]) dfs(u);
}
} int main(){ scanf("%d%d", &n, &m);
rep(i, 1, n) scanf("%lld", a + i); rep(i, 1, m){
int x, y;
scanf("%d%d", &x, &y);
v[x].push_back(y);
v[y].push_back(x);
} rep(i, 1, n) if (!vis[i]){
now = 1e10;
dfs(i);
ans += now;
} printf("%lld\n", ans);
return 0;
}

Problem D

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

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

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

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) int n, d;
int x;
int mi = 0, mx = 0;
int ans; int main(){ scanf("%d%d", &n, &d);
rep(i, 1, n){
scanf("%d", &x);
if (x){
mi += x, mx += x;
if (mi > d) return 0 * puts("-1");
mx = min(mx, d);
} else{
if (mx >= 0) mi = max(mi, 0);
else ++ans, mx = d, mi = 0;
}
} printf("%d\n", ans);
return 0;
}

Problem E

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

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

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

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

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

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

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

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL;
typedef pair <int, int> PII; const int N = 2e6 + 10;
const int mod = 1e9 + 7; int fac[N];
int c[N];
int val[N];
int ret, q, x, y;
int inv[N];
vector <PII> pri[N]; inline int Pow(int a, int b, int mod){
int ret = 1;
for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) ret = 1ll * ret * a % mod;
return ret;
} inline int C(int n, int k){ return 1ll * fac[n] * inv[k] % mod * inv[n - k] % mod; } void init(){
fac[0] = 1;
rep(i, 1, 2e6 + 3) fac[i] = 1ll * fac[i - 1] * i % mod;
rep(i, 0, 2e6 + 3) inv[i] = Pow(fac[i], mod - 2, mod);
rep(i, 1, 1e6 + 3) val[i] = i;
rep(i, 2, 1e6 + 3) if (!c[i]){
for (int j = i * 2; j <= 1e6 + 3; j += i){
c[j] = 1;
int cnt = 0;
while (val[j] % i == 0) val[j] /= i, ++cnt;
pri[j].push_back(MP(i, cnt));
}
} rep(i, 2, 1e6 + 3) if (val[i] > 1)
pri[i].push_back(MP(i, 1));
} int main(){ init();
scanf("%d", &q);
while (q--){
int x, y;
scanf("%d%d", &x, &y);
ret = Pow(2, y - 1, mod);
for (auto u : pri[x]){
int d = u.se;
ret = 1ll * ret * C(y + d - 1, d) % mod;
}
printf("%d\n", ret);
} return 0;
}

Problem F

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

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

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

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

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

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

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; const int N = 1e5 + 10;
const int M = 2e7 + 10; int father[N], deep[N];
int n, r;
vector <int> v[N];
int a[N];
int t[M], ls[M], rs[M];
int tot = 0;
int val[M];
int m;
int ans; void dfs(int x, int fa, int dep){
deep[x] = dep;
father[x] = fa;
for (auto u : v[x]){
if (u == fa) continue;
dfs(u, x, dep + 1);
}
} int ins(int x, int a, int b, int c, int p){
int y = ++tot;
val[y] = min(val[x], p);
if (a == b) return y;
int mid = (a + b) >> 1;
if (c <= mid) ls[y] = ins(ls[x], a, mid, c, p), rs[y] = rs[x];
else ls[y] = ls[x], rs[y] = ins(rs[x], mid + 1, b, c, p);
return y;
} int ask(int x, int a, int b, int d){
if (b <= d) return val[x];
int mid = (a + b) >> 1, t = ask(ls[x], a, mid, d);
if (d > mid) t = min(t, ask(rs[x], mid + 1, b, d));
return t;
} int merge1(int x, int y, int a, int b){
if (!x || !y) return x + y;
int z = ++tot;
val[z] = min(val[x], val[y]);
if (a == b) return z;
int mid = (a + b) >> 1;
ls[z] = merge1(ls[x], ls[y], a, mid);
rs[z] = merge1(rs[x], rs[y], mid + 1, b);
return z;
} void work(int x, int fa){
for (auto u : v[x]){ if (u == fa) continue; work(u, x); }
for (auto u : v[x]){
if (u == fa) continue;
t[x] = merge1(t[x], t[u], 1, n);
}
} int main(){ scanf("%d%d", &n, &r);
rep(i, 1, n) scanf("%d", a + i);
rep(i, 0, 2e7) val[i] = 2147000000; rep(i, 2, n){
int x, y;
scanf("%d%d", &x, &y);
v[x].push_back(y);
v[y].push_back(x);
} dfs(r, 0, 1);
rep(i, 1, n) t[i] = ins(0, 1, n, deep[i], a[i]);
work(r, 0);
ans = 0;
scanf("%d", &m);
while (m--){
int x, y;
scanf("%d%d", &x, &y);
x = ((x + ans) % n) + 1;
y = ((y + ans) % n);
y += deep[x];
if (y > n) y = n;
printf("%d\n", ans = ask(t[x], 1, n, y));
} return 0;
}

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. Vue 父子组件间的通信

    前言 在 Vue 项目中父子组件的通信是非常常见的,最近做项目的时候发现对这方面的知识还不怎么熟练,在这边做一下笔记,系统学习一下吧. 1 父组件传值给子组件 1.1 传值写法 父组件传值给子组件,这 ...

  2. UVA1589——xiangqi

    开始碰到这个题时觉得太麻烦了直接跳过没做,现在放假了再次看这个题发现没有想象中那么麻烦,主要是题目理解要透彻,基本思路就是用结构体数组存下红方棋子,让黑将军每次移动一下,看移动后是否有一个红方棋子可以 ...

  3. Linux学习-逻辑滚动条管理员 (Logical Volume Manager)

    LVM 可以整合多个实体 partition 在一起, 让这些 partitions 看起来就像是一个磁盘一样!而且,还可以在未来新增或移除其他的实 体 partition 到这个 LVM 管理的磁盘 ...

  4. Hadoop4.2HDFS测试报告之六

    测试结论 第一组数据作表格作图: 第二组数据作表格作图: 根据以上图分析得出以下结论: 1. 本地存储的读写速率基本保持23M左右,说明本地存储比较稳定. 2. HDFS存储两个数据节点的读写速率性能 ...

  5. Leetcode207--->课程表(逆拓扑排序)

    题目: 课程表,有n个课程,[0, n-1]:在修一个课程前,有可能要修前导课程: 举例: 2, [[1,0]] 修课程1前需要先修课程0 There are a total of 2 courses ...

  6. 使mysql的表内容可以输入中文内容

    修改数据库的字符集mysql>use mydb mysql>alter database mydb character set utf8;

  7. Baum Welch估计HMM参数实例

    Baum Welch估计HMM参数实例 下面的例子来自于<What is the expectation maximization algorithm?> 题面是:假设你有两枚硬币A与B, ...

  8. Leetcode 447.回旋镖的数量

    回旋镖的数量 给定平面上 n 对不同的点,"回旋镖" 是由点表示的元组 (i, j, k) ,其中 i 和 j 之间的距离和 i 和 k 之间的距离相等(需要考虑元组的顺序). 找 ...

  9. 紫书第一章训练1 D -Message Decoding

    Some message encoding schemes require that an encoded message be sent in two parts. The first part, c ...

  10. Difference between git remote add and git clone

    http://stackoverflow.com/questions/4855561/difference-between-git-remote-add-and-git-clone git remot ...