@codeforces - 549E@ Sasha Circle】的更多相关文章

目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定两个点集 M 与 S,求是否存在一个圆能够分割两个点集. 原题传送门. @solution@ 不妨考虑圆内是 M,圆外是 S 的情况.反过来同理. 如果 M 只有一个点,显然有解:否则至少可以让分割圆经过 M 的凸包上的某两个点. 一个暴力做法是枚举这两个点 x, y,则其他点会对分割圆的位置产生限制.可以用 \(\vec{xy}\) 所对圆周角大小来描述这…
Codeforces 1109D. Sasha and Interesting Fact from Graph Theory 解题思路: 这题我根本不会做,是周指导带飞我. 首先对于当前已经有 \(m\) 个联通块的有标号生成树的数量是 \[ n^{m-2}\prod_{i=1}^msize_i \] 其中 \(size_i\) 是第 \(i\) 个联通块的大小. 原理就是考虑 \(prufer\) 编码,先把每个联通块看成一个点,那么序列中每出现一个第 \(i\) 联通块缩成的点,能连的边的数…
Sasha and Interesting Fact from Graph Theory n 个 点形成 m 个有标号森林的方案数为 F(n, m) = m * n ^ {n - 1 - m} 然后就没啥难度了... #include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #defin…
题目链接:http://codeforces.com/problemset/problem/1189/B AC代码: #include<bits/stdc++.h> using namespace std; ; int a[maxn]; int b[maxn]; int c[maxn]; bool check(int i) { ]+a[i+]) return true; else return false; } int main() { int n; cin >> n; ;i &l…
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules…
Codeforces 题面传送门 & 洛谷题面传送门 讲个笑话,这题是 2020.10.13 dxm 讲题时的一道例题,而我刚好在一年后的今天,也就是 2021.10.13 学 LCT 时做到了这道题...... 首先考虑一个区间的导出子图是一棵树的充要条件.显然这些点组成的边集不能有环,其次这些点组成的导出子图必须满足 \(|V|-|E|=1\),而对于一个不存在环的图必然有 \(|V|-|E|\ge 1\),因此这两个条件加在一起就组成了一个区间符合条件的充要条件. 考虑如何维护之,注意到当…
线段树. 线段树维护区间矩阵和,操作都是最简单的线段树.$lazy$标记不要记录乘了几次,直接记录乘了几次之后的矩阵就可以了,不然每次下传的时候再算一遍时间复杂度会提高. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include…
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1109E.html 题意 给定一个长度为 n 的数列 a,以及一个模数 M(不一定是质数). 要求支持 q 次以下操作: 区间乘 单点除(保证能够整除) 区间求和,最终结果对 M 取模输出. $$n,q\leq 10^5$$ 题解 这里我们设 $f(x)$ 表示 $\frac x {\gcd(x,M)}$ . 令 $c(x,i)$ 表示 x 最多能够整除 M 的第 $i$ 个质因子的 $c(x,i)$ 次…
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1109D.html 题意 所有边权都是 [1,m] 中的整数的所有 n 个点的树中,点 a 到点 b 的距离恰好是 m 的有几个. $$n,m\leq 10^6$$ 题解 首先显然 a 和 b 的具体值是没用的. 于是我们就可以直接计数: 枚举树链 ab 上除了 a 和 b 有几个节点,假设是 i 个节点,那么这种情况下的方案总数是多少? 首先,ab 路径上 i+1 条 [1,m] 的边的和是 m ,共有…
题意: 桌子上有 n 个石头围成一个环.每个石头都有一种颜色.每种颜色可以由小写英文字母表示.如果每一对相邻的石头都是不同颜色的,则称这 n 个石头构成的环是美丽的.现在,你可以从这 n 个石头中拿走一段连续的石头(可以为空),且你只能拿一次. 对于每个 k(0≤k≤n−1) ,判断是否存在一种取石头的方案,使得在拿走 k 个连续的石头后,剩下的 n−k 个石头构成的环是美丽的. n<=1000000 正解kmp,转换思路,不去考虑拿走什么,考虑留下什么,不去考虑什么合法,去考虑哪些是违法的.…
题目简述:维护以下三种操作 1. "1 t s":在时刻$t$插入命令$s$.保证任意操作后,任意时刻至多只有一个命令. 2. "2 t":删除时刻$t$的命令. 3. "3 l r v":求最小的$t \in [l, r]$,使得$f(t)=0$,其中 $$ f(t) = v+\int_l^t g(x) \mathrm{d} x, $$ 其中设在$[l, r]$时间内的命令依次为$(t_1, s_1), \dots, (t_m, s_m)$,则…
题目简述:给定一个$n \times m$的二维矩阵$a[i][j]$,其中$1 \leq nm \leq 2 \times 10^5$,矩阵元素$1 \leq a[i][j] \leq nm$且互不相等.一个区间$[l, r]$是[好]的,如果所有在$[l, r]$范围内的元素(在平面上)构成了一棵树.求[好]区间$[l, r](1 \leq l \leq r \leq nm)$的个数. 解:code 建模: 令$G = (V, E)$表示二维矩阵$a[i][j]$对应的无向图,构造如下: 1…
题目简述:给定$m \leq 10^9+9$,维护以下操作 1. "1 l r x":将序列$a[l], a[l+1], \dots, a[r]$都乘上$x$. 2. "2 p x":将$a[p]$除以$x$,保证可整除. 3. "3 l r":求$(a[l]+a[l+1]+\dots+a[r]) \bmod m$. 解:code 除了操作2以外,都显然可以用线段树维护. 主要遇到的问题是$m$不一定是质数,不妨设$m = p_1^{m_1} p…
传送门 解题思路: 这道题给了我们一个崭新的角度来看线段树. 我们常常使用的线段树是维护区间的函数的. 这里呢,提示我们线段树其实还可以维护递推. 美好的矩阵递推性质支持了这一功能. 或者说,对于递推项求和,可以使用线段树维护矩阵. 区间向前递推可以用懒惰标记记录递推矩阵. 区间的查询可以是子节点矩阵和. 这其实也是满足分配率的. 最后pushup,pushdown搞一搞就好了. 代码(闲来无事卡常码风突变): #include<cstdio> #include<cstring>…
https://codeforc.es/contest/1189/problem/B 优先考虑最大的元素怎么构造.拿两个次大的围着他就很好,但是其他的怎么安排呢?就直接降序排列就可以了. a数组还开错了. #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; int a[100005]; int main() { #ifdef Yinku freopen("Yinku.in", &…
下面是题解,做的不好.下一步的目标是rating涨到 1800,没打过几次cf A. Face Detection Author: Monyura One should iterate through each 2x2 square and check if it is possible to rearrange letters in such way they they form the word "face". It could be done i.e. by sorting al…
C. Sasha and Array 题目大意&题目链接: http://codeforces.com/problemset/problem/718/C 长度为n的正整数数列,有m次操作,$opt==1$时,对$[L,R]$全部加x,$opt==2$时,对$[L,R]$求$\sum_{i=L}^{R}Fibonacc(a_{i})$. 题解: 线段树+矩阵快速幂. 在每个线段树存一个转移矩阵,然后YY即可. 代码: #include<cstdio> #include<cstrin…
Problem   Codeforces Round #539 (Div. 2) - D. Sasha and One More Name Time Limit: 1000 mSec Problem Description Input The first line contains one string s (1≤|s|≤5000) — the initial name, which consists only of lowercase Latin letters. It is guarante…
Problem   Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax Time Limit: 2000 mSec Problem Description Input The first line contains one integer n (2≤n≤3⋅10^5) — the size of the array. The second line contains n integers a1,a2,…,an (0≤ai<2^…
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules…
E. Sasha and Array 题目连接: http://codeforces.com/contest/719/problem/E Description Sasha has an array of integers a1, a2, ..., an. You have to perform m queries. There might be queries of two types: 1 l r x - increase all integers on the segment from l…
链接:https://codeforces.com/contest/1169/problem/A 题意: The circle line of the Roflanpolis subway has nn stations. There are two parallel routes in the subway. The first one visits stations in order 1→2→…→n→1→2→…1→2→…→n→1→2→… (so the next stop after sta…
Codeforces Round #581 (Div. 2)-E. Natasha, Sasha and the Prefix Sums-动态规划+组合数学 [Problem Description] ​ 给你\(n\)个\(1\),\(m\)个\(-1\),他们任意排列有\(\frac{(n+m)!}{n!\cdot m!}\)中排列,每种排列都有一个最大前缀和(可能为\(0\)),求所有排列的最大前缀和之和为多少. [Solution] ​ 定义\(dp[i][j]\)表示有\(i\)个\(…
题目链接: E. Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Sasha has an array of integers a1, a2, ..., an. You have to perform m queries. There might be queries of two types:…
题目链接:http://codeforces.com/contest/719/problem/E 题意:操作1将[l, r] + x; 操作2求f[l] + ... + f[r]; 题解:注意矩阵可以是a*(b + c) = a*b + a*c ,还有update的时候传入矩阵 //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream…
题目连接:652F - Ants on a Circle 题目大意:\(n\)个蚂蚁在一个大小为\(m\)的圆上,每个蚂蚁有他的初始位置及初始面向,每个单位时间蚂蚁会朝着当前面向移动一个单位长度,在遇到其它蚂蚁时会立刻掉头.求经过\(t\)个单位时间后每一个蚂蚁的所在位置 题解:首先可以发现,最终答案其实是在不考虑碰撞下得出答案的一个排列,而且蚂蚁们的相对位置是不会改变的.所以如果求出了其中任意一个蚂蚁的位置,就能求出最终的答案. 为了方便起见,先默认所有蚂蚁的位置是按升序排的,且第一个蚂蚁的位…
https://codeforces.com/contest/1113/problem/B 思想不难,但是在比较大小的时候,我选择了很笨的方法,我用两个数变化之后的差值大小来进行选择,然后最后再进行数组的更改,最后求和. 实际上,可以先求和,在每次运算之前,减去两个数,然后再把处理后的两个数加上,比较和的大小. #include<bits/stdc++.h> using namespace std; int n; vector<int> num; vector<int>…
Codeforces 1109 C 题意:现在有个碗,每时每刻其中的水量都会加一个整数(可以为负). 给\(n\)个询问,询问有\(3\)种类型: \(1\ t\ s\):将从第\(t\)秒开始水量增加的速度改为\(s\). \(2\ t\):删除第\(t\)秒对水量增加速度的改变. \(3\ l\ r\ v\):考虑从第\(l\)秒到第\(r\)秒对水量增加速度的改变,并假设初始时水量为\(v\),问什么时候水量降至\(0\). 思路:一看就是道数据结构题. 前两个操作其实都是改变一个时间段的…
Ants on a Circle 感觉这个思路好巧妙啊. 我们能发现不管怎么碰撞,初始态和最终态蚂蚁间的相对顺序都是一样的, 并且所占的格子也是一样的, 那么我们就只需要 找到其中一个蚂蚁的最终位置就能确定所有蚂蚁的位置了, 我们考虑找初始为止离0最近的那个蚂蚁的最终位置,我们能发现 蚂蚁从m-1->0  rk++, 蚂蚁从0->m-1 rk--, 在取模意义下rk就是那个蚂蚁的最终位置. #include<bits/stdc++.h> #define LL long long #…
E. Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Sasha has an array of integers a1, a2, ..., an. You have to perform m queries. There might be queries of two types: 1 l r…