【CS Round #46 (Div. 1.5) E】Ultimate Orbs
【链接】链接
【题意】
【题解】
【错的次数】
【反思】
【代码】
/* */
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <cstdlib>
#include <cmath>
#include <bitset>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define ld long double
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rf(x) scnaf("%lf",&x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
#define sz(x) ((int) x.size())
#define ld long double typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //mt19937 myrand(time(0));
//int get_rand(int n){return myrand()%n + 1;}
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e6; int n,d,l[N+10],r[N+10],dp[N+10];
LL sum[N+10];
pll a[N+10];
vector <pll> v;
vector <int> ans; int dfs(int x){
if (dp[x]!=-1) return dp[x];
if (l[x]==-1 && r[x]==-1){
return dp[x] = true;
}
LL temp = a[x].fi;
if (l[x]==-1)
temp += sum[x-1];
else
temp += sum[x-1] - sum[l[x]];
if (r[x]==-1)
temp += sum[n] - sum[x];
else
temp += sum[r[x]-1] - sum[x];
if (l[x]!=-1 && temp + d >= a[l[x]].fi && dfs(l[x]))
return dp[x] = true;
if (r[x]!=-1 && temp + d >= a[r[x]].fi && dfs(r[x]))
return dp[x] = true;
return dp[x] = false;
} int main(){
ms(dp,255);
//Open();
//Close();
ri(n),ri(d);
rep1(i,1,n){
LL x;
rl(x);
a[i].fi = x,a[i].se = i;
sum[i] = sum[i-1] + x;
} rep1(i,1,n){
while (!v.empty() && v.back().fi<=a[i].fi){
v.pop_back();
}
//v.back() > a[i].fi
if (v.empty()){
l[i] = -1;
}else{
l[i] = v.back().se;
}
v.pb(a[i]);
} v.clear();
rep2(i,n,1){
while (!v.empty() && v.back().fi<=a[i].fi){
v.pop_back();
}
//v.back() > a[i].fi
if (v.empty()){
r[i] = -1;
}else{
r[i] = v.back().se;
}
v.pb(a[i]);
} rep1(i,1,n)
if (dfs(i)){
ans.pb(i);
}
rep1(i,0,sz(ans)-1){
oi(ans[i]);
if (i==sz(ans)-1)
puts("");
else
oc;
}
return 0;
}
【CS Round #46 (Div. 1.5) E】Ultimate Orbs的更多相关文章
- 【CS Round #46 (Div. 1.5) C】Set Subtraction
[链接]h在这里写链接 [题意] 一开始有n个数字,然后有一个数字X,把每个数字都减去X,又生成N个新的数字. 然后把这2*N个数字混在一起. 告诉你这2*N个数字是什么.让你复原出原来的N个数字,以 ...
- 【CS Round #46 (Div. 1.5) B】Letters Deque
[链接]h在这里写链接 [题意] 让你把一个正方形A竖直或水平翻转. 问你翻转一次能不能把A翻转成B [题解] 有说一定要恰好为1次. 并不是说A和B相同就一定不行. [错的次数] 2 [反思] 自己 ...
- 【CS Round #46 (Div. 1.5) A】Letters Deque
[链接]h在这里写链接 [题意] 在这里写题意 [题解] string类模拟 [错的次数] 0 [反思] 在这了写反思 [代码] /* */ #include <cstdio> #incl ...
- 【CS Round #36 (Div. 2 only) A】Bicycle Rental
[题目链接]:https://csacademy.com/contest/round-36/task/bicycle-rental/ [题意] 让你从n辆车中选一辆车; 每一辆车有3个属性 1.到达车 ...
- 【CS Round #37 (Div. 2 only) D】Reconstruct Graph
[Link]:https://csacademy.com/contest/round-37/task/reconstruct-graph/statement/ [Description] 给你一张图; ...
- 【CS Round #37 (Div. 2 only) B】Group Split
[Link]:https://csacademy.com/contest/round-37/task/group-split/ [Description] 让你把一个数分成两个数a.b的和; (a,b ...
- 【CS Round #37 (Div. 2 only) A】Boring Number
[Link]:https://csacademy.com/contest/round-37/task/boring-number/ [Description] 让你找离平均数最近的一个数的下标; [S ...
- 【CS Round #39 (Div. 2 only) D】Seven-segment Display
[Link]:https://csacademy.com/contest/round-39/task/seven-segment-display/ [Description] 0..9各自有一个数字, ...
- 【CS Round #39 (Div. 2 only) C】Reconstruct Sum
[Link]:https://csacademy.com/contest/round-39/task/reconstruct-sum/ [Description] 给你一个数字S; 让你找有多少对A, ...
随机推荐
- 重装python 和 yum
https://blog.csdn.net/ghostyusheng/article/details/https://segmentfault.com/q/1010000009194060/a-102 ...
- vs平台 error link:2019
需要XXX.lib或XXX.dll库.手动添加,项目->属性->配置属性->链接器->输入 然后在附件依赖项添加XXX.lib,再生成第一个无法解析的外部符号错误消失了.
- 51.cgi网站后门
运行截图: html开发: <html> <body> <form id="form" name="form" method=&q ...
- Fragment-Transaction 源码分析
概述 这篇文章的简要分析了Activity中的Transaction和add,replace等操作以及backstack的工作原理. 分析transaction源码的原因是因为我在写一个测试代码的时候 ...
- string StartsWith 方法 Https
public ActionResult Index() { string url = "Https://www.baodu.com"; ...
- Android开发之ConstraintLayout相对布局
介绍 一个 ConstraintLayout 是一个 ViewGroup 允许您以灵活的方式定位和调整小部件的方法. 注意: ConstraintLayout 作为支持库提供,您可以在API级别9(G ...
- idea 生成方法注释的快捷键
我用的15,在keymap里搜索 Fix doc comment 给他一个快捷建.参考 http://www.oschina.net/question/179541_26961
- 调用中行接口针对返回报文(xml形式)做相关处理
最近在对接中行银行接口,在获取返回报文的时候遇到一些问题,现在在这里做个总结 TIP: 在返回报文之前,要对前置机的URL请求,在这期间遇到一个坑,还是通过查看日志才发现问题 在填写转账信息的时候要求 ...
- [TypeScript] Restrict null and undefined via Non-Nullable-Types in TypeScript
This lesson introduces the --strictNullChecks compiler option and explains how non-nullable types di ...
- Maven和Ant的差别
近期做的项目中一直是在使用maven.可是要知道最早出来的构建工具是Ant,如今Ant依旧有好多人再用.于是自己就抽出来时间.学习了一下Ant的主要的使用.这样也能跟好的理解Maven提供的新特性. ...