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 ...
随机推荐
- 《The Practice and Theory of Bolshevism》的笔记-第114页
章节名:International Policy 页码:第114页 2017-09-30 15:11:24 Among religions, Bolshevism is to be reckoned ...
- ubuntu Qt linuxdeployqt打包
1.下载PatchELF 0.9.,https://nixos.org/patchelf.html 安装:./configure make sudo make install 2.终端命令设置设置环境 ...
- Vue 实战项目开发流程
一 基础配备 ## 一.环境搭建 #### 1.安装node - 去[官网](https://nodejs.org/zh-cn/)下载node安装包 - 傻瓜式安装 - 万一安装后终端没有node环境 ...
- php password_hash
2018-1-6 17:22:13 星期六 php 自带的密码生成方法, 如果生成密码最好使用这个, 这个是"单程"的, 没有解密函数 $a = '123456'; $b = pa ...
- interface{} 泛型编程
转自: 张晓龙 中兴开发者社区 https://mp.weixin.qq.com/s/EEUtTykcrXhcM2hJT01SoQ 序言 众所周知,Golang中不支持类似C++/Java中的标记式泛 ...
- js 正则提取img标签的src值
var r = '<img[^<>]*? src="([^<>]*?)"'; var yyy=content.match(r); alert(yyy[ ...
- 6)django-示例(fbv)
FBV(function base view),即一个url对应views.py一个函数 示例演示如下 1)FBV如何使用 2)渲染页面,并返回字典数据 3)字典数据页面如何访问 1)url.py f ...
- window Maven私服搭建——nexus
注:本文来源于 <window Maven私服搭建--nexus> Maven私服搭建--nexus 1.下载nexus https://www.sonatype.com/downlo ...
- linux之iptables常用命令
iptables详解 iptables -L 该命令会以列表的形式显示出当前使用的 iptables 规则,每一条规则前面的编号可以用来做为其它操作--例如删除操作--的参数,很有用 iptables ...
- 【python】ftp连接,主被动,调试等级
示例代码如下: #!/usr/bin/env python # -*- coding: utf-8 -*- import os from ftplib import FTP def ftp_down( ...