QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#379480#8576. Symphony in c++ majorucup-team1198#WA 444ms167496kbC++203.8kb2024-04-06 17:37:532024-04-06 17:37:53

Judging History

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

  • [2024-04-06 17:37:53]
  • 评测
  • 测评结果:WA
  • 用时:444ms
  • 内存:167496kb
  • [2024-04-06 17:37:53]
  • 提交

answer

#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;

const int K1 = 7;
const int K2 = 4;

string sogl = "dmfrstl";
string gl = "oiae";

const int INF = 1e9;

int dp[(1 << 20) + 228][K2 + 1][K1 + 1];

void recalc(int v, int left, int right) {
    for (int i = 0; i <= K2; ++i)
        fill(dp[v][i], dp[v][i] + K1 + 1, INF);
    for (int i = 0; i <= K2; ++i) {
        for (int j = 0; j <= K1; ++j) {
            int j2 = j == K1 ? K2 : (j & 3);
            for (int l = 0; l <= K1; ++l) {
                dp[v][i][l] = min(dp[v][i][l], dp[2 * v + 1][i][j] + dp[2 * v + 2][j2][l]);
            }
        }
    }
    int mid = (left + right) / 2;
    for (int i = 0; i <= K2; ++i) {
        for (int j = 0; j <= K1; ++j) {
            dp[v][i][j] = min(dp[v][i][j], dp[2 * v + 1][i][j] + right - mid);
            dp[v][i][j] = min(dp[v][i][j], mid - left + dp[2 * v + 2][i][j]);
        }
    }
}

void upd_symbol(int v, char c) {
    // left dim is right
    // right dim is left
    for (int i = 0; i <= K2; ++i)
        fill(dp[v][i], dp[v][i] + K1 + 1, INF);
    for (int i = 0; i < K2; ++i) {
        if (c == gl[i])
            dp[v][i][K1] = 0;
    }
    for (int i = 0; i < K1; ++i) {
        if (c == sogl[i])
            dp[v][K2][i] = 0;
    }
    dp[v][K2][K1] = 1;
}

void build(int v, int left, int right, string& s) {
    if (left + 1 == right) {
        upd_symbol(v, s[left]);
        return;
    }
    int mid = (left + right) / 2;
    build(2 * v + 1, left, mid, s);
    build(2 * v + 2, mid, right, s);
    recalc(v, left, right);
}

void upd(int v, int left, int right, int x, int y, string& s) {
    if (y <= left || right <= x)
        return;
    if (left + 1 == right) {
        upd_symbol(v, s[left - x]);
        return;
    }
    int mid = (left + right) / 2;
    upd(2 * v + 1, left, mid, x, y, s);
    upd(2 * v + 2, mid, right, x, y, s);
    recalc(v, left, right);
}

int cur_dp[K1 + 1];
int tmp_cur_dp[K1 + 1];

void get(int v, int left, int right, int x, int y) {
    if (y <= left || right <= x)
        return;
    if (x <= left && right <= y) {
        fill(tmp_cur_dp, tmp_cur_dp + K1 + 1, INF);
        for (int i = 0; i <= K1; ++i) {
            int i2 = i == K1 ? K2 : (i & 3);
            for (int j = 0; j <= K1; ++j)
                tmp_cur_dp[j] = min(tmp_cur_dp[j], cur_dp[i] + dp[v][i2][j]);
        }
        for (int i = 0; i <= K1; ++i)
            cur_dp[i] = tmp_cur_dp[i];
        return;
    }
    int mid = (left + right) / 2;
    get(2 * v + 1, left, mid, x, y);
    get(2 * v + 2, mid, right, x, y);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n, q;
    cin >> n >> q;
    string s;

    //for (int i = 0; i < n; ++i)
    //    s += char('a' + rand() % 26);

    cin >> s;
    build(0, 0, n, s);
    string t;
    while (q--) {
        char c;
        
        //c = '?';

        cin >> c;

        
        if (c == '?') {
            int i, j;
            cin >> i >> j;

            /*i = rand() % n + 1;
            j = i + rand() % (n - i + 1);*/

            fill(cur_dp, cur_dp + K1 + 1, INF);
            cur_dp[K1] = 0;
            get(0, 0, n, i - 1, j);
            cout << cur_dp[K1] << '\n';
        } else {
            int l, r;
            
            /*l = rand() % n + 1;
            r = l + 1;
            t = char('a' + rand() % 26);*/

            cin >> l >> r;
            cin >> t;
            upd(0, 0, n, l - 1, r, t);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3824kb

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: 444ms
memory: 167496kb

input:

500000 300000
rfsraltzititrofomloldlaefikdemaddaafmimiioiuaueiaedifacmxamttiiitaaltiiireexeafsaaraedosotlaioootaiosizlifiioadhnxiofsasaflleaiisstaotdlliulilxatrpdaraaraaoiaeoooiumwuumarlifesroloistedoaaieolisaoatamsredorrfiifaaidfeassfioaiasmstomasallsftsrfaiiirteomaeiirefldmlaoaofrxlaeuilioirafotoa...

output:

122151
133262
96922
55212
91547
148150
73505
4097
300800
54039
56741
265921
127608
170707
79236
209443
84732
83219
184042
77169
94062
172946
202750
97798
92449
67243
171524
145772
53856
165837
104913
179165
35068
55895
17287
74510
319357
244761
118810
162817
175172
136079
43107
237581
112894
48610
1...

result:

wrong answer 9th numbers differ - expected: '300798', found: '300800'