题意:问你有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(数据结构+差分)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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

  5. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) G. Polygons 数论

    G. Polygons Description You are given two integers

  6. 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$ ...

  7. 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 列的价值定义为 ...

  8. 线段树维护最后一个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序列. 思路: 首 ...

  9. 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 ...

  10. 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]; ...

随机推荐

  1. linux脚本错误: line *: [: missing `]',linux编写shell脚本时的注意点

    转载:https://www.cnblogs.com/bovenson/p/4548079.html 关于shell的一些注意点,粘贴自拉钩教育精选评论:测试开发核心技术 46 讲-->第6讲 ...

  2. 利用dotnet-dump分析docker容器内存泄露

    目录 一 运行官方示例 1,Clone代码并编译 2,创建Dockerfile构建镜像 3,启动容器 二 生成dump转储文件 1,制造问题 2,创建dump文件 三 分析dump文件 1,创建一个用 ...

  3. laravel邮件发送

    laravel邮件发送 使用邮件发送类Mail 文本 静态方法 raw() 富文本 静态方法 send() 注:使用邮件发送必须有邮件账号,需要开启smtp协议,现在主流服务器都支持,smtp默认端口 ...

  4. 70.LeetCode爬楼梯

    爬楼梯 点击标题可跳转到官网进行查看 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数. 示例 1: ...

  5. docker 安装linux centos 环境

    如何在centos7中使用docker创建一个支持ssh连接的容器 以下内容已有现成的,这里借用下这哥们的帖子https://www.cnblogs.com/caidingyu/p/10642158. ...

  6. 【Docker】Docker启动停止重启 Redirecting to /bin/systemctl start docker.service

    [root@liuawen local]# docker -v Docker version 1.13.1, build cccb291/1.13.1 [root@liuawen local]# 启动 ...

  7. 【CRS】vipca最后一步执行报错CRS-0215

    当我们在安装Clusterware 的时候, 需要在第二节点上vipca , 配置到最后安装的时候, 安装到 75% 左右,报错:     CRS-0215 : Could not start res ...

  8. JDBC入门程序总结

    JDBC本质 只是一个接口 每个数据库的规范 就是实现类的接口 其实是官方 定义的一套操作所有关系型数据库的规则,就是接口,各个数据库厂商去实现这套接口,提供数据库驱动jar包, 我们可以使用这套接口 ...

  9. leetcode 730. 统计不同回文子序列(区间dp,字符串)

    题目链接 https://leetcode-cn.com/problems/count-different-palindromic-subsequences/ 题意 给定一个字符串,判断这个字符串中所 ...

  10. [Usaco2015 dec]Breed Counting

    原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=4397 用线段树维护区间和即可.时间复杂度\(O((N+Q)logN)\). #includ ...