Codeforces 587 E. Duff as a Queen】的更多相关文章

https://codeforces.com/contest/587/problem/E 一个序列, 1区间异或操作 2查询区间子集异或种类数 题解 解题思路大同小异,都是利用异或的性质进行转化,std和很多网友用的都是差分的思想,用两棵线段树 第一棵维护差分序列上的线性基,第二棵维护原序列的异或区间和,两者同时进行修改 考虑两个序列 $(a,b)(d,e)$,按照std的想法,应该是维护$(0 \^ a,a \^ b)(0 \^ d,d \^ e)$ 然后合并首尾变成$(0 \^ a,a \^…
题目链接:http://codeforces.com/contest/587/problem/E 其实就是线段树维护区间线性基,合并的时候注意一下.复杂度${O(nlog^{3})}$ #include<iostream> #include<cstdio> #include<algorithm> #include<vector> #include<cstdlib> #include<cmath> #include<cstring…
C. Queen time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a rooted tree with vertices numerated from 11 to nn. A tree is a connected graph without cycles. A rooted tree has a s…
题目链接: B. Duff in Beach time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output While Duff was resting in the beach, she accidentally found a strange array b0, b1, ..., bl - 1 consisting of l posit…
$n \leq 200000$的序列,支持以下$q \leq 4e4$个操作:区间异或$k$:查询区间能异或出多少不同的数.数字$0 \leq a_i \leq 1e9$. 大概是要区间线性基.区间修改用差分.异或也是可以差分的:$b_i=a_i \ \ xor \ \ a_i-1$,则$a_l,a_{l+1},...,a_{r}$的线性基跟$a_l,b_{l+1},...,b_{r}$的线性基一样,询问的时候取出$a_l$和$b_{l+1},...,b_r$即可.线段树维护$b_i$的区间线性…
A.Duff and Weight Lifting(思维) 显然题目中只有一种情况可以合并 2^a+2^a=2^(a+1).我们把给出的mi排序一下,模拟合并操作即可. # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> # include <sta…
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取模. 因为取模后至少减半, 复杂度$O(nlognlogC)$ 2. CF 431E Chemistry Experiment 大意: n个试管, 第$i$个试管有$a_i$单位水银, m个操作: 1, 修改$a_x$改为$v$. 2, 将$v$单位水倒入试管, 求一种方案使得有水的试管水银与水总量的最大…
D. Duff in Beach Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/problem/D Description While Duff was resting in the beach, she accidentally found a strange array b0, b1, ..., bl - 1 consisting of l positive integers. Th…
C. Duff and Weight Lifting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/problem/C Description Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of wei…
B. Duff in Love Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/problem/B Description Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such…
A. Duff and Meat Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/problem/A Description Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly aikilo…
B. Pasha and PhonePasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, …
题意: Duff每天要吃ai千克肉,这天肉的价格为pi(这天可以买好多好多肉),现在给你一个数值n为Duff吃肉的天数,求出用最少的钱满足Duff的条件. 思路: 只要判断相邻两天中,今天的总花费 = ai*pi 与昨天的总花费(还有加上今天要吃的肉的重量)= (ai-1 + ai)*pi-1 . 代码如下: #include <iostream> #include <cstdio> #include <cstring> #include <fstream>…
C. Queen time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a rooted tree with vertices numerated from 11 to nn. A tree is a connected graph without cycles. A rooted tree has a s…
题意(CodeForces 588E) 给定一棵\(n\)个点的树,给定\(m\)个人(\(m\le n\))在哪个点上的信息,每个点可以有任意个人:然后给\(q\)个询问,每次问\(u\)到\(v\)上的路径有的点上编号最小的\(k(k \le 10)\)个人(没有那么多人就该有多少人输出多少人). 分析 \(u\)到\(v\)上路径的询问很显然的想到LCA,但是要维护前\(k\)个在路径上的最小的点似乎是个有点麻烦的问题.其实,找到了LCA(设为\(p\)点),我们就可以同样的利用倍增的思想…
B. Duff in Love time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer…
链接: https://codeforces.com/contest/1216/problem/D 题意: There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and eac…
链接: https://codeforces.com/contest/1216/problem/C 题意: There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the botto…
链接: https://codeforces.com/contest/1216/problem/B 题意: Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a table. Cans are numbered from left to right from 1…
链接: https://codeforces.com/contest/1216/problem/A 题意: Nikolay got a string s of even length n, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from 1 to n. He wants to modify his string so that every its prefix…
https://codeforces.com/contest/1216/problem/A A. Prefixes 题意大概就是每个偶数位置前面的ab数目要相等,很水,被自己坑了 1是没看见要输出修改后的字符串,2是修改的写反了..3是忘记清零了?,生生把罚时拖的... 本来四分钟的题的..然后罚时+10分钟过题,我晕了,以后还是要再认真一点,比如说把样例测完.. #include<bits/stdc++.h> using namespace std; typedef long long ll…
题目:https://codeforces.com/contest/1216/problem/F 题意:一排有n个位置,我要让所有点都能联网,我有两种方式联网,第一种,我直接让当前点联网,花费为i,第二种,如果当前点的值为1,代表当前点可以放置一个路由器,范围 [i-k,i+k]都能连上网,花费为i,求最小花费是所有点都能连上网 思路:这个很容易看出是一个DP,我们设立dp[i],为前i个位置都能连上网的最小花费,因为设立一个路由器左右范围都可以联网,所以我们考虑设立路由器的右端点,如果i-k可…
题目链接:Round #587 题目答案:官方Editorial.My Solution A. Prefixes 题意:给一字符串,只含有'a'或'b',需要改变某些位置('a'变'b'或'b'变'a'),使得该字符串任意偶数长度前缀中'a'和'b'个数相等,求改变的最少次数以及更改后的字符串. 题解:遍历,判断s[2i]和s[2i+1]是否相等.如果相等,需要一次更改,并将其中一个改为不同字母. B. Shooting 题意:给\(n\)个编号\(1\)~\(n\)的射击目标,每个目标有不同的…
Codeforces 题面传送门 & 洛谷题面传送门 2-SAT hot tea. 首先一眼二分答案,我们二分答案 \(mid\),那么问题转化为,是否存在一个所有边权都 \(\le mid\) 的集合 \(S\),满足 \(S\)​ 中任意两条边的端点互不相同,并且没有选择的选择的边每种颜色的边两两之间的端点也互不相同. 乍一看这个问题看似无法解决.但不难发现每条边只有两种状态--选或不选,也就是说我们考虑将每条边拆成两个点 \(x_i\)​ 和 \(\lnot x_i\)​,分别表示边 \(…
题意: 一个数x被定义为lovely number需要满足这样的条件:不存在一个数a(a>1),使得a的完全平方是x的因子(即x % a2  != 0). 给你一个数n,求出n的因子中为lovely number的最大因子. 思路: 由于1<=n<=0=109,所以我们只要从1到找sqrt(n)就好,然后先从最大因子开始判断是否满足lovely number的条件,当满足时直接出输出即可. 代码如下: #include <iostream> #include <cstd…
题意:一个n个点的数, m个人住在其中的某些点上, 每个人的标号1-m, 询问u-v 路径上标号前a个人,并输出标号,a < 10. 作法, 利用倍增, ID[j][i] 表示i到i的第2^j个祖先上前10个人, 那么每次询问直接维护就好了,细节好多, 刚开始不知道怎么求ID[j][i]. 这里把2^j分成两部分, 前2^(j-1)和 后2^(j-1)个, 然后递推的维护. 感觉树链剖分也可以做, 不知道会不会TLE, 树链剖分的话 线段树的每个点维护10个值, 每次合并就行了. #includ…
---恢复内容开始--- You are given a rooted tree with vertices numerated from 11 to nn . A tree is a connected graph without cycles. A rooted tree has a special vertex named root. Ancestors of the vertex ii are all vertices on the path from the root to the v…
题目 水题,dfs #include <iostream> #include <stdio.h> #include <algorithm> using namespace std; #define MAX 100000 struct Node { int value; int c; int next; }edge[MAX+5]; int pos; int head[MAX+5]; int a[MAX+5]; int aa=0; int n; void Init() {…
题意:一数列an,如果存在一个k,有2^(ai)+2^(aj)+......=2^k成立,那么一次能拿走ai,aj这些全部.问最少拿的次数. 太简单. 乱码 //#pragma comment(linker,"/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<ve…
题意概述: 给出一棵N个结点的树,然后有M个居民分散在这棵树的结点上(允许某个结点没有居民).现在给出一些询问形如u,v,a,定义k=min(x,a),其中x表示的是u->v路径上的居民数量.将所有路径上的居民编号升序排列之后得到序列p1,p2,...,px,要求对于每一组询问,输出k,p1,p2,...,pk. N,M,Q<=10^5,1<=a<=10. 分析: 实际上这个题是被丢在数据结构作业里面的只是....好像没有这个必要? 分析一波可以发现每个点可能在答案中出现的居民最多…