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$ ...
随机推荐
- 五一培训 清北学堂 DAY5
今天是吴耀轩老师的讲解- 今天的主要内容:图论 如何学好图论? 学好图论的基础:必须意识到图论! 图 邻接矩阵存图: 其缺点是显而易见的:1. 空间复杂度O(n^2)不能接受:2.有重边的时候很麻烦: ...
- 安装mongodb-window10版
第一.下载mongodb 官方地址:https://www.mongodb.com/ 第二步mongodb安装 运行mongodb-win32-x86_64-2008plus-ssl-v3.4-lat ...
- 【零基础】彻底搞懂51单片机各种型号(ATMEL系列)
零.前言 初学者开始学习51单片机时往往先是一愣,说好51单片机啊,咋个型号是AT89C52,这个S52又是咋回事?上学的时候大都懵懵懂懂就这么用着,但始终没整明白,所以今天我们就彻底搞明白这些“51 ...
- MongDB的DateZone
先理解:Date本身是没有格式的,只是一个毫秒数,要显示成某种格式就一定是字符串 https://github.com/ewcmsfree/ewcms/wiki/Help-mongo-java-dri ...
- JWT加密解密
如何保证WebAPI的安全?1.JWT加密解密.token2.使用https传输协议.3.把用户所有请求的参数信息加上一个只有服务器端知道的secret,做个散列运算,然后到了服务器端,服务器端也做一 ...
- pytorch-googleNet
googleNet网络结构 输入网络: 由4个分支网络构成 第一分支: 由1x1的卷积构成 第二分支: 由1x1的卷积,3x3的卷积构成 第三分支: 由1x1的卷积, 5x5的卷积构成 第四分支: 由 ...
- Android中常见的默认实现类
* Basexxx* Defaultxxx* Simplexxx* Baicxxx
- 【JavaScript】全面解析offsetLeft、offsetTop
假设 obj 为某个 HTML 控件.obj.offsetLeft 指 obj 距离左方或上层控件的位置,整型,单位像素. obj.offsetRight 指 obj 距离右方或上层控件的位置,整型, ...
- Python - 默认参数传参陷阱
def extend_list(v, li=[]): li.append(v) return li list1 = extend_list(10) print(list1) # [10] list2 ...
- oracle数据ORA-03113:通信通道的文件到达结尾的简单处理方式
<ORA-03113:通信通道的文件结尾>错误处理: 出现的主要原因是由于归档日志空间不够了. 解决办法: --以sysdba方式登录 sqlplus / as sysdba --关闭数据 ...