-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShil and Palindrome Research .cpp
More file actions
145 lines (116 loc) · 2.49 KB
/
Copy pathShil and Palindrome Research .cpp
File metadata and controls
145 lines (116 loc) · 2.49 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define mod 1000000007
#define F first
#define S second
typedef long long ll;
using namespace std;
bool check(int l, int r, int** bit)
{
r = r+1;
int* right = new int[26];
int* left = new int[26];
memset(right,0,26*sizeof(int));
memset(left,0,26*sizeof(int));
while(r>0)
{
for(int i = 0; i<=25; i++)
{
right[i]+=bit[r][i];
}
r = r - (r & (-r));
}
while(l>0)
{
for(int i = 0; i<=25; i++)
{
left[i]+=bit[l][i];
}
l = l - (l & (-l));
}
for(int i = 0; i<=25; i++)
{
right[i] = right[i] - left[i];
//cout<<right[i]<<" ";
}
//cout<<endl;
bool odd = false;
for(int i = 0; i<=25; i++)
{
if(right[i]%2==1 && !odd)
{
odd = true;
}
else if(right[i]%2==1)
{
return false;
}
}
return true;
}
void update(int index, int** bit, int n, int val)
{
index = index+1;
while(index<=n)
{
bit[index][val]++;
index = index + (index & (-index));
}
}
void updatebit(string& a, int index, int** bit, int n, int newval)
{
index = index + 1;
int oldval = a[index-1]-97;
a[index-1] = (char)(newval+97);
while(index<=n)
{
bit[index][oldval]--;
bit[index][newval]++;
index = index + (index & (-index));
}
}
int** construct(string a, int n)
{
int** bit = new int*[n+1];
for(int i = 0; i < n+1; ++i)
bit[i] = new int[26];
for(int i = 0; i<=n; i++)
{
for(int j = 0; j<26; j++)
{
bit[i][j] = 0;
}
}
for(int i = 0; i<=a.length()-1; i++)
{
update(i,bit,n,a[i]-97);
}
return bit;
}
int main()
{
int n, q, h;
scanf("%d %d ",&n,&q);
string a;
cin>>a;
int** bit = construct(a,n);
for(int i = 1; i<=q; i++)
{
scanf("%d ",&h);
if(h==1)
{
int l; char x;
scanf("%d %c ",&l,&x);
updatebit(a,l-1,bit,n,x-97);
}
else
{
int l,r;
scanf("%d %d",&l,&r);
if(check(l-1,r-1,bit))
printf("yes\n");
else printf("no\n");
}
}
return 0;
}