题意

给一个10^5之内的字符串(小写字母)时限2s

输入n,有n个操作  (n<10^5)

当操作是1的时候,输入位置x和改变的字母

当操作是2的时候,输入区间l和r,有多少不同的字母

思路

二维树状数组

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<map>
#define lowbit(x) x&(-x)
using namespace std;
const int maxn=1e5+;
char s[maxn];
int l,n,yi,er,san;
char c;
struct node{
int tr[maxn];
void inint(){
memset(tr,,sizeof(tr));
}
void updata(int x,int y){
for(int i=x; i<=l; i+=lowbit(i)){
tr[i]+=y;
}
}
int geshu(int x,int y){
int sum1=,sum2=;
for(int i=x; i>; i-=lowbit(i)){
sum1+=tr[i];
}
for(int i=y; i>; i-=lowbit(i)){
sum2+=tr[i];
}
return sum2-sum1;
}
} a[];
int main(){ while(~scanf("%s",&s)){
for(int i=; i<; i++){
a[i].inint();
}
l=strlen(s);
for(int i=; i<l; i++){
a[s[i]-'a'].updata(i+,);
}
scanf("%d",&n);
for(int i=; i<n; i++){
scanf("%d",&yi);
if(yi==){
scanf("%d %c",&er,&c);
er--;
a[s[er]-'a'].updata(er+,-);
s[er]=c;
a[s[er]-'a'].updata(er+,); }
else{
scanf("%d%d",&er,&san);
int ans=;
er--;
for(int i=; i<; i++){
//cout<<i<<" "<<a[i].geshu(er,san)<<endl;
if(a[i].geshu(er,san)){
ans+=;
}
}
printf("%d\n",ans);
}
}
}
return ;
}

Codeforces #590 D 二维树状数组的更多相关文章

  1. Codeforces Round #198 (Div. 1) D. Iahub and Xors 二维树状数组*

    D. Iahub and Xors   Iahub does not like background stories, so he'll tell you exactly what this prob ...

  2. 二维树状数组 BZOJ 1452 [JSOI2009]Count

    题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...

  3. HDU1559 最大子矩阵 (二维树状数组)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others)  ...

  4. POJMatrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 22058   Accepted: 8219 Descripti ...

  5. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  6. POJ 2155 Matrix(二维树状数组+区间更新单点求和)

    题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...

  7. [poj2155]Matrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Descripti ...

  8. POJ 2155 Matrix (二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17224   Accepted: 6460 Descripti ...

  9. [POJ2155]Matrix(二维树状数组)

    题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部 ...

随机推荐

  1. 每天进步一点点------MicroBlaze

             有了前面两个实例的铺垫,下面这个工程就要带大家尝试搭建一个基于MicroBlaze的应用.特权同学也是第一次接插Xilinx的嵌入式开发平台,跑了一个流程下来,正如所料,和Alter ...

  2. jquery--获取input checkbox是否被选中以及渲染checkbox选中状态

    jquery获取checkbox是否被选中 html <div><input type="checkbox" id="is_delete" n ...

  3. 刷题3. Longest Substring Without Repeating Characters

    一.题目 Longest Substring Without Repeating Characters,具体请自行搜索. 这个题目,我看了一下,经过一番思考,我觉得实现起来不是很复杂. 但要做到bug ...

  4. 【网易官方】极客战记(codecombat)攻略-地牢-祸之火焰

    关卡连接: https://codecombat.163.com/play/level/banefire 绕着火焰跳舞,否则你的骨头下次就会被烧着 默认代码 # 食人魔看上去又大又慢,这是你的机会. ...

  5. 虚拟函数是否应该被声明仅为private/protected?

    问题导入 我想对于大家来说,虚拟函数并不能算是个陌生的概念吧.至于怎么样使用它,大部分人都会告诉我:通过在子类中重写(override)基类中的虚拟函数,就可以达到OO中的一个重要特性——多态(pol ...

  6. AcWing 868. 筛质数 线性筛法

    #include <iostream> #include <algorithm> using namespace std; ; int primes[N], cnt; bool ...

  7. 线段树 区间查询区间修改 poj 3468

    #include<cstdio> #include<iostream> #include<algorithm> #include<string.h> u ...

  8. VUE style 绑定

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. Mysql数据库内置功能之函数

    一 函数 MySQL中提供了许多内置函数,例如: 一.数学函数 ROUND(x,y) 返回参数x的四舍五入的有y位小数的值 RAND() 返回0到1内的随机值,可以通过提供一个参数(种子)使RAND( ...

  10. python3中的正则表达式

    精确匹配: \d: 匹配一个数字     \w: 匹配一个字母或数字     . : 匹配任意一个字符     \s: 匹配一个空格(包括tab等空白符) 匹配变长的字符:     * : 匹配任意个 ...