Codeforces Round #426 (Div. 2) B The Festive Evening
来源:互联网 发布:php代码模板 编辑:程序博客网 时间:2024/06/06 04:09
对于每种字符,第一次出现的位置为起点,最后一次出现的位置为终点,构成一条线段。每种字符一条线段,求线段重叠,最多有多少个线段重叠,然后和k比较。线段树区间更新,然后查询最值
#include<bits/stdc++.h>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define mid (l+r)>>1const int MAXN = 1e6+10;int n,k;pair<int,int> ps[26];int sum[MAXN<<2];int col[MAXN<<2];void init(){ for(int i = 0; i < 26; ++i) { ps[i].first = MAXN; ps[i].second = 0; }}void pushdown(int rt){ if(col[rt]) { sum[rt<<1]+=col[rt]; sum[rt<<1|1]+=col[rt]; col[rt<<1]+=col[rt]; col[rt<<1|1]+=col[rt]; col[rt]=0; }}void pushup(int rt){ sum[rt]=max(sum[rt<<1],sum[rt<<1|1]);}void update(int L, int R, int c, int l, int r, int rt){ if(L <= l && r <= R) { col[rt] += c; sum[rt] += c; return; } pushdown(rt); int m=mid; if(L<=m) update(L,R,c,lson); if(R>m) update(L,R,c,rson); pushup(rt);}int query(int L,int R,int l,int r,int rt){ if(L<=l&&r<=R) { return sum[rt]; } pushdown(rt); int m=mid, ret=0; if(L<=m) ret=max(ret,query(L,R,lson)); if(R>m) ret=max(ret,query(L,R,rson)); return ret;}int main(){ init(); char ch; int index; scanf("%d %d",&n,&k); getchar(); for(int i = 1; i <= n; ++i) { ch = getchar(); index = ch - 'A'; if(i < ps[index].first) ps[index].first = i; if(i > ps[index].second) ps[index].second = i; } for(int i = 0; i < 26; ++i) { if(ps[i].first != MAXN) { update(ps[i].first,ps[i].second,1,1,n,1); } } int res = query(1,n,1,n,1); if(res > k) printf("YES\n"); else printf("NO\n"); return 0;}
阅读全文
0 0
- B. The Festive Evening(Codeforces Round #426 (Div. 2) B)
- Codeforces Round #426 (Div. 2) B. The Festive Evening
- Codeforces Round #426 (Div. 2)-B. The Festive Evening
- Codeforces Round #426 (Div. 2) B The Festive Evening
- Codeforces Round #426 (Div. 2) B. The Festive Evening
- Codeforces Round #426 (Div. 2) B. The Festive Evening
- Codeforces Round #426 (Div. 2)B. The Festive Evening
- Codeforces Round #426 (Div. 2) B.The Festive Evening+C.The Meaningless Game
- Codeforces Round #426 (Div. 2) B. The Festive Evening(思维)
- #426 (Div. 2) B. The Festive Evening
- Codeforces Round 834B-The Festive Evening
- (模拟)Codeforces Round #426 B. The Festive Evening
- 【CodeForces】426Div2 B The Festive Evening
- CodeForces #426 div2 B The Festive Evening
- Codeforces 834B-The Festive Evening
- Codeforces 834 B The Festive Evening
- CodeForces 834B The Festive Evening
- The Festive Evening (Codeforces
- Android之FFmpeg(2)--FFmpeg结构总览及函数基本使用
- 广搜加优先队列 题目:Rescue
- 算法学习笔记 二叉树和图遍历—深搜 DFS 与广搜 BFS
- Delphi 模式窗体返回值ModalResult的使用方法及注意事项
- 线段树基础:单点更新,区间最值(和)查询
- Codeforces Round #426 (Div. 2) B The Festive Evening
- 浙江中医药大学暑期训练测试赛八A
- 【Algorithm】藏在Ranking中的ELo
- Python关键字及其用法
- CF833A-The Meaningless Game
- 2017.07.28回顾
- java基础之JDBC编程(mysql)
- SSM数据库数据导出excel
- oracleday04(数据类型 alter )