結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー 👑 kmjpkmjp
提出日時 2021-10-31 15:29:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 4,000 ms
コード長 1,758 bytes
コンパイル時間 2,173 ms
コンパイル使用メモリ 196,312 KB
実行使用メモリ 23,888 KB
最終ジャッジ日時 2024-04-17 08:20:23
合計ジャッジ時間 6,237 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 10 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 8 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 10 ms
5,376 KB
testcase_13 AC 10 ms
5,376 KB
testcase_14 AC 72 ms
5,376 KB
testcase_15 AC 11 ms
5,376 KB
testcase_16 AC 16 ms
5,376 KB
testcase_17 AC 27 ms
5,376 KB
testcase_18 AC 86 ms
5,376 KB
testcase_19 AC 23 ms
5,376 KB
testcase_20 AC 10 ms
5,376 KB
testcase_21 AC 77 ms
5,376 KB
testcase_22 AC 81 ms
10,240 KB
testcase_23 AC 80 ms
9,344 KB
testcase_24 AC 52 ms
7,680 KB
testcase_25 AC 88 ms
13,696 KB
testcase_26 AC 73 ms
11,648 KB
testcase_27 AC 66 ms
15,232 KB
testcase_28 AC 102 ms
14,592 KB
testcase_29 AC 99 ms
14,080 KB
testcase_30 AC 91 ms
16,384 KB
testcase_31 AC 57 ms
9,472 KB
testcase_32 AC 111 ms
21,152 KB
testcase_33 AC 114 ms
21,884 KB
testcase_34 AC 108 ms
20,480 KB
testcase_35 AC 112 ms
18,560 KB
testcase_36 AC 119 ms
20,224 KB
testcase_37 AC 107 ms
5,376 KB
testcase_38 AC 107 ms
5,376 KB
testcase_39 AC 103 ms
5,376 KB
testcase_40 AC 102 ms
5,376 KB
testcase_41 AC 100 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 11 ms
23,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------


string X,Y;
int A,B;
ll H[60],sum[60][26];

int S[101010][26];
int T[101010][26];
int Q;
int C;

ll hoge(int cur,ll num) {
	if(num==0) return 0;
	if(num>=H[cur]) {
		return sum[cur][C];
	}
	
	if(cur==1) {
		return S[num][C];
	}
	else if(num<=H[cur-1]){
		return hoge(cur-1,num);
	}
	else if(num<=H[cur-1]+B) {
		ll pat=sum[cur-1][C];
		num-=H[cur-1];
		pat+=T[num][C];
		return pat;
	}
	else {
		ll pat=sum[cur][C]-hoge(cur-1,H[cur]-num);
		return pat;
	}
	
	
	
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>X>>Y;
	A=X.size();
	B=Y.size();
	FOR(i,A) {
		FOR(j,26) S[i+1][j]=S[i][j];
		S[i+1][X[i]-'a']++;
	}
	FOR(i,B) {
		FOR(j,26) T[i+1][j]=T[i][j];
		T[i+1][Y[i]-'a']++;
	}
	H[1]=A;
	FOR(j,26) sum[1][j]=S[A][j];
	for(i=2;i<=40;i++) {
		H[i]=min(1LL<<60,H[i-1]*2+B);
		FOR(j,26) sum[i][j]=min(1LL<<60,sum[i-1][j]*2+T[B][j]);
	}
	
	cin>>Q;
	while(Q--) {
		int L,R;
		cin>>L>>R>>s;
		C=s[0]-'a';
		cout<<hoge(31,R)-hoge(31,L-1)<<endl;
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0