#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
long long ans[1000007];
vector<pair<int,int> >add[1000007],remv[1000007];
multiset<int>s[1000007];//也可以用deque,rmq等数据结构实现,多重集自带排序
int main(){
int n,w;
cin>>n>>w;
for(int i=1;i<=n;i++){
int cnt;
cin>>cnt;
for(int j=1;j<=cnt;j++){
int x;
cin>>x;
add[j].push_back({x,i});//按列分类,起点
remv[w-cnt+j].push_back({x,i});//终点
}
if(cnt<w){
add[1].push_back({0,i});//如果把这一行移动到最右端,左端用0填充,起点为1,终点为w-cnt
remv[w-cnt].push_back({0,i});
add[cnt+1].push_back({0,i});//如果把这一行移动到最左端,右端用0填充,起点为cnt+1,终点为w
remv[w].push_back({0,i});
}
}
for(int j=1;j<=w;j++){
for(auto v:add[j]){
int idx=v.second,val=v.first;
cout<<val<<" "<<idx;
ans[j]-=s[idx].empty()?0:*s[idx].rbegin();
s[idx].insert(val);
ans[j]+=*s[idx].rbegin();
}
if(j<w){
ans[j+1]=ans[j];
for(auto v:remv[j]){//remv[j]表示这些数对第j列有贡献,对j+1列就没有贡献了,所以统计第j+1列的最大值时,需要将这些数移除。
int idx=v.second,val=v.first;
ans[j+1]-=*s[idx].rbegin();
s[idx].erase(s[idx].find(val));
ans[j+1]+=s[idx].empty()?0:*s[idx].rbegin();
}
}
}
for(int i=1;i<=w;i++)
cout<<ans[i]<<" ";
return 0;
}

Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)E(多重集维护)的更多相关文章

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

随机推荐

  1. Django框架之ORM常用字段

    一.ORM介绍 1.ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术. 简单的说,ORM是通过 ...

  2. word中如何删除一张空白表格

    百度知道:https://baijiahao.baidu.com/s?id=1631677477148377412&wfr=spider&for=pc 当word中出现如下一张空白表格 ...

  3. opencv:截取 ROI 区域

    Rect roi; roi.x = 100; roi.y = 100; roi.width = 250; roi.height = 200; // 截取 ROI 区域 // 这种方式改变 sub,原图 ...

  4. SPOJ Distinct Substrings

    给定一个字符串,求不相同子串个数.每个子串一定是某个后缀的前缀,那么原问题等价于求所有后缀之间的不相同子串个数.总数为n*(n-1)/2,再减掉height[i]的和就是答案 #include< ...

  5. cas的单点登录实现

    1.  前提条件 环境:jdk1.8.shiro1.4.0及以上版本.项目以 spring+shiro构建 工具:buji-pac4j-3.1.0-jar-with-dependencies.jar以 ...

  6. 【C语言】求1到100的和

    #include<stdio.h> int main() { ; ; ; ) { sum = sum + number; number = number + ; i = i + ; } p ...

  7. ELK日志分析系统部署

    ======================================================================================= 操作系统 IP地址 主机 ...

  8. python重要的日志模块logging

    一,logging模块简介 logging模块是Python内置的标准模块,主要用于输出运行日志,可以设置输出日志的等级.日志保存路径.日志文件回滚等:相比print,具备如下优点: 1.可以通过设置 ...

  9. Spark性能调优-基础篇

    前言 在大数据计算领域,Spark已经成为了越来越流行.越来越受欢迎的计算平台之一.Spark的功能涵盖了大数据领域的离线批处理.SQL类处理.流式/实时计算.机器学习.图计算等各种不同类型的计算操作 ...

  10. 给博客页面添加 live2d 小萝莉

    添加依赖 在页脚HTML代码的地方添加下面的代码: <script src="https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d ...