QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#379179 | #8576. Symphony in c++ major | ucup-team055# | TL | 0ms | 3616kb | C++23 | 2.8kb | 2024-04-06 16:30:30 | 2024-04-06 16:30:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LLONG_MAX / 4;
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define all(a) begin(a), end(a)
ll sz(auto& a) { return size(a); }
template<class T> bool chmin(T& a, T b) { if(a <= b) return 0; a = b; return 1; }
template<class T> bool chmax(T& a, T b) { if(a >= b) return 0; a = b; return 1; }
struct M {
uint64_t x;
operator uint64_t() const { return x; }
operator uint64_t&() { return x; }
uint64_t col(ll j) const {
return x >> j & 0x0101010101;
}
uint8_t row(ll i) const {
return x >> (i * 8) & 0xFF;
}
};
M match(M a, M b) {
M c = {0};
rep(j, 0, 7) {
const ll i = vector{0, 1, 2, 3, 0, 3, 2}[j];
c |= a.col(j) * b.row(i);
}
return c;
}
M mismatch(M a, ll pa, M b, ll pb) {
uint64_t c = 0, r = 0;
rep(i, 0, 5) r |= b.row(i);
if(pb == 0) rep(i, 0, 5) r |= a.row(i);
rep(j, 0, 8) c |= a.col(j);
if(pa == 0) rep(j, 0, 8) c |= b.col(j);
return {c * r};
}
struct T {
ll p;
M bit0, bit1;
};
const T e = {0, 1ULL << 39, 1ULL << 39};
T one(char c) {
T a = e;
rep(i, 0, 4) if(c == "oeia"[i]) {
a.bit0 |= 1ULL << (i * 8 + 7);
a.bit1 = a.bit0;
return a;
}
rep(i, 0, 7) if(c == "drmfslt"[i]) {
a.bit0 |= 1ULL << (32 + i);
a.bit1 = a.bit0;
return a;
}
return a;
}
T op(T a, T b) {
T c;
auto& [p, bit0, bit1] = c;
p = a.p + b.p + 1;
bit0 = match(a.bit0, b.bit0);
bit1 = mismatch(a.bit0, a.p, b.bit0, b.p);
bit1 |= match(a.bit0, b.bit1);
bit1 |= match(a.bit1, b.bit0);
if(bit0.x) {
return c;
}
p--;
bit0 = bit1;
bit1 = match(a.bit1, b.bit1);
bit1 |= mismatch(a.bit0, a.p, b.bit1, b.p - 1);
bit1 |= mismatch(a.bit1, a.p - 1, b.bit0, b.p);
return c;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
ll N, Q;
cin >> N >> Q;
string S;
cin >> S;
vector<T> seg(N * 2);
auto set = [&](ll i, char c) {
i += N;
seg[i] = one(c);
while(i >>= 1) seg[i] = op(seg[i * 2], seg[i * 2 + 1]);
};
rep(i, 0, N) set(i, S[i]);
while(Q--) {
char c;
cin >> c;
ll L, R;
cin >> L >> R;
L--;
const ll w = R - L;
if(c == '?') {
L += N;
R += N;
T pL = e, pR = e;
for(; L < R; L >>= 1, R >>= 1) {
if(L & 1) pL = op(pL, seg[L++]);
if(R & 1) pR = op(seg[--R], pR);
}
T ans = op(pL, pR);
cout << w - ans.p * 2 << '\n';
}
else {
string S;
cin >> S;
rep(i, 0, w) set(L + i, S[i]);
}
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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
Time Limit Exceeded
input:
500000 300000 rfsraltzititrofomloldlaefikdemaddaafmimiioiuaueiaedifacmxamttiiitaaltiiireexeafsaaraedosotlaioootaiosizlifiioadhnxiofsasaflleaiisstaotdlliulilxatrpdaraaraaoiaeoooiumwuumarlifesroloistedoaaieolisaoatamsredorrfiifaaidfeassfioaiasmstomasallsftsrfaiiirteomaeiirefldmlaoaofrxlaeuilioirafotoa...
output:
112543 122998 89460 50884 84439 136672 67925 3783 277498 49861 52347 245331 117792 157473 73242 193189 78182 76695 169772 71189 86776 159668 187032 90256 85337 62033 158178 134478 49684 152929 96725 165277 32348 51607 16011 68762 294641 225785 109514 150175 161674 125493 39805 219167 104194 44826 18...