QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#388440#8576. Symphony in c++ majorBUET_POTATOES#WA 11ms198948kbC++203.6kb2024-04-13 15:42:212024-04-13 15:42:22

Judging History

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

  • [2024-04-13 15:42:22]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:198948kb
  • [2024-04-13 15:42:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9, K = 4, N = 5e5 + 5;
void conv(string &s){
    for(auto &x : s){
        if(x == 'd')x = 's';
        else if(x == 'm')x = 't';
        else if(x == 'f')x = 'l';
    }
}
char cng(char c){
    if(c == 's')return 1;
    if(c == 't')return 2;
    if(c == 'l')return 3;
    if(c == 'r')return 4;
    if(c == 'o')return 4+1;
    if(c == 'i')return 4+2;
    if(c == 'a')return 4+3;
    if(c == 'e')return 4+4;
    return 0;
}
namespace ST{
    struct node{
        int val[K + 1][K + 1];
        void init(){
            for(int i = 0; i <= K; ++i){
                for(int j = 0; j <= K; ++j)
                    val[i][j] = -INF;
            }
            val[0][0] = 0;
        }
        void init(char c){
            c = cng(c);
            init();
            if(c == 0)return;
            if(c > K)
                val[c - K][0] = 0;
            else
                val[0][c] = 0;
        }
        node(){
            init();
        }
        node(char c){
            init(c);
        }
    };

    node comb(const node &a, const node &b){
        node ret;
        for(int i = 0; i <= K; ++i){
            for(int j = 0; j <= K; ++j){
                ret.val[i][j] = max(ret.val[i][j], a.val[i][0] + b.val[0][j]);
                ret.val[i][j] = max(ret.val[i][j], a.val[i][j]);
                ret.val[i][j] = max(ret.val[i][j], b.val[i][j]);
                for(int k = 1; k <= K; ++k){
                    ret.val[i][j] = max(ret.val[i][j], a.val[i][k] + b.val[k][j] + 2);
                }
            }
        }
        return ret;
    }
    node st[N << 2];
    void init(int u, int l, int r, const string &s){
        if(l == r){
            st[u].init(s[l]);
            return;
        }
        int mid = l + r >> 1;
        init(u << 1, l, mid, s);
        init(u << 1 | 1, mid + 1, r, s);
        st[u] = comb(st[u << 1], st[u << 1 | 1]);
//        cout << "NODE: " << u << ' ' << l << ' ' << r << endl;
//        for(int i = 0; i <= K; ++i){
//            for(int j = 0; j <= K; ++j)
//                if(st[u].val[i][j] >= 0)cout << i << ' ' << j << ' ' << st[u].val[i][j] << endl;
//        }
    }
    void update(int u, int l, int r, int L, int R, int &k, string &s){
        if(L > r || R < l)return;
        if(l == r){
            st[u].init(s[k++]);
            return;
        }
        int mid = l + r >> 1;
        update(u << 1, l, mid, L, R, k, s);
        update(u << 1 | 1, mid + 1, r, L, R, k, s);
        st[u] = comb(st[u << 1], st[u << 1 | 1]);
    }
    node query(int u, int l, int r, int L, int R){
        if(L > r || R < l)return node();
        if(L <= l && R >= r){
            return st[u];
        }
        int mid = l + r >> 1;
        return comb(query(u << 1, l, mid, L, R), query(u << 1 | 1, mid + 1, r, L, R));
    }
}

void testcase(int cs){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    conv(s);
    cout << sizeof(ST::st) << endl;

    ST::init(1, 0, n - 1, s);
    while(q--){
        char c;
        cin >> c;
        int l, r;
        cin >> l >> r;
        --l, --r;
        if(c == '?'){
            auto ans = ST::query(1, 0, n - 1, l, r);

            cout << r - l + 1 - ans.val[0][0] << "\n";
        }else{
            cin >> s;
            int k = 0;
            ST::update(1, 0, n - 1, l, r, k, s);
        }
    }
}
/*
4 3
eldo
? 1 2
? 3 4
? 1 4
*/
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
//    cin >> T;
    for(int cs = 1; cs <= T; ++cs){
        testcase(cs);
    }
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 11ms
memory: 198948kb

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:

200002000
3
4
6
6
6
6

result:

wrong answer 1st numbers differ - expected: '3', found: '200002000'