约数 区间codeforces divisors

Educational Codeforces Round 16 E

提炼 首先观察范围发现是1e7 好像是dp 但是发现直接朴素的dp发现是有环的 跑了一发dijk带log 答案是肯定没过 我们可以想一下 如果我要是一个10 我肯定不会从11转移过来 因为我不如先去5 再2 如果我要是一个9 我可以从8+1转移过来 也可以从52-1转移过来 这样我们就消除了环 in ......
Educational Codeforces Round 16

Educational Codeforces Round 158 (Rated for Div. 2)

A. Line Trip There is a road, which can be represented as a number line. You are located in the point \(0\) of the number line, and you want to travel ......
Educational Codeforces Round Rated 158

Codeforces Round 911 (Div. 2)补题C、D

Codeforces Round 911 (Div. 2) C. Anji's Binary Tree 思路 树形dp ac代码 #include <bits/stdc++.h> using namespace std; using i64 = long long; const i64 inf = ......
Codeforces Round 911 Div

Codeforces Round 911 (Div. 2)

B题 假设我们考虑能不能获得1,注意到b-c的奇偶性不会改变,然后特判一下只有一个大于0就行。 #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<map> #include<vector> ......
Codeforces Round 911 Div

Codeforces Round 911 (Div. 2) D

Codeforces Round 911 (Div. 2) D D. Small GCD 题意 定义\(f(a,b,c)\)为\(a,b,c\)中较小两个数的\(gcd\),给定数组\(a_{1...n}\),求\(\sum\limits_{i=1}^{n}\sum\limits_{j=i+1}^{ ......
Codeforces Round 911 Div

Codeforces Round 894 (Div. 3)

Codeforces Round 894 (Div. 3) A. Gift Carpet 题意:判断一列一个字母有没有“vika” 思路:挨个枚举每一列 #include<bits/stdc++.h> using namespace std; char mp[25][25]; char x[]={' ......
Codeforces Round 894 Div

Codeforces Round 903 (Div. 3)

Codeforces Round 903 (Div. 3) A. Don't Try to Count 大概题意给你两个字符串a,b。a串可进行的操作为将整个a串复制到之前的a串后面(直接用a+a即可),然后看操作多少次可以让b串变为a串的子串如果不能就输出-1。 #include <iostrea ......
Codeforces Round 903 Div

Codeforces Round 911 (Div. 2)

Codeforces Round 911 (Div. 2) D - Small GCD 思路:求Σf(ai,aj,ak),其实就是所有gcd(ai,aj)的贡献,那么ijk的顺序就不重要了,首先可以将a排序。 可以枚举j,求出Σgcd(ai,aj),i<j,且k的个数等于Σgcd(ai,aj)贡献的 ......
Codeforces Round 911 Div

Codeforces Round 911 (Div. 2) D、E

CF1900D ​ 从小到大排列,第\(i\)个元素作为最大值对答案的贡献为\(\sum_{x=1}^{i-1} \sum_{y=x+1}^{i-1} gcd(a_x,a_y)\),即区间\([1,i-1]\)两两元素\(gcd\)和,记作\(val_{i-1}\)。然后考虑用第\(i\)个元素更新 ......
Codeforces Round 911 Div

Codeforces Round 911 (Div. 2) D. Small GCD

题目链接:https://codeforces.com/contest/1900/problem/D 对于已经排序好的数组 \(a\),我们需要计算: \[\sum_{i=1}^n\sum_{j=i+1}^n gcd(a_i, a_j) * (n - j) \]由于 \(\sum_{d|n} \ph ......
Codeforces Round Small 911 Div

E. Permutation Sorting 树状数组实现离线区间数点

题目链接🔗 题意解读:给定一串数组a,每次操作将所有的 a[i] != i 的数循环右移一位,直到所有的数都在自己的位置上。求对于1到n之间的每个i,需要移动多少次。 首先,先考虑移动次数的问题: 为了简化循环问题,考虑将数组长度手动扩充至 2 * n,对于所有的位置 i 上的一个 a[i] ,分 ......
数组 区间 Permutation Sorting

Codeforces Round 911 (Div. 2) D

D. Small GCD 题意 给定数组 \(a\) ,求出数组 \(a\) 中所有三元组中较小的两个元素的 \(gcd\) 的和. 分析 显然数组中元素的顺序不影响统计答案,为了方便先将数组排个序; 枚举中间的元素 \(a_j\) ,那么只有它前边的元素能与其产生贡献,它后边的元素个数就是这个贡献 ......
Codeforces Round 911 Div

Codeforces Round 911 (Div. 2)

Codeforces Round 911 (Div. 2) A - Cover in Water 解题思路: 如果存在三个以上相邻的格子需要填,那么答案为二,否则有多少空格答案为多少。 代码: #include <bits/stdc++.h> using namespace std; using l ......
Codeforces Round 911 Div

Codeforces Round 911 (Div. 2) A-C

Codeforces Round 911 (Div. 2) A. Cover in Water 题意: 有n个单元格,有的空着有的被堵住,可以做两种操作:给一个空着的单元格放入水;将单元格的水移到另一个单元格。并且,若一个单元格左右两边都有水,它也会自动充满水。所有空着的单元格都要充满水,求最少的放 ......
Codeforces Round 911 A-C Div

Codeforces Round 911 (Div. 2)

2023 11 27 A. Cover in Water 题意是:有一片坑,可以进行两个操作,一个是在一个坑里倒水,一个是把水到在另一个坑里,如果一个坑的左右两边都有水,那么这个坑也会有水 思路:想想发现,只要有三个连续的坑,那么所有的坑都可以被填上,如果没有就只能一个一个的填。 using nam ......
Codeforces Round 911 Div

Codeforces Round 911 (Div. 2)

A - Cover in Water 三个连续的 . 就可以造出无限水,这时直接输出 \(2\),否则输出区间长度和。 Submission B - Laura and Operations 每次操作不会改变不需要的两个数的个数的和的奇偶性,而当这个和为偶数的时候,通过若干操作一定可以全部变成另一个 ......
Codeforces Round 911 Div

Codeforces Round 911 (Div. 2)

比赛录屏 \(A. Cover in Water\) https://codeforces.com/contest/1900/submission/234430348 \(B. Laura and Operations\) https://codeforces.com/contest/1900/su ......
Codeforces Round 911 Div

Codeforces Round 911 (Div. 2) A

真的太菜了…… 题目链接:Problem - A - Codeforces // Problem: A. Cover in Water // Contest: Codeforces - Codeforces Round 911 (Div. 2) // URL: https://codeforces. ......
Codeforces Round 911 Div

Educational Codeforces Round 158 (Rated for Div. 2)

A - Line Trip 最后一段需要往返。 \[ans = \max(\max\limits_{i=1}^{n} a_i-a_{i-1},2(x-a_n)) \]Submission B - Chip and Ribbon 相当于问:每次给一个区间减一,最少需要选择多少个区间使得所有数变成 \( ......
Educational Codeforces Round Rated 158

[Codeforces] CF1799B Equalize by Divide

序列操作(divide.cpp)—CF1799B—1200 题目描述 给您一个 \(a_1,a_2,\dots a_n\) 这样的正整数数组,您可以对它进行多次(可以是零次)这样的操作: 选择两个索引 \(i,j(1 \leq i,j \leq n,i \neq j)\); 将 \(a_i\) 赋值 ......
Codeforces Equalize Divide 1799B 1799

[Codeforces] CF1747C Swap Game

游戏(game.cpp)—CF1747C—1200 \(时间:1s \space |\space 空间:250MB\) 题面翻译 Alice 和 Bob 两个人在玩游戏。 有一个长度为 \(n\) 的序列 \(a\),Alice 和 Bob 两人轮流完成一个操作,Alice 先开始。 每个人可以将数 ......
Codeforces 1747C 1747 Swap Game

Educational Codeforces Round 158 (Rated for Div. 2)

Educational Codeforces Round 158 (Rated for Div. 2) A - Line Trip 解题思路: 每次到加油站油都会加满,所以我们考虑到达两个加油站间需要的最大油量即可。 注意:最后一站的油量是一个来回。 代码: #include <bits/stdc+ ......
Educational Codeforces Round Rated 158

Educational Codeforces Round 158 (Rated for Div. 2)

Educational Codeforces Round 158 (Rated for Div. 2) 基本情况 A题很水,几分钟秒了。 B题想到一个解,被自己 hack 掉之后没有重新想,一直想在自己一开始的基础上改好,结果最后B都没拿下。 B. Chip and Ribbon 我的思路 其实也是 ......
Educational Codeforces Round Rated 158

带修区间mex

1 x y 把x改成y.2 x y 询问区间[x,y]的mex. part0 polylog做法 考虑整体二分,那就转换成了. 保留权值[vl,vr)的数,带修区间数颜色数(是否全部出现过 <=> 颜色数=vr-vl). 这个问题可以直接cdq. 复杂度O(n log^3 n). part1 考虑分 ......
区间 mex

Codeforces Round 686 (Div. 3)

A. Special Permutation #include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pa ......
Codeforces Round 686 Div

Educational Codeforces Round 158 补题(A~D)

A. 思路 找出最大耗油的路程即可 ac代码 #include <bits/stdc++.h> using namespace std; using i64 = long long; const i64 inf = 8e18; typedef pair<int, int> pii; void sol ......
Educational Codeforces Round 158

Educational Codeforces Round 158 A-D

Educational Codeforces Round 158 A-D A. Line Trip 题意: 有一条路,从0到x,你需要开汽车从0到x再返回0,每个单位距离消耗一升油,出发时汽车满油,中间设有n个加油站,求油箱的最小容积 思路: 油箱中的油至少要能坚持从一个加油站开到下一个加油站,注意 ......
Educational Codeforces Round 158 A-D

Educational Codeforces Round 158 (Rated for Div. 2)

A. Line Trip 题意是:有n个加油点,人要来回两趟,问你最少要多少油? using namespace std; int a[100]; void solve(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++)cin>>a[i]; int ans=a[ ......
Educational Codeforces Round Rated 158

Educational Codeforces Round 146 补题(A~C)

Educational Codeforces Round 146 (Rated for Div. 2) A. Coins 题目大意 给你两个整数n和k,问你是否存在两个非负整数x和y,使得 2⋅x+k⋅y=n 成立 思路 裴蜀定理秒了,记得开long long ac代码 #include <bits ......
Educational Codeforces Round 146

算法学习笔记(43): 可持久化线段树 - 区间加!

可持久化线段树 也叫做主席树,单点修改时简单,使用空间 \(O(\log n)\),问题在于如何区间加。 区间覆盖可以做,但是似乎只能单点查? 所以我们需要引入标记永久化的概念。 一个标记在没有下放前会放在 \(O(\log n)\) 个点上,这覆盖了整个操作区间。 一般来说我们会 update 更 ......
线段 区间 算法 笔记 43
共1720篇  :10/58页 首页上一页10下一页尾页