QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#883714#8576. Symphony in c++ majortassei903#WA 1761ms245844kbC++234.3kb2025-02-05 18:22:042025-02-05 18:22:13

Judging History

This is the latest submission verdict.

  • [2025-02-05 18:22:13]
  • Judged
  • Verdict: WA
  • Time: 1761ms
  • Memory: 245844kb
  • [2025-02-05 18:22:04]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define ov4(a, b, c, d, name, ...) name
#define rep3(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep2(i, a, b) rep3(i, a, b, 1)
#define rep1(i, n) rep2(i, 0, n)
#define rep0(n) rep1(aaaaa, n)
#define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
#define per(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define fore(e, v) for(auto&& e : v)
#define all(a) begin(a), end(a)
#define sz(a) (int)(size(a))
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define eb emplace_back

template<typename T, typename S> bool chmin(T& a, const S& b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S> bool chmax(T& a, const S& b) { return a < b ? a = b, 1 : 0; }

const int INF = 1e9 + 100;
const ll INFL = 3e18 + 100;

#define i128 __int128_t

struct _ {
   _() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); }
} __;

template<class S, S (*op)(S, S), S (*e)()> struct segtree {
   segtree(int n) : segtree(vector<S>(n, e())) {}
   segtree(const vector<S>& v) : n(sz(v)) {
      s = bit_ceil(unsigned(n));
      log = countr_zero(unsigned(s));
      d = vector<S>(2 * s, e());
      rep(i, n) d[s + i] = v[i];
      per(i, s, 1) update(i);
   }
   void set(int p, S x) {
      d[p += s] = x;
      rep(i, 1, log + 1) update(p >> i);
   }
   S prod(int l, int r) const {
      S sml = e(), smr = e();
      l += s, r += s;
      while(l < r) {
         if(l & 1) sml = op(sml, d[l++]);
         if(r & 1) smr = op(d[--r], smr);
         l >>= 1, r >>= 1;
      }
      return op(sml, smr);
   }
   S all_prod() const { return d[1]; }
   template<typename F> int max_right(int l, F f) const {
      if(l == n) return n;
      l += s;
      S sm = e();
      do {
         while(~l & 1) l >>= 1;
         if(!f(op(sm, d[l]))) {
            while(l < s) {
               l <<= 1;
               if(f(op(sm, d[l]))) sm = op(sm, d[l++]);
            }
            return l - s;
         }
         sm = op(sm, d[l++]);
      } while((l & -l) != l);
      return n;
   }
   template<typename F> int min_left(int r, F f) const {
      if(!r) return 0;
      r += s;
      S sm = e();
      do {
         r--;
         while(r > 1 and r & 1) r >>= 1;
         if(!f(op(d[r], sm))) {
            while(r < s) {
               r = (2 * r + 1);
               if(f(op(d[r], sm))) sm = op(d[r--], sm);
            }
            return r + 1 - s;
         }
         sm = op(d[r], sm);
      } while((r & -r) != r);
      return 0;
   }

   private:
   int n, s, log;
   vector<S> d;
   void update(int k) { d[k] = op(d[k * 2], d[k * 2 + 1]); }
};

using uint8 = uint8_t;
const int M = 4;
struct S {
    vector<int> to;
    vector<uint8> cnt;
};
// a ... fl
// e ... r?
// i ... mt
// o ... ds
const vector<string> LL = {"fl", "r?", "mt", "ds"};
const string RR = "aeio";

S e() {
    S z;
    z.cnt.resize(1<<M);
    z.to.resize(1<<M);
    rep(i, 1<<M)z.cnt[i] = 0, z.to[i] = i;
    return z;
}
S op(S x, S y) {
    S z = e();
    rep(i, 1 << M) {
        z.to[i] = y.to[x.to[i]];
        z.cnt[i] = x.cnt[i] + y.cnt[x.to[i]];
    }
    return z;
}


S get(char x) {
    S z = e();
    rep(i, 1 << M) {
        int to = i, cnt = 0;
        rep(j, M) {
            if (LL[j][0] == x || LL[j][1] == x) to |= (1 << j);
            if (i >> j & 1 && RR[j] == x) {
                to = 0;
                cnt = 1;
                break;
            }
        }
        z.to[i] = to;
        z.cnt[i] = cnt;
        
    }
    return z;
}

void solve() {
    int n, q;cin >> n >> q;
    string s;cin >> s;
    vector<S> a(n);
    rep(i, n) a[i] = get(s[i]);

    segtree<S, op, e> st(a);

    rep(q) {
        string t;cin >> t;
        if (t == "?") {
            int l, r;cin >> l >> r;
            l--;
            cout << r - l - 2 * st.prod(l, r).cnt[0] << endl;
        }
        else {
            int l, r;cin >> l >> r;
            l--;
            string news;cin >> news;

            rep(i, l, r) {
                st.set(i, get(news[i-l]));
            }
        }
    }
}   

int main() {
    // int T;cin >> T;
    int T = 1;
    while (T--) {
        solve();
    }
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1761ms
memory: 245844kb

input:

500000 300000
rfsraltzititrofomloldlaefikdemaddaafmimiioiuaueiaedifacmxamttiiitaaltiiireexeafsaaraedosotlaioootaiosizlifiioadhnxiofsasaflleaiisstaotdlliulilxatrpdaraaraaoiaeoooiumwuumarlifesroloistedoaaieolisaoatamsredorrfiifaaidfeassfioaiasmstomasallsftsrfaiiirteomaeiirefldmlaoaofrxlaeuilioirafotoa...

output:

173351
188558
136858
77740
129435
209590
103713
5633
426238
76565
80293
376513
180344
241875
112004
296483
119548
117523
260330
108913
132974
244626
287230
138246
130849
95403
242692
206188
76384
234957
148433
253917
49404
78933
24455
105230
452475
346649
167962
230399
247876
192911
60515
336397
159...

result:

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