結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー auauaauaua
提出日時 2021-10-29 22:27:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 4,000 ms
コード長 3,254 bytes
コンパイル時間 1,875 ms
コンパイル使用メモリ 171,332 KB
実行使用メモリ 51,840 KB
最終ジャッジ日時 2024-04-16 15:17:45
合計ジャッジ時間 5,141 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 6 ms
5,760 KB
testcase_13 AC 6 ms
5,888 KB
testcase_14 AC 23 ms
5,760 KB
testcase_15 AC 7 ms
6,400 KB
testcase_16 AC 10 ms
6,912 KB
testcase_17 AC 14 ms
7,296 KB
testcase_18 AC 30 ms
5,504 KB
testcase_19 AC 10 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 20 ms
5,376 KB
testcase_22 AC 54 ms
18,688 KB
testcase_23 AC 46 ms
17,152 KB
testcase_24 AC 35 ms
12,800 KB
testcase_25 AC 60 ms
27,520 KB
testcase_26 AC 55 ms
22,016 KB
testcase_27 AC 59 ms
30,848 KB
testcase_28 AC 71 ms
29,312 KB
testcase_29 AC 67 ms
28,288 KB
testcase_30 AC 71 ms
33,536 KB
testcase_31 AC 37 ms
16,896 KB
testcase_32 AC 94 ms
45,184 KB
testcase_33 AC 96 ms
46,336 KB
testcase_34 AC 92 ms
43,136 KB
testcase_35 AC 86 ms
38,400 KB
testcase_36 AC 90 ms
42,112 KB
testcase_37 AC 29 ms
5,376 KB
testcase_38 AC 29 ms
5,376 KB
testcase_39 AC 29 ms
5,376 KB
testcase_40 AC 29 ms
5,376 KB
testcase_41 AC 29 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 60 ms
51,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
//#define vec vector<ll>
//#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=MOD;
const ll MAX=200010;
const double PI=acos(-1.0);
typedef vector<vector<ll> > mat;
typedef vector<ll> vec;



void solve(){
    string x,y;cin>>x>>y;
    ll a=x.size(),b=y.size();
    vector<vector<ll> >cntx(a,vector<ll>(26)),cnty(b,vector<ll>(26));
    rep(i,a){
        if(i){
            rep(j,26){
                cntx[i][j]=cntx[i-1][j];
            }
        }
        cntx[i][x[i]-'a']++;
    }
    rep(i,b){
        if(i){
            rep(j,26){
                cnty[i][j]=cnty[i-1][j];
            }
        }
        cnty[i][y[i]-'a']++;
    }
    ll q;cin>>q;
    while(q--){
        ll l,r;
        cin>>l>>r;
        char c;cin>>c;
        ll z=c-'a';
        ll w=(l-1)/(a+b);
        ll e=(l-1)%(a+b);
        ll t=r/(a+b);
        ll u=r%(a+b);
        ll m=cntx[a-1][z]+cnty[b-1][z];
        ll sum1=w*m,sum2=m*t;
        if(e>=a){
            sum1+=cntx[a-1][z];
            bool f=0;
            ll now=w+1;
            for(int j=32;j>=0;j--){
                if((1LL<<j)>now)continue;
                if(now==(1LL<<j)){
                    break;
                }
                f^=1;
                now=(1LL<<j)*2LL-now;
            }
            if(!f){
                if(e>a){
                    sum1+=cnty[e-a-1][z];
                }
            }else{
                if(e>a){
                    sum1+=cnty[b-1][z]-cnty[b-1-(e-a)][z];
                }
            }
        }else{
            if((w+1)%2==0){
                if(e){
                    sum1+=cntx[a-1][z]-cntx[a-1-e][z];
                }
            }else{
                if(e){
                    sum1+=cntx[e-1][z];
                }
            }
        }
        swap(e,u),swap(t,w);
        if(e>=a){
            sum2+=cntx[a-1][z];
            bool f=0;
            ll now=w+1;
            for(int j=32;j>=0;j--){
                if((1LL<<j)>now)continue;
                if(now==(1LL<<j)){
                    break;
                }
                f^=1;
                now=(1LL<<j)*2LL-now;
            }
            if(!f){
                if(e>a){
                    sum2+=cnty[e-a-1][z];
                }
            }else{
                if(e>a){
                    sum2+=cnty[b-1][z]-cnty[b-1-(e-a)][z];
                }
            }
        }else{
            if((w+1)%2==0){
                if(e){
                    sum2+=cntx[a-1][z]-cntx[a-1-e][z];
                }
            }else{
                if(e){
                    sum2+=cntx[e-1][z];
                }
            }
        }
        cout<<sum2-sum1<<endl;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
0