結果

問題 No.2554 MMA文字列2 (Query Version)
ユーザー cho435cho435
提出日時 2023-12-08 19:22:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 919 ms / 5,000 ms
コード長 854 bytes
コンパイル時間 4,633 ms
コンパイル使用メモリ 272,040 KB
実行使用メモリ 96,764 KB
最終ジャッジ日時 2023-12-08 19:23:10
合計ジャッジ時間 37,703 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 3 ms
6,548 KB
testcase_03 AC 5 ms
6,548 KB
testcase_04 AC 8 ms
6,548 KB
testcase_05 AC 8 ms
6,548 KB
testcase_06 AC 5 ms
6,548 KB
testcase_07 AC 4 ms
6,548 KB
testcase_08 AC 5 ms
6,548 KB
testcase_09 AC 8 ms
6,548 KB
testcase_10 AC 8 ms
6,548 KB
testcase_11 AC 4 ms
6,548 KB
testcase_12 AC 96 ms
27,532 KB
testcase_13 AC 737 ms
89,116 KB
testcase_14 AC 144 ms
24,576 KB
testcase_15 AC 630 ms
95,696 KB
testcase_16 AC 371 ms
26,852 KB
testcase_17 AC 575 ms
49,620 KB
testcase_18 AC 187 ms
6,548 KB
testcase_19 AC 278 ms
26,412 KB
testcase_20 AC 709 ms
92,700 KB
testcase_21 AC 240 ms
9,472 KB
testcase_22 AC 840 ms
96,764 KB
testcase_23 AC 863 ms
96,764 KB
testcase_24 AC 871 ms
96,764 KB
testcase_25 AC 859 ms
96,764 KB
testcase_26 AC 839 ms
96,764 KB
testcase_27 AC 867 ms
96,764 KB
testcase_28 AC 871 ms
96,764 KB
testcase_29 AC 846 ms
96,764 KB
testcase_30 AC 863 ms
96,764 KB
testcase_31 AC 881 ms
96,764 KB
testcase_32 AC 104 ms
6,548 KB
testcase_33 AC 104 ms
6,548 KB
testcase_34 AC 114 ms
6,548 KB
testcase_35 AC 115 ms
6,548 KB
testcase_36 AC 118 ms
6,548 KB
testcase_37 AC 844 ms
96,764 KB
testcase_38 AC 841 ms
96,764 KB
testcase_39 AC 815 ms
96,764 KB
testcase_40 AC 824 ms
96,764 KB
testcase_41 AC 846 ms
96,764 KB
testcase_42 AC 849 ms
96,764 KB
testcase_43 AC 824 ms
96,764 KB
testcase_44 AC 848 ms
96,764 KB
testcase_45 AC 851 ms
96,764 KB
testcase_46 AC 832 ms
96,764 KB
testcase_47 AC 858 ms
96,764 KB
testcase_48 AC 883 ms
96,764 KB
testcase_49 AC 919 ms
96,764 KB
testcase_50 AC 885 ms
96,764 KB
testcase_51 AC 870 ms
96,764 KB
testcase_52 AC 887 ms
96,764 KB
testcase_53 AC 882 ms
96,764 KB
testcase_54 AC 875 ms
96,764 KB
testcase_55 AC 861 ms
96,764 KB
testcase_56 AC 896 ms
96,764 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),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];
		smb+=b.v1[i];
	}
	c.sm=a.sm+b.sm;
	rep(i,26){
		c.v2[i]+=a.v1[i]*(smb-b.v1[i]);
		c.sm+=a.v1[i]*b.v2[i];
		c.sm+=(a.v1[i]-1)*a.v1[i]/2*(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