Gym-102141E
https://vjudge.net/problem/Gym-102141E
用set乱搞
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<set>
#include<cstring>
#define inf 2147483647
#define N 1000010
#define p(a) putchar(a)
#define For(i,a,b) for(int i=a;i<=b;++i) using namespace std;
char s[N];
int T,kase;
struct node{
int l,r;
bool operator < (const node &b) const{
if(r!=b.r) return r<b.r;
return l<b.l;
}
}; struct tree{
set<node>s;
void init(){
s.clear();
}
void insert(int l,int r){
s.insert({l,r});
}
void spilt(int x){
auto res=*s.lower_bound({-,x});
s.erase(res);
if(x!=res.l) s.insert({res.l,x-});
if(x!=res.r) s.insert({x+,res.r});
}
int query(int x){
auto it=s.lower_bound({-,x});
return (it->r)-(it->l)+;
}
}a[]; void in(int &x){
int y=;char c=getchar();x=;
while(c<''||c>''){if(c=='-')y=-;c=getchar();}
while(c<=''&&c>=''){ x=(x<<)+(x<<)+c-'';c=getchar();}
x*=y;
}
void o(int x){
if(x<){p('-');x=-x;}
if(x>)o(x/);
p(x%+'');
} int main(){
in(T);
while(T--){
scanf("%s",s);
int n=strlen(s),op,q,x,l=;
For(i,,)
a[i].init();
For(i,,n-)
if(s[i]!=s[i-]){
a[s[i-]-'A'].insert(l,i-);
l=i;
}
a[s[n-]-'A'].insert(l,n-);
in(q);
printf("Case %d:\n",++kase);
while(q--){
in(op);in(x);
if(op&)
o(a[s[x]-'A'].query(x)),p('\n');
else
a[s[x]-'A'].spilt(x),s[x]='#';
}
}
return ;
}
Gym-102141E的更多相关文章
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
- Gym 101102C---Bored Judge(区间最大值)
题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...
- 2016"百度之星" - 初赛(Astar Round2A)Gym Class(拓扑排序)
Gym Class Accepts: 849 Submissions: 4247 Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65 ...
随机推荐
- css3技巧——产品列表之鼠标滑过效果translateY(三)
<div class="main"> <div class="view view-tenth"> <figure> < ...
- github 拷贝项目到本地
第一步,git config --global --list 验证邮箱 第二步,git config --global user.name "yourname",git confi ...
- HashMap(常用)方法个人理解
Hashmap的存值: public static void main(String[] args) { ///*Integer*/map.put("1", 1);//向map ...
- class.forname & classloader
From https://www.cnblogs.com/gaojing/archive/2012/03/15/2413638.html 传统的使用jdbc来访问数据库的流程为: Class.forN ...
- hive 总结三(压缩)
本文参考:黑泽君相关博客 本文是我总结日常工作中遇到的坑,结合黑泽君相关博客,选取.补充了部分内容. 开启 map 输出阶段压缩可以减少 job 中 map 和 Reduce task 间数据传输量. ...
- 第十五篇:java操作oracle踩坑之旅
最近刚做完mysql的各种需求,项目要满足oracle数据库,于是走上了漫漫的踩坑之路,同行可以看看以免踩坑……第一条:oracle建表的时候不需要在建表sql语句后指定默认字符集 DEFAULT C ...
- 基于jdk8的格式化时间方法
背景 jdk8之前,java使用Date表示时间,在做时间的格式化时,通常使用SimpleDateFormat,但是SimpleDateFormat是非线程安全的,在写代码时通常要将之定义为局部变量或 ...
- 关系型数据库——MySQL
[MySQL架构图] MySQL简要架构图如下图所示,引擎层以插件方式集成了不同的存储引擎,它们共用Server层对外提供服务. 连接器:用于连接管理,进行身份认证及权限相关的管理.(登录MySQ ...
- Entity Framework Code First 模式-建立多对多联系
Entity Framework 在建立多对多的联系时,会生成一个中间表,用来表示这个多对多的关系.这和数据库设计时从概念模型到逻辑模型转化时,多对多的关系不能和任何一端的实体合并,需要将关系也转化为 ...
- [Vue warn]: Failed to mount component: template or render function not defined. 错误解决方法
解决方法import Vue from "vue"; 默认引入的文件是 vue/dist/vue.runtime.common.js.这个可以在node_modules/vue/p ...