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];
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(多重集维护)的更多相关文章
- 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 ...
随机推荐
- PAT 1017 Queueing at Bank (模拟)
Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...
- 【代码学习】PYTHON 私有化
一.私有化 xx: 公有变量_x: 单前置下划线,私有化属性或方法,from somemodule import *禁止导入,类对象和子类可以访问__xx:双前置下划线,避免与子类中的属性命名冲突,无 ...
- 对象的上转型和下转型 (instanceof关键字)
1.对象的上转型,就是多态的一种写法 格式:父类名称 对象名 = new 子类名称(): Animal animal = new Cat(); 含义:右侧创建一个子类对象,把它当作父类来使用 向上转型 ...
- java编译器不匹配问题(java compiler level does not match the version of the installed java project facet)
问题:项目经常copy过来,经常会报说Java编译器不匹配 解决方法:找到项目所在的目录,在.settings子目录里面,用文本编辑器打开org.eclipse.wst.common.project. ...
- idea 快捷使用(一)条件断点的使用
调试的时候,在循环里增加条件判断,可以极大的提高效率,心情也能愉悦.以下介绍下IDEA使用条件[Condition]断点的方法 1.编写一段样例代码 /** * @author jiashubing ...
- javac 编译引用外部指定jar包进行编译和执行编译后的class文件
1.libs新建文件夹存放依赖所有jar包 2.cmd 执行: 2.1 javac -encoding UTF-8 -classpath .;C:\Users\chenquan\IdeaProject ...
- python函数1_参数,返回值和嵌套
函数 将重复的代码,封装到函数,只要使用直接找函数 函数可以增强代码的模块化和提高代码的重复利用率 函数的定义和调用 格式 def 函数名([参数,参数...]): 函数体 定义函数 import r ...
- 「CQOI2015」任务查询系统
「CQOI2015」任务查询系统 传送门 好像也是板子题??? 区间修改,单点查询,考虑差分. 然后每次查询时就直接在对应的主席树上二分即可. 参考代码: #include <cstdio> ...
- Linux - 找到正在使用的 Shell 是哪个
1. ps -p $$ 一个名为 "$$" (这是shell的特殊参数),表示当前你正在运行的 shell 实例的 PID 2. echo $0 3. echo $SHELL - ...
- 论文阅读|Focal loss
原文标题:Focal Loss for Dense Object Detection 概要 目标检测主要有两种主流框架,一级检测器(one-stage)和二级检测器(two-stage),一级检测器, ...