結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 11 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
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 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 13 ms
5,504 KB
testcase_21 WA -
testcase_22 AC 141 ms
34,176 KB
testcase_23 AC 138 ms
30,848 KB
testcase_24 AC 94 ms
22,400 KB
testcase_25 AC 175 ms
51,584 KB
testcase_26 AC 144 ms
40,832 KB
testcase_27 AC 149 ms
58,496 KB
testcase_28 WA -
testcase_29 AC 187 ms
52,864 KB
testcase_30 WA -
testcase_31 AC 106 ms
30,848 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 224 ms
73,344 KB
testcase_36 WA -
testcase_37 AC 116 ms
5,376 KB
testcase_38 AC 116 ms
5,376 KB
testcase_39 AC 117 ms
5,376 KB
testcase_40 AC 119 ms
5,376 KB
testcase_41 AC 125 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

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(int n){
    int 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: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-(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