結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー HaaHaa
提出日時 2021-10-29 22:53:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,541 bytes
コンパイル時間 1,885 ms
コンパイル使用メモリ 172,044 KB
実行使用メモリ 100,480 KB
最終ジャッジ日時 2024-04-16 15:39:04
合計ジャッジ時間 8,060 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 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 RE -
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 116 ms
6,944 KB
testcase_38 AC 119 ms
6,940 KB
testcase_39 AC 119 ms
6,944 KB
testcase_40 AC 118 ms
6,944 KB
testcase_41 AC 118 ms
6,940 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 RE -
権限があれば一括ダウンロードができます

ソースコード

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;

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);
                for(int i=(1<<29);i>=1;i/=2){
                    if(tmp%i==0){
                        if(tmp/i%2==0)
                            ans+=yl[r%(n+m)-n][c-'a']-(l%(n+m)-n==0?0:xl[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-(r%(n+m)-n)-1][c-'a']);
                        break;
                    }
                }
                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--;
            for(int i=(1<<29);i>=1;i/=2){
                if(ynuml%i==0){
                    if(ynuml/i%2==0)
                        ans+=yr[(l%(n+m)-n)][c-'a'];
                    else
                        ans+=yl[m-1-(l%(n+m)-n)][c-'a'];
                    break;
                }
            }
        }
        if(r%(n+m)>=n&&r%(n+m)<n+m-1){
            ynumr++;
            for(int i=(1<<29);i>=1;i/=2){
                if(ynumr%i==0){
                    if(ynumr/i%2==0)
                        ans+=yl[r%(n+m)-n][c-'a'];
                    else
                        ans+=yr[m-1-(r%(n+m)-n)][c-'a'];
                    break;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}
0