QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#167005#6866. Hello World 3 Pro MaxPPP#AC ✓191ms12888kbC++173.5kb2023-09-06 22:37:412023-09-06 22:37:41

Judging History

你现在查看的是最新测评结果

  • [2023-09-06 22:37:41]
  • 评测
  • 测评结果:AC
  • 用时:191ms
  • 内存:12888kb
  • [2023-09-06 22:37:41]
  • 提交

answer

#ifdef DEBUG
//#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

const ll mod = 1000000007;
//const ll mod = 998244353;

#define X first
#define Y second

ll pew(ll a, ll b)
{
    ll res = 1;
    while (b>0)
    {
        if (b&1) res = res*a%mod;
        b >>= 1;
        a = a*a%mod;
    }
    return res;
}

vector<ll> P(7);

vector<vector<ll>> a;

const int K = 10;
int t[10000][K+1][K+1];

void calc(int v, int tl, int tr)
{
    for (int i=0;i<=K;i++)
    {
        for (int j=i;j<=K;j++) t[v][i][j] = 0;
        t[v][i][i] = 1;
    }
    for (int p=tl;p<=tr;p++)
    {
        for (int j=K-1;j>=0;j--)
        {
            for (int st=0;st<=j;st++)
            {
                t[v][st][j+1] = (t[v][st][j+1]+t[v][st][j]*a[p][j])%mod;
            }
        }
    }
}

void recalc(int v)
{
    for (int i=0;i<=K;i++)
    {
        for (int j=i;j<=K;j++)
        {
            t[v][i][j] = 0;
            for (int w=i;w<=j;w++)
            {
                t[v][i][j] = (t[v][i][j]+t[v*2][i][w]*1LL*t[v*2+1][w][j])%mod;
            }
        }
    }
}


void build(int v, int tl, int tr)
{
    if (tr-tl<=20)
    {
        calc(v,tl,tr);
        return;
    }
    int tm = (tl+tr)/2;
    build(v*2,tl,tm);
    build(v*2+1,tm+1,tr);
    recalc(v);
}

void upd(int v, int tl, int tr, int p)
{
    if (tr-tl<=20)
    {
        calc(v,tl,tr);
        return;
    }
    int tm = (tl+tr)/2;
    if (tm>=p) upd(v*2,tl,tm,p);
    else upd(v*2+1,tm+1,tr,p);
    recalc(v);
}

vector<ll> dp(K+1);

void get(int v, int tl, int tr, int l, int r)
{
    if (tl>=l and tr<=r)
    {
        for (int j=K;j>0;j--)
        {
            for (int i=j-1;i>=0;i--) dp[j] = (dp[j]+dp[i]*t[v][i][j])%mod;
        }
        return;
    }
    if (tr-tl<=20)
    {
        l = max(l,tl);
        r = min(r,tr);
        for (int p=l;p<=r;p++)
        {
            for (int j=K-1;j>=0;j--)
            {
                dp[j+1] = (dp[j+1]+dp[j]*a[p][j])%mod;
            }
        }
        return;
    }
    int tm = (tl+tr)/2;
    if (tm>=l) get(v*2,tl,tm,l,r);
    if (tm<r) get(v*2+1,tm+1,tr,l,r);
}

void solve()
{
    int n;
    cin >> n;
    ll S = 0;
    for (int i=0;i<7;i++)
    {
        cin >> P[i];
        S += P[i];
    }
    S = pew(S,mod-2);
    for (int i=0;i<7;i++) P[i] = P[i]*S%mod;
    vector<int> pos = {0,1,2,2,3,4,3,5,2,6};
    string ss = "helloworld";
    a.resize(n,vector<ll>(10));
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<10;j++) a[i][j] = P[pos[j]];
    }
    build(1,0,n-1);
    int q;
    cin >> q;
    while (q--)
    {
        int T;
        cin >> T;
        if (T==1)
        {
            int x;
            char ch;
            cin >> x >> ch;
            x--;
            for (int i=0;i<K;i++)
            {
                if (ch!=ss[i]) a[x][i] = 0;
                else a[x][i] = 1;
            }
            upd(1,0,n-1,x);
            continue;
        }
        int L, R;
        cin >> L >> R;
        L--, R--;
        for (int i=0;i<=K;i++) dp[i] = 0;
        dp[0] = 1;
        get(1,0,n-1,L,R);
        cout << dp[K] << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//#ifdef DEBUG
    //freopen("input.txt", "r", stdin);
//#endif
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 191ms
memory: 12888kb

input:

10
11
1 1 1 1 1 1 1
16
1 1 h
2 1 11
2 2 11
1 2 e
1 3 l
1 4 l
1 5 l
2 1 11
1 6 o
1 7 w
2 2 11
1 8 o
1 9 r
1 10 l
1 11 d
2 1 11
100
58260522 77914575 2436426 24979445 61648772 23690081 33933447
100
2 15 80
2 20 79
1 25 h
2 2 81
2 22 99
2 7 90
1 2 l
2 8 99
2 9 94
2 3 92
2 9 86
2 21 77
1 20 h
2 7 81
2 1...

output:

667718262
953066461
937670535
0
3
232051379
621924234
493081837
2393352
652807536
640770300
295605485
956417981
649085445
147228730
383512042
530537470
319879012
770744528
869183544
538022860
841160411
26935379
210531625
355301868
865355727
169566795
750631442
219328548
104188127
259914506
263795372...

result:

ok 34614 lines