codeforces 1037
题解:
E-trips
哎哎哎好傻逼啊
没有想到算不能的一直在想怎么算能的
太傻逼了
其实很简单
我们只需要对好友<=k的首先dfs一下给他连接着的朋友-1
然后如果小于了就递归下去
这个正确性是比较好想的
最后剩下的每个都是好友>=k个的并且都是这之间的
我们把他们都选了就可以了
这样不支持连边但是可以删边,所以倒着做就可以了
大水题
会发现要求的长度为k,2k-1,3k-2,4k-3的最大值
单调栈维护前驱后继
然后前缀和优化一下求答案就完了
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rint register int
#define IL inline
#define rep(i,h,t) for (rint i=h;i<=t;i++)
#define dep(i,t,h) for (rint i=t;i>=h;i--)
#define mid ((h+t)>>1)
const int mo=1e9+;
const int N=2e6;
ll a[N],sum[N],ans;
int nxt[N],pre[N];
struct re{
int a,b;
}ve[N];
int main()
{
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
ios::sync_with_stdio(false);
int n,m;
cin>>n>>m;
rep(i,,n) cin>>a[i];
int k=;
rep(i,,n)
{
while (m*k-k+<=i) k++;
sum[i]=(sum[i-]+k-)%mo;
}
int t=;
rep(i,,n)
{
while (t&&ve[t].a<a[i])
{
nxt[ve[t].b]=i-;
t--;
}
t++; ve[t].a=a[i]; ve[t].b=i;
}
while (t)
{
nxt[ve[t].b]=n;
t--;
}
dep(i,n,)
{
while (t&&ve[t].a<=a[i])
{
pre[ve[t].b]=i+;
t--;
}
t++; ve[t].a=a[i]; ve[t].b=i;
}
while (t)
{
pre[ve[t].b]=;
t--;
}
rep(i,,n)
{
ans+=(sum[nxt[i]-pre[i]+]-sum[nxt[i]-i+-]-sum[i-pre[i]+-])*a[i];
ans%=mo;
}
cout<<(ans+mo)%mo<<endl;
return ;
}
codeforces 1037的更多相关文章
- Codeforces 1037 H. Security
\(>Codeforces \space 1037\ H. Security<\) 题目大意 : 有一个串 \(S\) ,\(q\) 组询问,每一次给出一个询问串 \(T\) 和一个区间 ...
- Manthan, Codefest 18 (Div 1 + Div 2) (A~E)
目录 Codeforces 1037 A.Packets B.Reach Median C.Equalize D.Valid BFS E.Trips(正难则反) Codeforces 1037 比赛链 ...
- CF 1037 D. Valid BFS?
D. Valid BFS? http://codeforces.com/contest/1037/problem/D 题意: 给一个序列,一棵树,判断能否bfs这棵树,得到这个序列. 分析: 将每个点 ...
- [Codeforces 1037E] Trip
[题目链接] http://codeforces.com/problemset/problem/1037/E [算法] 首先离线 , 将问题倒过来考虑 , 转化为 : 每次删除一条边 , 此时最多有多 ...
- [Codeforces 1037D] Valid BFS?
[题目链接] http://codeforces.com/problemset/problem/1037/D [算法] 首先求出每个点的父节点 , 每棵子树的大小 然后判断BFS序是否合法即可 时间复 ...
- [codeforces 1037D] Valid BFS? 解题报告(验证bfs序,思维题)
题目链接:http://codeforces.com/problemset/problem/1037/D 题目大意: 给出一棵树,询问一个序列是否可能为这棵树从节点1开始遍历的bfs序 题解: 对于每 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
随机推荐
- requests库入门10-超时,错误与异常
在实际发布到生产上的接口测试代码,都会加上超时的设置,当服务器超过一定时间没有响应,会报出超时异常.因为requests会自动等待响应.如果不加上超时的设置,可能脚本会一直卡在那里.. 超时设置在请求 ...
- 安装mongo php拓展
下载php_mongo.dll文件 下载地址:https://s3.amazonaws.com/drivers.mongodb.org/php/index.html(注意对应版本及是否线程安全)需要注 ...
- js模板引擎-art-template常用总结(转)
原文:https://www.cnblogs.com/shiyou00/p/6841801.html art-template javascript 模板引擎,官网:https://github.co ...
- Java序列化Serializable
1.什么是序列化和反序列化 Serialization(序列化)是一种将对象以一连串的字节描述的过程:deserialization(反序列化)是一种将这些字节重建成一个对象的过程. 2.什么情况下需 ...
- java 批量插入 Oracle
sql = "INSERT INTO LOG_FILENAME(ID,FILENAME,CREATETIME) VALUES(2,?,sysdate)"; public void ...
- 将C注册到lua环境中使用
注册到lua的方式有两种,一种是lua解释器,如果支持动态链接,使用动态链接机制,将函数接口编译成动态链接库,然后将动态链接库放到lua的C路径(LUA_CPATH)中,然后在lua文件中直接使用 r ...
- pointer & iterator
pointer: address, use operator(*) to get/set the value 1) support operator(+,-), move to next posito ...
- 一个简单的Loading控件
实现效果如下: 使用方法: 在layout文件中添加以下代码: <com.example.jack.ui.widget.RingLoading android:layout_width=&quo ...
- wx :swipertab切换
<view> <view class="navbar"> <block wx:for="{{body}}" wx:key=&quo ...
- Confluence 6 修改 Home 目录的位置
当 Confluence 第一次启动的时候,Confluence 将会读取 confluence-init.properties 文件并从这个文件中确定如何去查找 Home 目录. 希望修改 home ...