题意:问你有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. JavaCV更新到1.5.x版本后的依赖问题说明以及如何精简依赖包大小

    javaCV全系列文章汇总整理 javacv教程文档手册开发指南汇总篇 前言 JavaCV更新到1.5.x版本,依赖包也迎来了很大变化,体积也变大了不少.很多小伙伴们反馈,之前很多1.3.x和1.4. ...

  2. 剑指offer 面试题10:斐波那契数列

    题目描述 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0).n<=39 编程思想 知道斐波拉契数列的规律即可. 编程实现 class Solu ...

  3. Haproxy-1.8.20 编译安装:

    1 ) haproxy-1.8.20 : # 1.1 ) 安装Haproxy的依赖关系: yum install gcc gcc-c++ glibc glibc-devel pcre pcre-dev ...

  4. MySQL 使用MD5对数据进行加密

    数据库MD5加密 -- ================ 测试 MD5 加密 ============== CREATE TABLE `testmd5`( id INT(11) NOT NULL AU ...

  5. 【Linux】centos 7中,开机不执行rc.lcoal中的命令

    最近将一些需要开机启动的命令添加到了rc.local中 本想着开机就启动了,很省事 但是一次意外的重启,发现rc.local中的全部命令都没有执行 发现问题后,及时查找 参考:https://blog ...

  6. 【IMP】IMP导入表的时候,如果表存在怎么办

    在imp导入的时候,如果表存在的话,会追加数据在表中, 所以如果不想追加在表中的话,需要将想导入的表truncate掉后,在imp SQL: truncate table TEST1; imp tes ...

  7. CTFHub - Web(三)

    密码口令: 弱口令: 1.随意输入账号密码,抓包, 2.右击,"Send to Intruder",打开选项卡Intruder,点击position,椭圆框处软件已经自动为我们把要 ...

  8. F4IF_INT_TABLE_VALUE_REQUEST选择屏幕自定义F4帮助

    今天在用 F4IF_INT_TABLE_VALUE_REQUEST函数写选择屏幕的自定义帮助的时候,发现了个问题,那就是 F4IF_INT_TABLE_VALUE_REQUEST中参数value_ta ...

  9. websocket的应用---Django

    websocket的应用---Django 1.长轮询 轮询:在前端通过写js实现.缺点:有延迟.服务器压力大. 就是客户端通过一定的时间间隔以频繁请求的方式向服务器发送请求,来保持客户端和服务器端的 ...

  10. Py编程方法,尾递归优化,map函数,filter函数,reduce函数

    函数式编程 1.面向过程 把大的问题分解成流程,按照流程来编写过程 2.面向函数 面向函数编程=编程语言定义的函数+数学意义上的函数先弄出数学意义上的方程式,再用编程方法编写这个数学方程式注意面向函数 ...