Submission #38076430
Source Code Expand
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double PI = acos(-1);
int main() {
int n;
cin >> n;
string s;
cin >> s;
fenwick_tree<int> fs(n+1);
vector<fenwick_tree<int>> fenal(26, fenwick_tree<int>(n+1));
vector<int> al(26);
rep(i,n) {
int cint = s[i]-'a';
al[cint]++;
fenal[cint].add(i, 1);
if (i) {
if (!(s[i-1] <= s[i])) fs.add(i,-1);
}
if (i != n-1) {
if (!(s[i] <= s[i+1])) fs.add(i,-1);
}
}
int q;
cin >> q;
rep(qi,q) {
int t;
cin >> t;
if (t == 1) {
int x;
cin >> x;
x--;
char c;
cin >> c;
al[s[x]-'a']--;
fenal[s[x]-'a'].add(x, -1);
al[c-'a']--;
fenal[c-'a'].add(x, 1);
fs.add(x, -fs.sum(x,x+1));
s[x] = c;
if (x) {
if (!(s[x-1] <= s[x])) fs.add(x,-1);
}
if (x != n-1) {
if (!(s[x] <= s[x+1])) fs.add(x,-1);
}
} else {
int l, r;
cin >> l >> r;
l--; r--;
if (fs.sum(l, r+1) < 0) {
cout << "No" << endl;
continue;
}
vector<int> al2(26);
rep(i,26) {
al2[i] = fenal[i].sum(l, r+1);
}
int first = s[l]-'a';
int last = s[r]-'a';
bool ok = true;
rep(i,26) {
if (i == first || i == last) continue;
if (al2[i]) {
if (al2[i] != al[i]) ok = false;
}
}
if (ok == true) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
return 0;
}
Submission Info
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
0 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample_01.txt |
| All |
hand.txt, min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt |
| Case Name |
Status |
Exec Time |
Memory |
| hand.txt |
WA |
8 ms |
3492 KiB |
| min.txt |
AC |
2 ms |
3612 KiB |
| random_01.txt |
WA |
327 ms |
14252 KiB |
| random_02.txt |
WA |
303 ms |
14208 KiB |
| random_03.txt |
WA |
198 ms |
14332 KiB |
| random_04.txt |
WA |
208 ms |
14268 KiB |
| random_05.txt |
WA |
93 ms |
14212 KiB |
| random_06.txt |
WA |
92 ms |
14332 KiB |
| random_07.txt |
WA |
311 ms |
14216 KiB |
| random_08.txt |
WA |
335 ms |
14224 KiB |
| random_09.txt |
WA |
203 ms |
14148 KiB |
| random_10.txt |
WA |
198 ms |
14268 KiB |
| random_11.txt |
WA |
93 ms |
14212 KiB |
| random_12.txt |
WA |
91 ms |
14212 KiB |
| random_13.txt |
WA |
214 ms |
14272 KiB |
| random_14.txt |
WA |
207 ms |
14216 KiB |
| random_15.txt |
WA |
156 ms |
14212 KiB |
| random_16.txt |
AC |
222 ms |
14188 KiB |
| random_17.txt |
AC |
226 ms |
14232 KiB |
| random_18.txt |
AC |
216 ms |
14188 KiB |
| random_19.txt |
AC |
216 ms |
14192 KiB |
| random_20.txt |
AC |
208 ms |
14268 KiB |
| random_21.txt |
AC |
208 ms |
14228 KiB |
| sample_01.txt |
WA |
5 ms |
3416 KiB |