結果

問題 No.2554 MMA文字列2 (Query Version)
ユーザー cho435cho435
提出日時 2023-12-08 19:16:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,347 ms / 5,000 ms
コード長 904 bytes
コンパイル時間 4,676 ms
コンパイル使用メモリ 272,948 KB
実行使用メモリ 136,364 KB
最終ジャッジ日時 2023-12-08 19:17:39
合計ジャッジ時間 54,829 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 4 ms
6,676 KB
testcase_03 AC 6 ms
6,676 KB
testcase_04 AC 11 ms
6,676 KB
testcase_05 AC 11 ms
6,676 KB
testcase_06 AC 7 ms
6,676 KB
testcase_07 AC 6 ms
6,676 KB
testcase_08 AC 7 ms
6,676 KB
testcase_09 AC 11 ms
6,676 KB
testcase_10 AC 10 ms
6,676 KB
testcase_11 AC 5 ms
6,676 KB
testcase_12 AC 147 ms
37,832 KB
testcase_13 AC 1,119 ms
125,544 KB
testcase_14 AC 218 ms
33,536 KB
testcase_15 AC 1,040 ms
134,736 KB
testcase_16 AC 565 ms
36,844 KB
testcase_17 AC 906 ms
69,152 KB
testcase_18 AC 258 ms
7,808 KB
testcase_19 AC 409 ms
36,256 KB
testcase_20 AC 1,097 ms
130,572 KB
testcase_21 AC 360 ms
12,032 KB
testcase_22 AC 1,320 ms
136,364 KB
testcase_23 AC 1,322 ms
136,364 KB
testcase_24 AC 1,315 ms
136,364 KB
testcase_25 AC 1,341 ms
136,364 KB
testcase_26 AC 1,317 ms
136,364 KB
testcase_27 AC 1,301 ms
136,364 KB
testcase_28 AC 1,304 ms
136,364 KB
testcase_29 AC 1,303 ms
136,364 KB
testcase_30 AC 1,312 ms
136,364 KB
testcase_31 AC 1,320 ms
136,364 KB
testcase_32 AC 135 ms
6,676 KB
testcase_33 AC 134 ms
6,676 KB
testcase_34 AC 148 ms
6,676 KB
testcase_35 AC 148 ms
6,676 KB
testcase_36 AC 149 ms
6,676 KB
testcase_37 AC 1,204 ms
136,364 KB
testcase_38 AC 1,206 ms
136,364 KB
testcase_39 AC 1,209 ms
136,364 KB
testcase_40 AC 1,210 ms
136,364 KB
testcase_41 AC 1,204 ms
136,364 KB
testcase_42 AC 1,233 ms
136,364 KB
testcase_43 AC 1,247 ms
136,364 KB
testcase_44 AC 1,243 ms
136,364 KB
testcase_45 AC 1,246 ms
136,364 KB
testcase_46 AC 1,234 ms
136,364 KB
testcase_47 AC 1,324 ms
136,364 KB
testcase_48 AC 1,327 ms
136,364 KB
testcase_49 AC 1,323 ms
136,364 KB
testcase_50 AC 1,339 ms
136,364 KB
testcase_51 AC 1,347 ms
136,364 KB
testcase_52 AC 1,338 ms
136,364 KB
testcase_53 AC 1,333 ms
136,364 KB
testcase_54 AC 1,310 ms
136,364 KB
testcase_55 AC 1,307 ms
136,364 KB
testcase_56 AC 1,317 ms
136,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i=0;i<(int)(n);i++)

struct S{
	vector<ll> v1,v2,v3;
	ll sm;
	S():v1(26,0),v2(26,0),v3(26,0),sm(0){}
};
S op(S a,S b){
	S c;
	ll smb=0;
	rep(i,26){
		c.v1[i]=a.v1[i]+b.v1[i];
		c.v2[i]=a.v2[i]+b.v2[i];
		c.v3[i]=a.v3[i]+b.v3[i];
		smb+=b.v1[i];
	}
	c.sm=a.sm+b.sm;
	rep(i,26){
		c.v2[i]+=a.v1[i]*(smb-b.v1[i]);
		c.v3[i]+=a.v1[i]*b.v1[i];
		c.sm+=a.v1[i]*b.v2[i];
		c.sm+=a.v3[i]*(smb-b.v1[i]);
	}
	return c;
}
S e(){
	return S();
}
S mk(char c){
	S s;
	s.v1[c-'A']++;
	return s;
}

int main(){
	int n,q;
	string s;
	cin>>n>>s>>q;
	atcoder::segtree<S,op,e> seg(n);
	rep(i,n) seg.set(i,mk(s[i]));
	rep(i,q){
		int t;
		cin>>t;
		if(t==1){
			int x;
			char c;
			cin>>x>>c;
			x--;
			seg.set(x,mk(c));
		}else{
			int l,r;
			cin>>l>>r;
			l--;
			cout<<seg.prod(l,r).sm<<"\n";
		}
	}
}
0