Codeforces #590 D 二维树状数组
题意
给一个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 二维树状数组的更多相关文章
- 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 ...
- 二维树状数组 BZOJ 1452 [JSOI2009]Count
题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...
- HDU1559 最大子矩阵 (二维树状数组)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others) ...
- POJMatrix(二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 22058 Accepted: 8219 Descripti ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- POJ 2155 Matrix(二维树状数组+区间更新单点求和)
题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...
- [poj2155]Matrix(二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 25004 Accepted: 9261 Descripti ...
- POJ 2155 Matrix (二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17224 Accepted: 6460 Descripti ...
- [POJ2155]Matrix(二维树状数组)
题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部 ...
随机推荐
- C#中的@和$ 占位符
c#中@的三种用法: 1.忽略转移字符 string str = "C:\\windows\\system32"; string str = @"C:\windows\s ...
- 每天进步一点点------Allegro中Autosilk top, Silkscreen top 和Assembly top三个什么区别
Autosilk top:最后出gerber的时候,自动生成的丝印层.会自动调整丝印位置,以及碰到阻焊开窗的地方,丝印会自动消失,避免露锡的地方涂上丝印(一般画丝印层的时候,焊盘上不会画上丝印,所以过 ...
- java把带小数点的字符串转换成int类型
String number ="1.0000"; int num =Double.valueOf(number).intValue();//转换为Int类型
- 存储过程(Stored Procedure)
存储过程中 IN,OUT,INOUT类型参数的区别 IN:输入参数:表示该参数的值必须在调用存储过程时指定赋值,在存储过程中修改该参数的值不能被返回,为默认值 OUT:在存储过程内部,该值的默认值为N ...
- linux下修改mysql的编码格式
修改编码格式:https://blog.csdn.net/qq_30038111/article/details/79376137 改编码格式在配置文件中修改才有效,在命令行中修改没效 ...
- 截取字符,超出的用省略号代替js实现 substring
可用到截取文字过多的问题,取0到6之间的字符,不包含6title.substring(0,6)+'...';
- 转载UUID.randomUUID()
UUID.randomUUID()生成唯一识别码 原创 清晨-阳光zx 最后发布于2019-04-11 20:54:40 阅读数 3039 收藏 发布于2019-04-11 20:54:40 分类专栏 ...
- expect 脚本
实现远程执行 /home/dataexa/test/proxy.expect touch proxy.expect #!/usr/bin/expect set timeout 30 spawn ssh ...
- dbGet net trace instant pin
proc rn { net_name } {puts " "puts "Net name : $net_name : "set name_rule [dbget ...
- Python的几种主动结束程序方式
1. sys.exit() 执行该语句会直接退出程序,这也是经常使用的方法,也不需要考虑平台等因素的影响,一般是退出Python程序的首选方法. 该方法中包含一个参数status,默认为0,表示正常退 ...