题意

给一个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. 每天进步一点点------verilog语言实现的分频

    一 .占空比50%的任意奇数分频 如果要实现占空比为50%的三分频时钟,可以通过待分频时钟下降沿触发计数,和上升沿同样的方法计数进行三分频,然后下降沿产生的三分频时钟和上升沿产生的时钟进行相或运算,即 ...

  2. IntelliJ IDEA 2017.3尚硅谷-----设置自动编译

  3. 解决VS2017中出现:This function or variable may be unsafe

    解决办法:项目名称-右键属性-C/C++ - 预处理器 -预处理器定义 - 右侧下拉框中选择"编辑"- 在第一个编辑框中添加_CRT_SECURE_NO_WARNINGS

  4. c语言用raw socket进行抓包

    https://www.cnblogs.com/MrYuan/p/5215923.html https://blog.csdn.net/qq_41787205/article/details/8669 ...

  5. 计算几何-Graham法-凸包

    This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. 关键一句话 Cr ...

  6. varchar(n)

    MySQL5.0.3之前varchar(n)这里的n表示字节数MySQL5.0.3之后varchar(n)这里的n表示字符数,比如varchar(200),不管是英文还是中文都可以存放200个根据字符 ...

  7. vue移动端项目在手机上调试

    1.电脑和手机要连同一个wifi  一定是复制无线网的IP,而不是以太网的IP 2.在你的电脑上查找无线网络的ipv4地址: 查找方法:windows+r   然后再输入框里输入cmd 回车 会出现这 ...

  8. 数据提取之JSON与JsonPATH

    数据提取之JSON与JsonPATH JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,它使得人们很容易的进行阅读和编写.同时也方便了机器进行解析和生成.适 ...

  9. Python实验案例

    Python 运算符.内置函数 实验目的: 1.熟练运用 Python 运算符. 2.熟练运用 Python 内置函数.实验内容: 1.编写程序,输入任意大的自然数,输出各位数字之和. 2.编写程序, ...

  10. 设备驱动基础学习--/proc下增加节点

    在需要创建一个由一系列数据顺序组合而成的/proc虚拟文件或一个较大的/proc虚拟文件时,推荐使用seq_file接口. 数据结构struct seq_fille定义在include/linux/s ...