QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#388443#8576. Symphony in c++ majorBUET_POTATOES#WA 503ms199152kbC++203.6kb2024-04-13 15:43:422024-04-13 15:43:42

Judging History

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

  • [2024-04-13 15:43:42]
  • 评测
  • 测评结果:WA
  • 用时:503ms
  • 内存:199152kb
  • [2024-04-13 15:43:42]
  • 提交

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);
    }
}


詳細信息

Test #1:

score: 100
Accepted
time: 11ms
memory: 198896kb

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: 503ms
memory: 199152kb

input:

500000 300000
rfsraltzititrofomloldlaefikdemaddaafmimiioiuaueiaedifacmxamttiiitaaltiiireexeafsaaraedosotlaioootaiosizlifiioadhnxiofsasaflleaiisstaotdlliulilxatrpdaraaraaoiaeoooiumwuumarlifesroloistedoaaieolisaoatamsredorrfiifaaidfeassfioaiasmstomasallsftsrfaiiirteomaeiirefldmlaoaofrxlaeuilioirafotoa...

output:

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

result:

wrong answer 97th numbers differ - expected: '247820', found: '247822'