QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#378495#8576. Symphony in c++ majorucup-team2112#WA 650ms247976kbC++203.0kb2024-04-06 13:12:312024-04-06 13:12:33

Judging History

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

  • [2024-04-06 13:12:33]
  • 评测
  • 测评结果:WA
  • 用时:650ms
  • 内存:247976kb
  • [2024-04-06 13:12:31]
  • 提交

answer

#include <bits/stdc++.h>

struct Matrix{
    int v[5][5];
    Matrix(){
        for (int i = 0; i < 5; i++){
            for (int j = 0; j < 5; j++){
                v[i][j] = 1e9;
            }
            v[i][i] = 1;
        }
    }

    int *operator[](int i){
        return v[i];
    }
};

Matrix operator*(Matrix a, Matrix b){
    Matrix c;
    for (int i = 0; i < 5; i += 1) {
        c[i][i] = 1e9;
    }
    for (int i = 0; i < 5; i++){
        for (int k = 0; k < 5; k++){
            for (int j = 0; j < 5; j++){
                c[i][j] = std::min(c[i][j], a[i][k] + b[k][j]);
            }
        }
    }
    return c;
}

Matrix get_mat(char c) {
    Matrix res;
    if(c == 'd' or c == 's') {
        res[0][1] = 0;
    }
    if (c == 'r') {
        res[0][2] = 0;
    }
    if (c == 'm' or c == 't') {
        res[0][3] = 0;
    }
    if(c == 'f' or c == 'l') {
        res[0][4] = 0;
    }
    if (c == 'o') {
        res[1][0] = 0;
    }
    if(c == 'e') {
        res[2][0] = 0;
    }
    if (c == 'i') {
        res[3][0] = 0;
    }
    if (c == 'a') {
        res[4][0] = 0;
    }
    return res;
}

const int maxn = 5e5 + 233;
Matrix tree[maxn << 2], dp[maxn];
#define ls o << 1
#define rs o << 1 | 1

void build(int o, int l, int r) {
    if(l == r) {
        tree[o] = dp[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(ls, l, mid);
    build(rs, mid + 1, r);
    tree[o] = tree[ls] * tree[rs];
}

void modify(int o, int l, int r, int pos, Matrix v) {
    if(l == r) {
        tree[o] = v;
        return;
    }
    int mid = (l + r) >> 1;
    if(pos <= mid) {
        modify(ls, l, mid, pos, v);
    }
    else {
        modify(rs, mid + 1, r, pos, v);
    }
    tree[o] = tree[ls] * tree[rs];
}

Matrix query(int o, int l, int r, int ql, int qr) {
    if(ql <= l and r <= qr) {
        return tree[o];
    }
    int mid = (l + r) >> 1;
    Matrix res;
    if(ql <= mid) {
        res = query(ls, l, mid, ql, qr);
    }
    if(qr > mid) {
        res = res * query(rs, mid + 1, r, ql, qr);
    }
    return res;
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int n, q;
    std::string s;
    std::cin >> n >> q;
    std::cin >> s;
    build(1, 1, n);
    for (int i = 0; i < n; i += 1) {
        dp[i + 1] = get_mat(s[i]);
    }
    // auto cc = dp[1] * dp[2];
    // for (int i = 0; i < 5; i += 1) {
    //     for (int j = 0; j < 5; j += 1) {
    //         std::cout << dp[1][i][j] << ' ';
    //     }
    //     std::cout << '\n';
    // }
    build(1, 1, n);
    for (int i = 0; i < q; i++){
        int l, r;
        std::string p, t;
        std::cin >> p >> l >> r;
        if (p == "#") {
            std::cin >> t;
            for (int i = l; i <= r; i += 1) {
                modify(1, 1, n, i, get_mat(t[i - l]));
            }
        }
        else {
            std::cout << query(1, 1, n, l, r)[0][0] << '\n';
        }
    }
  
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 32ms
memory: 247808kb

input:

8 10
eldorado
? 1 3
? 1 8
# 6 7 it
? 1 8
# 3 3 t
? 1 8
# 1 8 streamer
? 1 8
# 1 8 symphony
? 1 8

output:

3
4
6
6
6
6

result:

ok 6 numbers

Test #2:

score: -100
Wrong Answer
time: 650ms
memory: 247976kb

input:

500000 300000
rfsraltzititrofomloldlaefikdemaddaafmimiioiuaueiaedifacmxamttiiitaaltiiireexeafsaaraedosotlaioootaiosizlifiioadhnxiofsasaflleaiisstaotdlliulilxatrpdaraaraaoiaeoooiumwuumarlifesroloistedoaaieolisaoatamsredorrfiifaaidfeassfioaiasmstomasallsftsrfaiiirteomaeiirefldmlaoaofrxlaeuilioirafotoa...

output:

122158
133269
96929
55221
91555
148158
73512
4107
300805
54043
56749
265926
127618
170715
79249
209451
84740
83226
184053
77184
94070
172956
202758
97808
92458
67252
171532
145782
53865
165844
104920
179173
35078
55903
17297
74519
319362
244771
118814
162824
175184
136088
43116
237590
112902
48617
1...

result:

wrong answer 1st numbers differ - expected: '122151', found: '122158'