D. Beautiful Array

题意

给你一个长度为 \(n\) 的序列。你可以选择至多一个子段,将该子段所有数乘上给定常数 \(x\) 。求操作后最大的最大子段和。

题解

考虑最大子段和的子段一共有三类点:1. 左边没有 \(\times x\) 的点 ; 2. 中间 \(\times x\) 的点; 3. 右边没有 \(\times x\) 的点。

考虑 dp 。设 \(f[i][1/2/3]\) 表示前 \(i\) 个数,第 \(i\) 个数作为第 1/2/3 类点的最大子段和。转移显然。

code

#include<cstdio>
#include<algorithm>
using namespace std;
const int N=3e5+5;
inline int gi()
{
char c; int x=0,f=1;
for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+c-'0';
return x*f;
}
int a[N],n,x;
long long f[N][5],ans=0;
int main()
{
n=gi(),x=gi();
for(int i=1;i<=n;++i) a[i]=gi();
for(int i=1;i<=n;++i)
{
f[i][1]=max(0ll,f[i-1][1])+a[i];
f[i][2]=max(0ll,max(f[i-1][1],f[i-1][2]))+1ll*a[i]*x;
f[i][3]=max(f[i-1][2],f[i-1][3])+a[i];
ans=max(ans,max(f[i][1],max(f[i][2],f[i][3])));
}
printf("%I64d",ans);
}

E. Guess the Root

题意

交互题。有一个 \(k(k\le 10)\) 次多项式 \(f(x)\) ,你可以进行不超过 \(50\) 次询问,每次询问给出 \(x\) ,返回 \(f(x)\) 。求 \(x_0\) 使得 \(f(x_0) \equiv 0 \mod (10^6 + 3)\) 。

题解

以下设 \(m=10^6+3\) 。

插值傻逼题。询问 \(k+1\) 次,然后枚举零点插值判断即可。

直接插值是 \(O(m k^2 \log m)\) 的。众所周知,当 \(x\) 取 \(1\sim n\) 可以通过预处理阶乘使插值复杂度降到 \(O(n)\) 。

当然由于本题 \(k\le 10\),我们甚至可以直接暴力打表分母。复杂度 \(O(mk)\) 。

code

#include<cstdio>
const int N=25,Mod=1e6+3;
const int n=11;
int y[N],k,inv[Mod+2];
int fm[]={404910,950915,220896,410947,30845,962989,30845,410947,220896,950915,404910};
inline int po(int x, int y)
{
int r=1;
while(y)
{
if(y&1) r=1ll*r*x%Mod;
x=1ll*x*x%Mod, y>>=1;
}
return r;
}
int judge(int k)
{
int ans=0,base=1;
for(int i=1;i<=n;++i) if(k!=i) base=1ll*base*(k-i)%Mod;
if(1<=k&&k<=11) return (1ll*base*fm[k-1]%Mod*y[k]%Mod+Mod)%Mod;
base=(base+Mod)%Mod;
for(int i=1;i<=n;++i)
ans=(ans+1ll*base*inv[(k-i+Mod)%Mod]%Mod*fm[i-1]%Mod*y[i]%Mod)%Mod;
return ans;
}
int main()
{
for(int i=1;i<=n;++i)
{
printf("? %d\n",i);
fflush(stdout);
scanf("%d",&y[i]);
}
inv[0]=inv[1]=1;
for(int i=2;i<Mod;++i) inv[i]=1ll*(Mod-Mod/i)*inv[Mod%i]%Mod;
for(int k=0;k<Mod;++k)
if(!judge(k))
{
printf("! %d\n",k);
fflush(stdout);
return 0;
}
printf("! -1\n");
fflush(stdout);
}

Educational Codeforces Round 63 选做的更多相关文章

  1. Educational Codeforces Round 64 选做

    感觉这场比赛题目质量挺高(A 全场最佳),难度也不小.虽然 unr 后就懒得打了. A. Inscribed Figures 题意 给你若干个图形,每个图形为三角形.圆形或正方形,第 \(i\) 个图 ...

  2. Educational Codeforces Round 65 选做

    好久没更博客了,随便水一篇 E. Range Deleting 题意 给你一个长度为 \(n\) 的序列 \(a_1,a_2,\dots a_n\) ,定义 \(f(l,r)\) 为删除 \(l\le ...

  3. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  4. [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)

    Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...

  5. Educational Codeforces Round 63部分题解

    Educational Codeforces Round 63 A 题目大意就不写了. 挺简单的,若果字符本来就单调不降,那么就不需要修改 否则找到第一次下降的位置和前面的换就好了. #include ...

  6. Educational Codeforces Round 63 Div. 2

    A:找到两个相邻字符使后者小于前者即可. #include<bits/stdc++.h> using namespace std; #define ll long long #define ...

  7. Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array 分类讨论连续递推dp

    题意:给出一个 数列 和一个x 可以对数列一个连续的部分 每个数乘以x  问该序列可以达到的最大连续序列和是多少 思路: 不是所有区间题目都是线段树!!!!!! 这题其实是一个很简单的dp 使用的是分 ...

  8. Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array(动态规划.递推)

    传送门 题意: 给你一个包含 n 个元素的序列 a[]: 定义序列 a[] 的 beauty 为序列 a[] 的连续区间的加和最大值,如果全为负数,则 beauty = 0: 例如: a[] = {1 ...

  9. Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array (简单DP)

    题目:https://codeforces.com/contest/1155/problem/D 题意:给你n,x,一个n个数的序列,你可以选择一段区间,区间的数都乘以x,然后求出最大字段和 思路: ...

随机推荐

  1. broadcom sdk command

    1.查看端口link状态 BCM.0>ps 2.查看vlan BCM.0>vlan show 3.查看pvlan BCM.0>pvlan show 4.CPU发包 BCM.0> ...

  2. icos下配置snake test

    Topo: # $language = "Python" # $interface = "1.0"# Author:Bing Song# Date:6/21/2 ...

  3. 一 Spring概述

    知识点概要: 1 SpringIOC入门(XML).Spring的Bean管理.Spring属性注入 2 SpringIOC注解方式.Spring的AOP开发(XML) 3 Spring的AOP注解开 ...

  4. c++11的记录

    decltype()类型指示符 设定一个返回值是int的函数f(),通过使用 decltype(f()) sum = x; 此时decltype()接受一个从f()返回的int型的值,并将sum设置为 ...

  5. idea 构建maven web项目

    参考:https://blog.csdn.net/czc9309/article/details/80304074 idea Tomcat 部署 war和war exploded的区别 参考:  ht ...

  6. postman 使用post方式提交参数值

    参考:https://www.cnblogs.com/haoxuanchen2014/p/7771459.html

  7. Python基础-4 运算符

    运算符 运算符:以1 + 2为例,1和2被称为操作数,"+" 称为运算符. Python语言支持以下类型的运算符: 算术运算符 比较(关系)运算符 赋值运算符 逻辑运算符 位运算符 ...

  8. Atcoder Beginning Contest 134E(二分查找(upper_bound),思维)

    #include<bits/stdc++.h>using namespace std;int a[100007],f[100007],ans,n;int main(){ cin>&g ...

  9. js获取一个页面 是从哪个页面过来的

    document.referrer 获取来源页面的url console.log(document.referrer) if(document.referrer=="http://127.0 ...

  10. :before 与 :after

    http://justcoding.iteye.com/blog/2032627  网址