Educational Codeforces Round 48 (Rated for Div. 2) - 赛后补题

C. Vasya And The Mushrooms

题解:拿笔画他的行走路线,你会发现可以前缀和预处理一些东西出来。

const int N = 300005;

int n;
ll a[N], b[N], dp[2][N], sp[2][N], sum[N];

int get_a() {

    dp[0][0] = 0;
    for (int i = 1; i < n; ++i) {
        dp[0][i] = dp[0][i - 1] + 1ll * i * a[i];
    }

    int t = n;
    dp[1][n - 1] = dp[0][n - 1] + 1ll * t * b[n - 1];

    for (int i = n - 2; ~i; --i) {
        t++;
        dp[1][i] = dp[1][i + 1] + 1ll * t * b[i];
    }
}

int get_b() {

    sp[1][0] = b[1];
    for (int i = 1; i < n; ++i) sp[1][i] = sp[1][i - 1] + 1ll * (i + 1) * b[i];

    int t = n + 1;
    sp[0][n - 1] = sp[1][n - 1] + 1ll * t * a[n - 1];

    for (int i = n - 2; ~i; --i) {
        t++;
        sp[0][i] = sp[0][i + 1] + 1ll * t * a[i];
    }
}

void Inite() {
    for (int i = n - 1; ~i; --i) sum[i] = sum[i + 1] + a[i] + b[i];
}

void solve() {
    ll ans = max(dp[1][0], sp[0][1]);
    int last = 0;
    ll tp = 0;
    for (int i = 0; i < n; ++i) {
        if(!last) {
            tp += 1ll * 2 * i * a[i] + 1ll * (2 * i + 1) * b[i];
            if(i + 1 != n) ans = max(ans, tp + 1ll * i * sum[i + 1] + sp[0][i + 1] - sp[1][i]);
        }
        else {
            tp += 1ll * 2 * i * b[i] + 1ll * (2 * i + 1) * a[i];
            if(i + 1 != n) ans = max(ans, tp + 1ll * (i + 1) * sum[i + 1] + dp[1][i + 1] - dp[0][i]);
        }
        last ^= 1;
    }
    printf("%I64d\n", max(ans, tp));
}

D. Vasya And The Matrix

题解:可以这么构造,除了第一行,第一列填上以外,其它的行和列都填0,所以主要是算map[1][1]改填几,或者填最后一行和最后一列。

 ans[n][m] = b[m] ^ (x ^ a[n]);

原文地址:https://www.cnblogs.com/zgglj-com/p/9419553.html

时间: 2024-10-07 17:10:16

Educational Codeforces Round 48 (Rated for Div. 2) - 赛后补题的相关文章

Educational Codeforces Round 48 (Rated for Div. 2)

http://codeforces.com/contest/1016 A. 没想到这个也会TLE,太粗心了 B. 暴力就好了,多情况讨论又出错... 思路跟我一样的解法   为什么我做了那么多讨论,原因是没注意这个: 标记 最后一个字符,同时注意 l+m-3. 特殊情况就 vis 0000011111111111112 s1  abaccabaacabacabacca      红色的地方是 l 和 r ,为了防止在 l 处计数多了就得 l + m - 3 s2  abacca we[s+m-1

Educational Codeforces Round 48 (Rated for Div. 2) B Segment Occurrences

翻译 给你一个字符串\(s\)和另一个字符串\(t\),然后给你\(q\)个区间,问\(s\)在这些区间里的子串有多少个与\(t\)相同. 思路 一道要细心的模拟题,使用\(STL string\),暴力,前缀和,\(Hash\),\(Kmp\)都能做出来,然后我来介绍一下用 \(vector\)的做法. 首先预处理\(s\),从头到位找到每一个长度是字符串t的长度\(m\)的字符串,如果其与\(t\)相等,那么就往vector中压入\(1\),否则压入\(0\),这样,我们就找到每个编号的字符

Educational Codeforces Round 48 (Rated for Div. 2)G. Appropriate Team

题意:求满足条件的(i,j)对数:\(gcd(v,a_i)=x,lcm(v,a_j)=y\) 题解:\(x|a_i,a_j|y\),\(x|y\),考虑质因子p,假设a_i中p次数为a,x中次数为b,y为c,\(a_j\)为d;a>=b,c>=d. 假设a>b,c>d,那么由于\(gcd(v,a_i)=x\),v中p的次数为b,由于\(lcm(v,a_j)=y\),那么\(max(b,d)==c\),又c>d,所以b=c<a和x|y矛盾,所以此时ij不满足条件 其他情况

Educational Codeforces Round 59 (Rated for Div. 2) (前四题)

A. Digits Sequence Dividing(英文速读) 练习英语速读的题,我还上来昏迷一次....只要长度大于2那么一定可以等于2那么前面大于后面就行其他no 大于2的时候分成前面1个剩下后面一定是对的因为按照数字大小 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n;

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) A - There Are Two Types Of Burgers

原文链接:https://www.cnblogs.com/xwl3109377858/p/11404050.html Educational Codeforces Round 71 (Rated for Div. 2) A - There Are Two Types Of Burgers There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburg

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 79 (Rated for Div. 2)

A. New Year Garland (CF 1279 A) 题目大意 给定红绿蓝三种颜色灯的数量,问能否摆成一排,使得相邻颜色不相同. 解题思路 植树问题.考虑数量最多为\(n\)的颜色的灯俩俩不相邻,那么其他颜色的灯的数量和要大于\(n-1\)即可,大过\(n-1\)的灯直接插到里面就好了. 神奇的代码 #include <bits/stdc++.h> #define MIN(a,b) ((((a)<(b)?(a):(b)))) #define MAX(a,b) ((((a)>