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 列的价值定义为这列的方块的价值和。求1到w列中每列的最大价值。注:如果一个位置没有方块,那么这个位置的价值为0
思路:
直接RMQ+差分数组即可。
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
//******************
int abss(int a);
int lowbit(int n);
int Del_bit_1(int n);
int maxx(int a,int b);
int minn(int a,int b);
double fabss(double a);
void swapp(int &a,int &b);
clock_t __STRAT,__END;
double __TOTALTIME;
void _MS(){__STRAT=clock();}
void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
//***********************
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const double E=2.718281828;
const double PI=acos(-1.0);
//const ll INF=(1LL<<60);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; int dp[N][],arr[N]; void rmq_init(int n)
{
for(int i=;i<=n;i++)
dp[i][]=arr[i];
for(int j=;(<<j)<=n;j++)
for(int i=;i+(<<j)-<=n;i++)
dp[i][j]=max(dp[i][j-],dp[i+(<<j-)][j-]);
}
int rmq(int l,int r)
{
int k=log2(r-l+);
return max(dp[l][k],dp[r-(<<k)+][k]);
}
ll ans[N];
ll DP[N]; void solve(int len)
{
int n;
sc("%d",&n);
for(int i=;i<=n;++i)
sc("%d",&arr[i]);
rmq_init(n);
int L,R;
int max_=max(,rmq(,n));
if(len>=*n+)
DP[n+]+=max_,DP[len+-n]-=max_;
for(int i=;i<=n;++i)
{
L=max(,n-(len-i));
R=min(n,i);
if(n-(len-i)<||i>n)
ans[i]+=max(,rmq(L,R));
else
ans[i]+=rmq(L,R);
}
int LL=max(n+,len-n+);
for(int i=LL;i<=len;++i)
{
L=max(,n-(len-i));
R=min(n,i);
if(n-(len-i)<||i>n)
ans[i]+=max(,rmq(L,R));
else
ans[i]+=rmq(L,R);
}
} void PR(ll _[],int n)
{
for(int i=;i<=n;++i)
pr("%lld ",_[i]);
pr("\n");
}
int main()
{
int n,m;
sc("%d%d",&n,&m);
for(int i=;i<=n;++i)solve(m);//,PR(DP,m);
for(int i=;i<=m;++i)
{
DP[i]+=DP[i-];
pr("%lld ",ans[i]+DP[i]);
}
// PR(DP,m);
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}
RMQ+差分处理(Let Them Slide)Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)的更多相关文章
- 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) E. Let Them Slide(数据结构+差分)
题意:问你有n个长度总和为n的数组 你可以移动数组 但不能移出长度为w的矩形框 问你每一列的最大值是多少? 思路:只有一次询问 我们可以考虑差分来解决 然后对于每一行数组 我们可以用数据结构维护一下 ...
- 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 ...
- 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]; ...
- 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$ ...
随机推荐
- 一个轻量级的模态组件,“礼貌地”要求您的用户停止使用过时的IE浏览器
插件github地址:https://github.com/panteng/ie-blocker 我们在做项目时,会考虑到浏览器的兼容问题,当然做,全浏览器都支持的项目我还没经历过,也不想经历,目前做 ...
- C#操作 Access 2013(.accdb)的方法
使用的Microsoft.Jet.OLEDB.4.0,的方法并不能连接最新的Access 存储文件,而且Microsoft.Jet.OLEDB.4.0不能使用x64的方式生成,而且使用这个数据库引擎效 ...
- Hadoop配置多个HDFS入口
为了验证存在不同的hdfs之间的hive的互操作(归根结底还是为了解决BUG) 需要在两个不同的hadoop集群的HDFS 能够在Hiveserver2上进行路由转发绕过一些坑. 就需要将某hdfs ...
- 解决Powershell中不能运行脚本问题
问题: powershell中不能执行脚本,提示‘because running scripts is disabled on this system’ 原因: powershell中默认的execu ...
- Java中<? extends T>和<? super T>的理解
? 通配符类型 - <? extends T> 表示类型的上界,表示参数化类型的可能是T 或是 T的子类; <? super T> 表示类型下界(Java Core中叫超类型限 ...
- 如何在uboot下列出使用的设备树信息?
答: 使用fdt命令 1. fdt addr <fdt addr> (将设备树加载到fdt addr指定的位置,如tftpboot 0x80000000 my.dtb,那么fdt add ...
- JVM学习笔记之认识JDK(一)
1. HotSpot VM: HotSpot VM是Sun JDK和OpenJDK中所带的虚拟机,也是目前使用范围最广的Java虚拟机. 什么是HotSpot VM & 深入理解Java虚拟机 ...
- idea 双击选中一个变量,及高亮显示相同的变量
其实idea有这个功能,只是没有背景颜色,在这里有可能是编辑区的背景颜色和选中变量的背景颜色一样, 所有我们只需要调一下背景颜色就可以了 版本:ideaIU-2018.1.5 1. 到这里就结束啦..
- python报错No module named 'pylab'
pip instal matplotlib
- 鸟哥私房菜基础篇:磁碟配额(Quota)与进阶文件系统管理习题
猫宁!!! 参考:http://cn.linux.vbird.org/linux_basic/0420quota.php 1-在前一章的第一个大量新增帐号范例中, 如果我想要让每个用户均具有 soft ...