QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#774061 | #9791. Intrusive Donkey | ucup-team133# | RE | 0ms | 3792kb | C++23 | 7.9kb | 2024-11-23 11:31:53 | 2024-11-23 11:31:55 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif
template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
for (auto& e : v) {
is >> e;
}
return is;
}
template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
for (std::string_view sep = ""; const auto& e : v) {
os << std::exchange(sep, " ") << e;
}
return os;
}
template <class T, class U = T> bool chmin(T& x, U&& y) {
return y < x and (x = std::forward<U>(y), true);
}
template <class T, class U = T> bool chmax(T& x, U&& y) {
return x < y and (x = std::forward<U>(y), true);
}
template <class T> void mkuni(std::vector<T>& v) {
std::ranges::sort(v);
auto result = std::ranges::unique(v);
v.erase(result.begin(), result.end());
}
template <class T> int lwb(const std::vector<T>& v, const T& x) {
return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
// @param n `0 <= n`
// @return minimum non-negative `x` s.t. `n <= 2**x`
int ceil_pow2(int n) {
int x = 0;
while ((1U << x) < (unsigned int)(n)) x++;
return x;
}
// @param n `1 <= n`
// @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0`
constexpr int bsf_constexpr(unsigned int n) {
int x = 0;
while (!(n & (1 << x))) x++;
return x;
}
// @param n `1 <= n`
// @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0`
int bsf(unsigned int n) {
#ifdef _MSC_VER
unsigned long index;
_BitScanForward(&index, n);
return index;
#else
return __builtin_ctz(n);
#endif
}
} // namespace internal
} // namespace atcoder
namespace atcoder {
template <class S,
S (*op)(S, S),
S (*e)(),
class F,
S (*mapping)(F, S),
F (*composition)(F, F),
F (*id)()>
struct lazy_segtree {
public:
lazy_segtree() : lazy_segtree(0) {}
explicit lazy_segtree(int n) : lazy_segtree(std::vector<S>(n, e())) {}
explicit lazy_segtree(const std::vector<S>& v) : _n(int(v.size())) {
log = internal::ceil_pow2(_n);
size = 1 << log;
d = std::vector<S>(2 * size, e());
lz = std::vector<F>(size, id());
for (int i = 0; i < _n; i++) d[size + i] = v[i];
for (int i = size - 1; i >= 1; i--) {
update(i);
}
}
void set(int p, S x) {
assert(0 <= p && p < _n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
d[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
S get(int p) {
assert(0 <= p && p < _n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
return d[p];
}
S prod(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
if (l == r) return e();
l += size;
r += size;
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push((r - 1) >> i);
}
S sml = e(), smr = e();
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() { return d[1]; }
void apply(int p, F f) {
assert(0 <= p && p < _n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
d[p] = mapping(f, d[p]);
for (int i = 1; i <= log; i++) update(p >> i);
}
void apply(int l, int r, F f) {
assert(0 <= l && l <= r && r <= _n);
if (l == r) return;
l += size;
r += size;
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push((r - 1) >> i);
}
{
int l2 = l, r2 = r;
while (l < r) {
if (l & 1) all_apply(l++, f);
if (r & 1) all_apply(--r, f);
l >>= 1;
r >>= 1;
}
l = l2;
r = r2;
}
for (int i = 1; i <= log; i++) {
if (((l >> i) << i) != l) update(l >> i);
if (((r >> i) << i) != r) update((r - 1) >> i);
}
}
template <bool (*g)(S)> int max_right(int l) {
return max_right(l, [](S x) { return g(x); });
}
template <class G> int max_right(int l, G g) {
assert(0 <= l && l <= _n);
assert(g(e()));
if (l == _n) return _n;
l += size;
for (int i = log; i >= 1; i--) push(l >> i);
S sm = e();
do {
while (l % 2 == 0) l >>= 1;
if (!g(op(sm, d[l]))) {
while (l < size) {
push(l);
l = (2 * l);
if (g(op(sm, d[l]))) {
sm = op(sm, d[l]);
l++;
}
}
return l - size;
}
sm = op(sm, d[l]);
l++;
} while ((l & -l) != l);
return _n;
}
template <bool (*g)(S)> int min_left(int r) {
return min_left(r, [](S x) { return g(x); });
}
template <class G> int min_left(int r, G g) {
assert(0 <= r && r <= _n);
assert(g(e()));
if (r == 0) return 0;
r += size;
for (int i = log; i >= 1; i--) push((r - 1) >> i);
S sm = e();
do {
r--;
while (r > 1 && (r % 2)) r >>= 1;
if (!g(op(d[r], sm))) {
while (r < size) {
push(r);
r = (2 * r + 1);
if (g(op(d[r], sm))) {
sm = op(d[r], sm);
r--;
}
}
return r + 1 - size;
}
sm = op(d[r], sm);
} while ((r & -r) != r);
return 0;
}
private:
int _n, size, log;
std::vector<S> d;
std::vector<F> lz;
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
void all_apply(int k, F f) {
d[k] = mapping(f, d[k]);
if (k < size) lz[k] = composition(f, lz[k]);
}
void push(int k) {
all_apply(2 * k, lz[k]);
all_apply(2 * k + 1, lz[k]);
lz[k] = id();
}
};
} // namespace atcoder
using namespace std;
using ll = long long;
using i128 = __int128_t;
i128 op(i128 l, i128 r) { return l + r; }
i128 e() { return 0; }
i128 mapping(i128 l, i128 r) { return l * r; }
i128 composition(i128 l, i128 r) { return l * r; }
i128 id() { return 1; }
i128 target;
bool f(i128 x) { return x <= target; }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int n, q;
cin >> n >> q;
string S;
cin >> S;
vector<i128> init(n, 1);
atcoder::lazy_segtree<i128, op, e, i128, mapping, composition, id> seg(init);
auto calc = [&](i128 l, i128 r, int i) -> i128 {
i128 pre = seg.prod(0, i), cur = seg.get(i);
l -= pre;
r -= pre;
if (r <= 0 or cur <= l) return cur;
i128 c = min(cur, r) - max(i128(0), l);
return cur + c;
};
auto update = [&](ll l, ll r) {
target = l;
int p = seg.max_right<f>(0);
target = r;
int q = seg.max_right<f>(0);
if (p + 1 < q) seg.apply(p + 1, q, 2);
if (q < n) seg.set(q, calc(l, r, q));
if (p < n and p != q) seg.set(p, calc(l, r, p));
};
auto query = [&](i128 i) -> char {
target = i;
int p = seg.max_right<f>(0);
assert(p < n);
return S[p];
};
for (; q--;) {
int type;
cin >> type;
if (type == 1) {
ll l, r;
cin >> l >> r;
update(--l, r);
} else {
ll i;
cin >> i;
cout << query(--i) << "\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3524kb
input:
4 7 abac 2 2 2 3 1 2 3 2 3 2 4 2 5 2 6
output:
b a b a a c
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
5 4 shrek 1 1 2 2 7 1 1 7 2 7
output:
k h
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
4 7 abac 2 2 2 3 1 2 3 2 3 2 4 2 5 2 6
output:
b a b a a c
result:
ok 6 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
5 4 shrek 1 1 2 2 7 1 1 7 2 7
output:
k h
result:
ok 2 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
3 55 vfe 1 2 3 1 2 2 1 3 5 2 4 1 1 2 2 9 2 7 2 5 1 10 10 1 1 1 2 9 1 8 12 2 8 1 7 10 2 1 1 5 6 1 1 4 1 20 24 1 14 32 1 19 38 2 48 1 56 64 2 58 2 19 1 64 72 1 36 86 2 11 1 117 124 2 38 2 108 2 85 1 112 118 2 153 2 40 2 114 2 80 1 11 18 2 27 2 73 1 159 162 2 84 1 130 164 2 163 2 65 1 150 156 1 101 109...
output:
f e f f f f v f e f f f e e e f e e f e e e f e f e v
result:
ok 27 lines
Test #6:
score: -100
Runtime Error
input:
60 51 ranhfkbjhkxckkcbhgsspsjcbjgpwcfvmqqlvlfualndmqqsihsfdyqviowu 2 53 2 37 2 33 2 60 1 1 32 2 44 1 87 92 1 7 77 1 56 86 2 17 1 128 184 1 26 159 2 323 2 55 1 24 316 1 435 652 2 316 2 444 1 819 868 2 27 2 912 2 313 1 555 576 1 510 942 1 1118 1269 2 365 2 84 1 595 650 2 1468 2 258 1 1557 1607 2 938 1...