QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#379427#8566. Can We Still Qualify For Semifinals?ucup-team206#WA 0ms3624kbC++173.0kb2024-04-06 17:29:522024-04-06 17:29:53

Judging History

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

  • [2024-04-06 17:29:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3624kb
  • [2024-04-06 17:29:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int mp[500], to[500];
struct Info {
    int f[5][8];
    inline void Init(char c) {
        for (int i = 0; i < 5; ++i)
            for (int j = 0; j < 8; ++j)
                f[i][j] = -1e9;
        if (mp[c] > 0) f[0][mp[c]] = 0;
        else if (mp[c] < 0) f[-mp[c]][0] = 0;
        f[0][0] = 0;
    }
} va[N];
Info Merge(Info a, Info b) {
    Info c;
    for (int i = 0; i < 5; ++i)
        for (int j = 0; j < 8; ++j) {
            c.f[i][j] = max(a.f[i][j] + b.f[0][0], a.f[0][0] + b.f[i][j]);
        }
    for (int i = 0; i < 5; ++i)
        for (int j = 1; j < 8; ++j)
            for (int k = 0; k < 8; ++k) {
                c.f[i][k] = max(c.f[i][k], a.f[i][j] + b.f[to[j]][k] + 1);
            }
    return c;
}
void Append(vector<int> &rst, Info b) {
    vector<int> lst(rst);
    for (int i = 0; i < 8; ++i) {
        rst[i] = max(lst[i] + b.f[0][0], lst[0] + b.f[0][i]);
    }
    for (int i = 1; i < 8; ++i)
        for (int j = 0; j < 8; ++j)
            rst[j] = max(rst[j], lst[i] + b.f[to[i]][j] + 1);
}
int n, q;
string str;
inline void PushUp(int v) {
    va[v] = Merge(va[v << 1], va[v << 1 | 1]);
}
void Build(int v, int l, int r) {
    if (l == r) { va[v].Init(str[l]); return; }
    int mid = (l + r) >> 1;
    Build(v << 1, l, mid); Build(v << 1 | 1, mid + 1, r);
    PushUp(v);
}
void Ask(int x, int y, vector<int> &rst, int v, int l, int r) {
    if (x <= l && r <= y) { Append(rst, va[v]); return; }
    if (x > r || y < l) return;
    int mid = (l + r) >> 1;
    Ask(x, y, rst, v << 1, l, mid); Ask(x, y, rst, v << 1 | 1, mid + 1, r); 
}
void Update(int x, char c, int v, int l, int r) {
    if (l == r) { va[v].Init(c); return; }
    int mid = (l + r) >> 1;
    if (x <= mid) Update(x, c, v << 1, l, mid);
    else Update(x, c, v << 1 | 1, mid + 1, r);
    PushUp(v);
}
int main() {
    // "do”, “re”, “mi”, “fa”, “so”, “la”, “ti”
    mp['d'] = 1; to[1] = 4;
    mp['r'] = 2; to[2] = 2;
    mp['m'] = 3; to[3] = 3;
    mp['f'] = 4; to[4] = 1;
    mp['s'] = 5; to[5] = 4;
    mp['l'] = 6; to[6] = 1;
    mp['t'] = 7; to[7] = 3;

    mp['a'] = -1;
    mp['e'] = -2;
    mp['i'] = -3;
    mp['o'] = -4;
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q;
    cin >> str; str = " " + str;
    Build(1, 1, n);
    for (int i = 1; i <= q; ++i) {
        string op, text;
        int x, y;
        cin >> op >> x >> y;
        if (op == "?") {
            vector<int> rst(8);
            for (int i = 1; i < 8; ++i) rst[i] = -1e9;
            Ask(x, y, rst, 1, 1, n);
            int ans = (y - x + 1) - 2 * *max_element(rst.begin(), rst.end());
            // for (auto x : rst) cout << x << ' ';
            // cout << endl;
            cout << ans << '\n';
        } else {
            cin >> text;
            for (int i = x; i <= y; ++i) Update(i, text[i - x], 1, 1, n);
        }
        
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3624kb

input:

3
3
111
25
1000010101111111111010100
35
01111011110111101111011110111101111

output:


result:

wrong answer Answer contains longer sequence [length = 3], but output contains 0 elements