結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー milanis48663220milanis48663220
提出日時 2021-10-29 23:14:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,137 bytes
コンパイル時間 1,457 ms
コンパイル使用メモリ 126,124 KB
実行使用メモリ 44,288 KB
最終ジャッジ日時 2024-04-16 15:51:21
合計ジャッジ時間 6,130 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 132 ms
5,376 KB
testcase_38 AC 131 ms
5,376 KB
testcase_39 AC 131 ms
5,376 KB
testcase_40 AC 131 ms
5,376 KB
testcase_41 AC 132 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 47 ms
44,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

string x, y;
ll n, m;
vector<ll> len(31);
vector<ll> cnt_y(26);
auto cnt = vec2d(31, 26, 0ll);
vector<vector<ll>> cnt_cumsum_x(26);
vector<vector<ll>> cnt_cumsum_y(26);

void test(string x, string y, int l, int r, int idx){
    int n = 10;
    vector<string> f(n);
    f[0] = x;
    for(int i = 1; i < n; i++){
        f[i] = f[i-1];
        f[i] += y;
        int m = f[i-1].size();
        for(int j = m-1; j >= 0; j--) f[i] += f[i-1][j];
    }
   
    int cnt = 0;
    for(int i = l; i < r; i++){
        if(f[9][i] == 'a'+idx) cnt++;
        cout << f[9][i];
    }
    cout << endl;
    cout << cnt << endl;
}

int sum_y(ll l, ll r, int idx, bool rev){
    if(l < 0) l = 0;
    if(r > m) r = m;
    if(l >= r) return 0;
    // int ans = 0;
    // if(rev){
    //     for(int i = m-r; i < m-l; i++){
    //         if(y[i]-'a' == idx) ans++;
    //     }
    // }else{
    //     for(int i = l; i < r; i++){
    //         if(y[i]-'a' == idx) ans++;
    //     }
    // }
    // return ans;
    if(rev){
        // cout << l << ' ' << r << ':' <<  cnt_cumsum_y[idx][m-l]-cnt_cumsum_y[idx][m-r] << endl;
        return cnt_cumsum_y[idx][m-l]-cnt_cumsum_y[idx][m-r];
    }else{
        // cout << l << '-' << r << ':' << cnt_cumsum_y[idx][r]-cnt_cumsum_y[idx][l] << endl;
        return cnt_cumsum_y[idx][r]-cnt_cumsum_y[idx][l];
    }
}

ll ans;
void solve(ll l, ll r, int idx, int depth, bool rev){
    // cout << "solve(" << l << "," << r << "," << depth << ")" << endl;
    if(l < 0) l = 0;
    if(r > len[depth]) r = len[depth];
    if(l >= r) return;
    if(depth == 0){
        if(rev){
            ans += cnt_cumsum_x[idx][n-l]-cnt_cumsum_x[idx][n-r];
        }else{
            ans += cnt_cumsum_x[idx][r]-cnt_cumsum_x[idx][l];
        }
        return;
    }
    if(l == 0 && r == len[depth]){
        ans += cnt[depth][idx];
        return;
    }
    solve(l, r, idx, depth-1, !rev);
    ans += sum_y(l-len[depth-1], r-len[depth-1], idx, !rev);
    solve(l-len[depth-1]-m, r-len[depth-1]-m, idx, depth-1, rev);
    // cout << l << ' ' << r << ' ' << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> x >> y;
    for(char c: x) cnt[0][c-'a']++;
    for(char c: y) cnt_y[c-'a']++;
    n = x.size(), m = y.size();
    len[0] = n;
    for(int i = 1; i <= 30; i++){
        len[i] = len[i-1]*2+m;
        for(int j = 0; j < 26; j++){
            cnt[i][j] += cnt[i-1][j]*2+cnt_y[j];
        }
    }
    
    for(int j = 0; j < 26; j++){
        cnt_cumsum_x[j].resize(n+1);
        cnt_cumsum_y[j].resize(m+1);
        for(int i = 0; i < n; i++){
            if(x[i] == 'a'+j) cnt_cumsum_x[j][i+1] = cnt_cumsum_x[j][i]+1;
            else cnt_cumsum_x[j][i+1] = cnt_cumsum_x[j][i];
        }
        for(int i = 0; i < m; i++){
            if(y[i] == 'a'+j) cnt_cumsum_y[j][i+1] = cnt_cumsum_y[j][i]+1;
            else cnt_cumsum_y[j][i+1] = cnt_cumsum_y[j][i];
        }
    }
    int q; cin >> q;
    while(q--){
        int l, r; cin >> l >> r; l--;
        char c; cin >> c;
        ans = 0;
        int idx = c-'a';
        solve(l, r, idx, 30, false);
        cout << ans << endl;
        // test(x, y, l, r, idx);
    }
}
0