結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー HaaHaa
提出日時 2021-10-29 23:26:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 242 ms / 4,000 ms
コード長 3,092 bytes
コンパイル時間 1,974 ms
コンパイル使用メモリ 172,944 KB
実行使用メモリ 100,284 KB
最終ジャッジ日時 2024-04-16 15:58:10
合計ジャッジ時間 7,431 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 12 ms
6,940 KB
testcase_07 AC 6 ms
6,940 KB
testcase_08 AC 9 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 16 ms
8,432 KB
testcase_13 AC 18 ms
8,704 KB
testcase_14 AC 102 ms
8,320 KB
testcase_15 AC 20 ms
9,728 KB
testcase_16 AC 26 ms
10,368 KB
testcase_17 AC 44 ms
11,392 KB
testcase_18 AC 121 ms
7,840 KB
testcase_19 AC 34 ms
6,984 KB
testcase_20 AC 13 ms
6,944 KB
testcase_21 AC 104 ms
6,940 KB
testcase_22 AC 138 ms
34,304 KB
testcase_23 AC 136 ms
30,848 KB
testcase_24 AC 92 ms
22,656 KB
testcase_25 AC 173 ms
51,840 KB
testcase_26 AC 141 ms
40,704 KB
testcase_27 AC 148 ms
58,496 KB
testcase_28 AC 194 ms
55,680 KB
testcase_29 AC 188 ms
52,992 KB
testcase_30 AC 180 ms
63,872 KB
testcase_31 AC 109 ms
31,104 KB
testcase_32 AC 238 ms
86,784 KB
testcase_33 AC 242 ms
89,472 KB
testcase_34 AC 233 ms
82,688 KB
testcase_35 AC 219 ms
73,344 KB
testcase_36 AC 231 ms
81,280 KB
testcase_37 AC 117 ms
6,940 KB
testcase_38 AC 116 ms
6,940 KB
testcase_39 AC 120 ms
6,940 KB
testcase_40 AC 115 ms
6,944 KB
testcase_41 AC 116 ms
6,944 KB
testcase_42 AC 2 ms
6,940 KB
testcase_43 AC 122 ms
100,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

bool f(ll n){
    ll k=n&-n;
    n=n&(k<<1);
    return n!=0;
}

int main(){
    string x, y; cin >> x >> y;
    int n=x.size(), m=y.size();
    VVI xl(n,VI(26,0)), xr(n,VI(26,0)), yl(m,VI(26,0)), yr(m,VI(26,0));
    REP(i,n){
        if(i>0)
            xl[i]=xl[i-1];
        xl[i][x[i]-'a']++;
    }
    for(int i=n-1;i>=0;i--){
        if(i<n-1)
            xr[i]=xr[i+1];
        xr[i][x[i]-'a']++;   
    }
    REP(i,m){
        if(i>0)
            yl[i]=yl[i-1];
        yl[i][y[i]-'a']++;
    }
    for(int i=m-1;i>=0;i--){
        if(i<m-1)
            yr[i]=yr[i+1];
        yr[i][y[i]-'a']++;   
    }
    int q; cin >> q;
    int l, r; char c;
    while(q--){
        cin >> l >> r >> c;
        l--, r--;
        int ans=0;
        if(l/(n+m)==r/(n+m)){
            if(l%(n+m)<n&&r%(n+m)<n){
                if((l/(n+m)+1)%2==1)
                    ans+=xl[r%(n+m)][c-'a']-(l%(n+m)==0?0:xl[l%(n+m)-1][c-'a']);
                else
                    ans+=xr[n-1-r%(n+m)][c-'a']-(l%(n+m)==0?0:xr[n-1-l%(n+m)+1][c-'a']);
                cout << ans << endl;
                continue;
            }
            else if(l%(n+m)>=n&&r%(n+m)>=n){
                int tmp=l/(n+m)+1;
                if(f(tmp)==0)
                    ans+=yl[r%(n+m)-n][c-'a']-(l%(n+m)-n==0?0:yl[l%(n+m)-n-1][c-'a']);
                else
                    ans+=yr[m-1-(r%(n+m)-n)][c-'a']-(l%(n+m)-n==0?0:yr[m-1-(l%(n+m)-n)+1][c-'a']);
                cout << ans << endl;
                continue;
            }
        }
        int xnumr=(r+m+1)/(n+m);
        int xnuml=(l+n+m-1)/(n+m)+1;
        int xnum=max(0,xnumr-xnuml+1);
        ans+=xl[n-1][c-'a']*xnum;
        if(l%(n+m)>0&&l%(n+m)<=n-1){
            xnuml--;
            if(xnuml%2==1)
                ans+=xr[l%(n+m)][c-'a'];
            else
                ans+=xl[n-1-l%(n+m)][c-'a'];
        }
        if(r%(n+m)>=0&&r%(n+m)<n-1){
            xnumr++;
            if(xnumr%2==1)
                ans+=xl[r%(n+m)][c-'a'];
            else
                ans+=xr[n-1-r%(n+m)][c-'a'];
        }
        int ynumr=(r+1)/(n+m);
        int ynuml=(l+m-1)/(n+m)+1;
        int ynum=max(0,ynumr-ynuml+1);
        ans+=yl[m-1][c-'a']*ynum;
        if(l%(n+m)>n&&l%(n+m)<=n+m-1){
            ynuml--;
            if(f(ynuml)==0)
                ans+=yr[(l%(n+m)-n)][c-'a'];
            else
                ans+=yl[m-1-(l%(n+m)-n)][c-'a'];
        }
        if(r%(n+m)>=n&&r%(n+m)<n+m-1){
            ynumr++;
            if(f(ynumr)==0)
                ans+=yl[r%(n+m)-n][c-'a'];
            else
                ans+=yr[m-1-(r%(n+m)-n)][c-'a'];
        }
        cout << ans << endl;
    }
    return 0;
}
0