-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBIT.cpp
More file actions
64 lines (64 loc) · 1.01 KB
/
BIT.cpp
File metadata and controls
64 lines (64 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<bits/stdc++.h>
#include<iostream>
#define test int t;scanf("%d",&t);while(t--)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,long int>
#define ll ll
using namespace std;
int BIT[100001][27];
string s;int n;
void update(int x,int val,int pos)
{
for(;x<=n;x+=x&-x)
BIT[x][pos]+=val;
}
int query(int x,int pos)
{
int sum=0;
for(;x>0;x-=x&-x)
sum+=BIT[x][pos];
return sum;
}
int main()
{
int q,l,r,type,odd=0;
scanf("%d%d",&n,&q);
//loop(i,0,n+1)
//BIT[i][j]=0;
cin>>s;
loop(i,0,s.length())
{
update(i+1,1,s[i]-'a');
}
char ch;
while(q--)
{
printf("Enter the values: %d\n",q);
scanf("%c",&ch);
scanf("%d%d%d",&type,&l,&r);
if(type==1)
{
update(l,-1,s[l]-'a');
update(l,1,r-97);
}
else
{
int res=0,odd=0;
loop(i,0,26)
{
res=query(r,i)-query(l-1,i);
printf("%d ",res);
if(res%2)
{
odd++;
}
}
printf("\n");
if(odd<=1)
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}