Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) E. Let Them Slide(数据结构+差分)

题意:问你有n个长度总和为n的数组 你可以移动数组 但不能移出长度为w的矩形框 问你每一列的最大值是多少?
思路:只有一次询问 我们可以考虑差分来解决 然后对于每一行数组 我们可以用数据结构维护一下区间最大值
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int N = 1e6+7;
typedef long long ll;
const ll mod = 998244353;
using namespace std;
ll a[N],ans[N],sum[N];
ll st[N][20];
void init(int len){
for(int i=1;i<=len;i++) st[i][0]=a[i];
int m=log2(len)+1;
for(int j=1;j<m;j++)
for(int i=1;i<=(len-(1<<j)+1);i++)
st[i][j]=max(st[i][j-1],st[i+(1<<(j-1))][j-1]);
}
ll ask(int l,int r){
int k=log2(r-l+1);
return max(st[l][k],st[r-(1<<k)+1][k]);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n,w; cin>>n>>w;
for(int i=1;i<=n;i++){
int l; cin>>l;
for(int j=1;j<=l;j++)
cin>>a[j];
init(l);
for(int j=1;j<=l;j++){
ll x;
if(j-(w-l)<1){
x=max(ask(1,j),0ll);
ans[j]+=x;
ans[j+1]-=x;
}else{
x=ask(j-(w-l),j);
ans[j]+=x;
ans[j+1]-=x;
}
}
for(int j=w;j>max(l,w-l);j--){
ll x;
int po=l-(w-j);
if(po+(w-l)>l){
x=max(ask(po,l),0ll);
ans[j]+=x;
ans[j+1]-=x;
}else{
x=ask(po,po+(w-l));
ans[j]+=x;
ans[j+1]-=x;
}
}
if(2*l<w){
ll x=max(0ll,ask(1,l));
ans[l+1]+=x;
ans[w-l+1]-=x;
}
}
for(int i=1;i<=w;i++){
sum[i]=sum[i-1]+ans[i];
cout<<sum[i]<<" ";
}
cout<<endl;
return 0;
}
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) E. Let Them Slide(数据结构+差分)的更多相关文章
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组 [Pro ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造 [Problem Descripti ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-E. Let Them Slide-思维+数据结构
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-E. Let Them Slide-思维+数据结构 [Problem ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) F. Bits And Pieces sosdp
F. Bits And Pieces 题面 You are given an array
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) G. Polygons 数论
G. Polygons Description You are given two integers
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) (1208F,1208G,1208H)
1208 F 大意: 给定序列$a$, 求$\text{$a_i$|$a_j$&$a_k$}(i<j<k)$的最大值 枚举$i$, 从高位到低位贪心, 那么问题就转化为给定$x$ ...
- RMQ+差分处理(Let Them Slide)Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
题意:https://codeforc.es/contest/1208/problem/E 现有n行w列的墙,每行有一排连续方块,一排方块可以左右连续滑动,且每个方块都有一个价值,第i 列的价值定义为 ...
- 线段树维护最后一个0的位置(Restore Permutation)Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
题意:https://codeforc.es/contest/1208/problem/D 给你长度为n的序列,s[i]的值为p[1]到p[i-1]中比p[i]小的数的和,让你求出p序列. 思路: 首 ...
- Codeforces Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
传送门 A. XORinacci 手玩三四项发现序列就是 $a,b,a\ xor\ b,a,b,...$,直接输出即可 #include<iostream> #include<cst ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)E(多重集维护)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long ans[1000007]; ...
随机推荐
- NTP服务解析
······[NTP服务概述] NTP(Network Time Protocol)服务主要用于同步服务器时间. nptd 可以运行在多种模式下,包括对称的 主动.被动(active/passive) ...
- Linux下Hadoop2.7.3集群环境的搭建
Linux下Hadoop2.7.3集群环境的搭建 本文旨在提供最基本的,可以用于在生产环境进行Hadoop.HDFS分布式环境的搭建,对自己是个总结和整理,也能方便新人学习使用. 基础环境 JDK的安 ...
- leetcode 357. 计算各个位数不同的数字个数(DFS,回溯,数学)
题目链接 357. 计算各个位数不同的数字个数 题意: 给定一个非负整数 n,计算各位数字都不同的数字 x 的个数,其中 0 ≤ x < 10n . 示例: 输入: 2 输出: 91 解释: 答 ...
- LeetCode108.有序数组转二叉搜索树
题目 1 class Solution { 2 public: 3 TreeNode* sortedArrayToBST(vector<int>& nums) { 4 if(num ...
- REUSE_ALV_FIELDCATALOG_MERGE函数
今天使用REUSE_ALV_FIELDCATALOG_MERGE函数,就是获取不到fieldcat, 搞了半天才发现,原来参数要全部大写才行!!小写字符就是获取不到,唉,悲哀...
- 处理K8S PVC删除后pod报错
报错如下 Jun 19 17:15:18 node1 kubelet[1722]: E0619 17:15:18.381558 1722 desired_state_of_world_populato ...
- 获取Java线程转储的常用方法
1. 线程转储简介 线程转储(Thread Dump)就是JVM中所有线程状态信息的一次快照. 线程转储一般使用文本格式, 可以将其保存到文本文件中, 然后人工查看和分析, 或者使用工具/API自动分 ...
- CUDA 介绍
1. 介绍 1.1 GPU vs. CPU GPU 使用更多的晶体管进行数据处理,而不是数据缓存和流控制,因此可以提供高度的并行计算. GPU 可以通过计算来隐藏内存访问延迟,而不是依赖于大量的数据缓 ...
- Linux 三剑客之 grep 使用详解
Linux 最重要的三个命令在业界被称为三剑客,它们是:awk.sed.grep.sed 已经在上篇中讲过,本文要讲的是 grep 命令. 我们在使用 Linux 系统中,grep 命令的使用尤为频繁 ...
- day132:2RenMJ:MJ需求文档&MJ游戏流程&Egret白鹭引擎安装&TypeScript简要介绍
目录 1.麻将产品需求文档 2.麻将游戏流程 3.Egret白鹭引擎 4.TypeScript简要了解 5.TypeScript快速入门 1.麻将产品需求文档 1.麻将术语 1.名词术语 牌⼦: 序数 ...