题意:问你有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. PHP 获取重复数组中 第二多的元素

    $target = ["重复项目", "repeat", "repeat", "重复", "重复项目" ...

  2. LinkedList 的 API 与数据结构

    LinkedList 是 List 接口和 Deque 接口的双向链表实现,它所有的 API 调用都是基于对双向链表的操作.本文将介绍 LinkedList 的数据结构和分析 API 中的算法. 数据 ...

  3. PAT甲级练习 1087 All Roads Lead to Rome (30分) 字符串hash + dijkstra

    题目分析: 这题我在写的时候在PTA提交能过但是在牛客网就WA了一个点,先写一下思路留个坑 这题的简单来说就是需要找一条最短路->最开心->点最少(平均幸福指数自然就高了),由于本题给出的 ...

  4. 如果数据库上的row格式是mixed或者mixed的格式,如何对比两台数据库服务器上的数据是否一致呢

    如果数据库上的row格式是mixed或者mixed的格式,如何对比两台数据库服务器上的数据是否一致呢

  5. 【ORA】ORA-01078和LRM-00109 解决方法

    今天切换到asm实例的时候,发现是一个空实例,尝试启动实例,结果报错ORA-01078和LRM-00109 SQL> startupORA-01078: failure in processin ...

  6. SDUST数据结构 - chap9 排序

    判断题: 选择题: 编程题: 7-1 排序: 输入样例: 11 4 981 10 -17 0 -20 29 50 8 43 -5 输出样例: -20 -17 -5 0 4 8 10 29 43 50 ...

  7. WCNSS_qcom_cfg.ini WIFI配置文件参数详细解析

    STA相关的一般配置 参数 含义 最小值 最大值 默认值 gNeighborLookupThreshold 1 触发roam scan发生的条件在WCNSS_qcom_cfg.ini文件中gNeigh ...

  8. Linq.Expressions扩展ExpressionExtension

    手上有一个以前项目用到的.NET工具类封装的DLL. 正好又想试一下动态LAMBDA表达式,用.NET Reflector看一下源码. public static class ExpressionEx ...

  9. jQuery 点击当前展开其他隐藏

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...

  10. vue.esm.js?efeb:628 [Vue warn]: Invalid prop: type check failed for prop "defaultActive". Expected String with value "0", got Number with value 0.

    vue.esm.js?efeb:628 [Vue warn]: Invalid prop: type check failed for prop "defaultActive". ...