結果
| 問題 |
No.2554 MMA文字列2 (Query Version)
|
| コンテスト | |
| ユーザー |
maeshun
|
| 提出日時 | 2023-11-26 00:26:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,732 bytes |
| コンパイル時間 | 4,447 ms |
| コンパイル使用メモリ | 260,164 KB |
| 最終ジャッジ日時 | 2025-02-18 01:17:35 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | WA * 55 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
# include <debug_print.hpp>
# define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
# define dbg(...) (static_cast<void>(0))
#endif
int op(int a, int b){
return a+b;
}
int e(){
return 0;
}
int main()
{
int n;
string s;
cin >> n >> s;
int q;
cin >> q;
segtree<int, op, e> seg(n);
vector<segtree<int, op, e>> cnt(26, seg);
vector<segtree<int, op, e>> sum(26, seg);
vector<set<int>> st(26);
rep(i,n){
cnt[s[i]-'A'].set(i,1);
sum[s[i]-'A'].set(i,i);
st[s[i]-'A'].insert(i);
}
rep(_,q){
int t;
cin >> t;
if(t==1){
int x;
char c;
cin >> x >> c;
--x;
st[s[x]-'A'].erase(x);
cnt[s[x]-'A'].set(x,0);
sum[s[x]-'A'].set(x,0);
s[x] = c;
cnt[s[x]-'A'].set(x,1);
sum[s[x]-'A'].set(x,x);
st[s[x]-'A'].insert(x);
}else{
int l, r;
cin >> l >> r;
--l;
ll ans = 0;
rep(i,26){
ll c = cnt[i].prod(l, r);
if(c<2) continue;
auto it = st[i].lower_bound(l);
ll s = sum[i].prod(l,r) - *it;
ans += (c-1)*(r-1);
ans -= s - (c-1)*(c-2)/2;
}
cout << ans << endl;
}
}
return 0;
}
maeshun