我是靠谱客的博主 勤劳狗,这篇文章主要介绍Codeforces Global Round 7 E. Bombs(线段树+思维),现在分享给大家,希望可以做个参考。

题目链接
在这里插入图片描述
在这里插入图片描述
思路:思维量很大的题,不看题解完全做不来。。。首先要明白一件事答案肯定是递减的,所以想减少复杂度就可以通过逐渐枚举答案ans,剩下的就是判断ans能否作为答案。只有区间内的某一个位置大于等于ans的数减去后面的炸弹数量大于0那么ans就可行。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=3e5+1; int a[maxn],b[maxn],pos[maxn]; struct node{ int l,r,lazy,sum; }tree[maxn<<2]; void pushup(int x) { tree[x].sum=max(tree[x<<1].sum,tree[x<<1|1].sum); } void pushdown(int x) { if(tree[x].lazy) { tree[x<<1].sum+=tree[x].lazy; tree[x<<1|1].sum+=tree[x].lazy; tree[x<<1].lazy+=tree[x].lazy; tree[x<<1|1].lazy+=tree[x].lazy; tree[x].lazy=0; } } void build(int x,int l,int r) { tree[x].l=l;tree[x].r=r; if(l==r){ tree[x].lazy=tree[x].sum=0;return ; } int mid=(l+r)>>1; build(x<<1,l,mid); build(x<<1|1,mid+1,r); pushup(x); } void update(int x,int l,int r,int v) { if(l<=tree[x].l&&tree[x].r<=r){ tree[x].sum+=v; tree[x].lazy+=v; return ; } pushdown(x); int mid=(tree[x].l+tree[x].r)>>1; if(l<=mid) update(x<<1,l,r,v); if(mid<r) update(x<<1|1,l,r,v); pushup(x); } int main() { int n; scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&a[i]),pos[a[i]]=i; for(int i=1;i<=n;++i) scanf("%d",&b[i]); build(1,1,n); int now=n; printf("%d ",n); update(1,1,pos[n],1); for(int i=1;i<n;++i) { update(1,1,b[i],-1); while(tree[1].sum<=0) now--,update(1,1,pos[now],1); printf("%d ",now); } }

最后

以上就是勤劳狗最近收集整理的关于Codeforces Global Round 7 E. Bombs(线段树+思维)的全部内容,更多相关Codeforces内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(78)

评论列表共有 0 条评论

立即
投稿
返回
顶部