CodeForces - 855B ring 前缀和】的更多相关文章

邓布利多教授正在帮助哈利摧毁魂器.当他怀疑一个魂器出现在那里时,他去了冈特沙克.他看到Marvolo Gaunt的戒指,并将其确定为魂器.虽然他摧毁了它,但仍然受到诅咒的影响.斯内普教授正在帮助邓布利多解除诅咒.为此,他想给Dumbledore提供他制作的药水x滴. x的值被计算为给定p,q,r和阵列a1,a2,......的p·ai + q·aj + r·ak的最大值,使得1≤i≤j≤k≤n.帮助Snape找到x的值.请注意x的值可能是负数. Input 第一行输入包含4个整数n,p,q,r(…
855B - Marvolo Gaunt's Ring 思路:①枚举a[j],a[i]和a[k]分别用前缀最小值最大值和后缀最小值和后缀最大值确定. ②dp,dp[i][j]表示到第j为止,前i+1个值加起来的最大值. 代码: 代码①: #include<bits/stdc++.h> using namespace std; #define ll long long ; const int INF=0x3f3f3f3f; int a[N]; int premx[N]; int premn[N]…
B. Marvolo Gaunt's Ring Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is sti…
It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically,…
链接:CodeForces - 776C 题意:给出数组 a[n] ,问有多少个区间和等于 k^x(x >= 0). 题解:求前缀和,标记每个和的个数.对每一个数都遍历到1e5,记录到答案. #include <bits/stdc++.h> using namespace std; long long n, k; map<long long, long long> mp; int main() { scanf("%lld%lld", &n, &am…
链接:CodeForces - 948C 题意:N天,每天生产一堆雪体积 V[i] ,每天每堆雪融化 T[i],问每天融化了多少雪. 题解:对 T 求前缀和,求每一堆雪能熬过多少天,再记录一下多余的就行了. #include <bits/stdc++.h> using namespace std; ; int N; int V[maxn], T[maxn]; long long S[maxn], E[maxn], D[maxn], X[maxn]; int main() { scanf(&qu…
http://codeforces.com/problemset/problem/1189/C 求一下前缀和,给定区间的数字和除以10就是答案 AC代码: #include<iostream> #include<algorithm> #include<vector> using namespace std; long long seq[100050]; int main(){     long long int num;     cin>>num;     …
B. Marvolo Gaunt's Ring 这种一般只有三个的都可以处理前缀和后缀,再枚举中间这个值. 这个和之前写过的C. Four Segments 前缀后缀 处理方式很像. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include <queue> #include <vector> #include <io…
题意原文地址:https://blog.csdn.net/chenzhenyu123456/article/details/50574169 题意:有n个数和m次查询,每次查询区间[l, r]问满足ai ^ ai+1 ^ ... ^ aj == k的(i, j) (l <= i <= j <= r)有多少对. 思路:离线做.首先预处理前缀异或和sum[],那么ai ^ ... ^ aj == sum[i-1] ^ sum[j]. 这样对一次查询[l, r]的处理,可以从左到右扫一次,统计…
A. Ring road time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The g…