QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#551747 | #9242. An Easy Geometry Problem | ucup-team133# | WA | 907ms | 36264kb | C++23 | 13.0kb | 2024-09-07 17:58:16 | 2024-09-07 17:58:19 |
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
namespace hash_impl {
static constexpr unsigned long long mod = (1ULL << 61) - 1;
struct modint {
modint() : _v(0) {}
modint(unsigned long long v) {
v = (v >> 61) + (v & mod);
if (v >= mod) v -= mod;
_v = v;
}
unsigned long long val() const { return _v; }
modint& operator+=(const modint& rhs) {
_v += rhs._v;
if (_v >= mod) _v -= mod;
return *this;
}
modint& operator-=(const modint& rhs) {
if (_v < rhs._v) _v += mod;
_v -= rhs._v;
return *this;
}
modint& operator*=(const modint& rhs) {
__uint128_t t = __uint128_t(_v) * rhs._v;
t = (t >> 61) + (t & mod);
if (t >= mod) t -= mod;
_v = t;
return *this;
}
modint& operator/=(const modint& rhs) { return *this = *this * rhs.inv(); }
modint operator-() const { return modint() - *this; }
modint pow(long long n) const {
assert(0 <= n);
modint x = *this, r = 1;
while (n) {
if (n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
modint inv() const { return pow(mod - 2); }
friend modint operator+(const modint& lhs, const modint& rhs) { return modint(lhs) += rhs; }
friend modint operator-(const modint& lhs, const modint& rhs) { return modint(lhs) -= rhs; }
friend modint operator*(const modint& lhs, const modint& rhs) { return modint(lhs) *= rhs; }
friend modint operator/(const modint& lhs, const modint& rhs) { return modint(lhs) /= rhs; }
friend bool operator==(const modint& lhs, const modint& rhs) { return lhs._v == rhs._v; }
friend bool operator!=(const modint& lhs, const modint& rhs) { return lhs._v != rhs._v; }
friend std::ostream& operator<<(std::ostream& os, const modint& rhs) {
os << rhs._v;
return os;
}
private:
unsigned long long _v;
};
uint64_t generate_base() {
std::mt19937_64 mt(std::chrono::steady_clock::now().time_since_epoch().count());
std::uniform_int_distribution<uint64_t> rand(2, mod - 1);
return rand(mt);
}
modint base(generate_base());
std::vector<modint> power{1};
modint get_pow(int n) {
if (n < int(power.size())) return power[n];
int m = power.size();
power.resize(n + 1);
for (int i = m; i <= n; i++) power[i] = power[i - 1] * base;
return power[n];
}
}; // namespace hash_impl
struct Hash {
using mint = hash_impl::modint;
mint x;
int len;
Hash() : x(0), len(0) {}
Hash(mint x) : x(x), len(1) {}
Hash(mint x, int len) : x(x), len(len) {}
Hash& operator+=(const Hash& rhs) {
x = x * hash_impl::get_pow(rhs.len) + rhs.x;
len += rhs.len;
return *this;
}
Hash operator+(const Hash& rhs) const { return Hash(*this) += rhs; }
bool operator==(const Hash& rhs) const { return x == rhs.x and len == rhs.len; }
};
struct ReversibleHash {
using mint = hash_impl::modint;
mint x, rx;
int len;
ReversibleHash() : x(0), rx(0), len(0) {}
ReversibleHash(mint x) : x(x), rx(x), len(1) {}
ReversibleHash(mint x, mint rx, int len) : x(x), rx(rx), len(len) {}
ReversibleHash rev() const { return ReversibleHash(rx, x, len); }
ReversibleHash operator+=(const ReversibleHash& rhs) {
x = x * hash_impl::get_pow(rhs.len) + rhs.x;
rx = rx + rhs.rx * hash_impl::get_pow(len);
len += rhs.len;
return *this;
}
ReversibleHash operator+(const ReversibleHash& rhs) const { return ReversibleHash(*this) += rhs; }
bool operator==(const ReversibleHash& rhs) const { return x == rhs.x and rx == rhs.rx and len == rhs.len; }
};
using ll = long long;
using namespace std;
namespace hash_impl {
std::vector<modint> power_sum{0};
modint get_pow_sum(int n) {
if (n < int(power_sum.size())) return power_sum[n];
get_pow(n - 1);
int m = power_sum.size();
power_sum.resize(n + 1);
for (int i = m; i <= n; i++) power_sum[i] = power_sum[i - 1] + power[i - 1];
return power_sum[n];
}
} // namespace hash_impl
using mint = hash_impl::modint;
using S = ReversibleHash;
S op(S l, S r) { return l + r; }
S e() { return S(); }
S mapping(int l, S r) {
auto add = hash_impl::get_pow_sum(r.len);
if (l >= 0) {
add *= l;
} else {
add *= hash_impl::mod + l;
}
return S(r.x + add, r.rx + add, r.len);
}
int composition(int l, int r) { return l + r; }
int id() { return 0; }
const int THRESHOLD = 32;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int n, q, k, b;
cin >> n >> q >> k >> b;
vector<int> A(n);
cin >> A;
vector<S> init;
for (int i = 0; i < n; i++) {
if (A[i] >= 0) {
init.emplace_back(A[i]);
} else {
init.emplace_back(hash_impl::mod + A[i]);
}
}
atcoder::lazy_segtree<S, op, e, int, mapping, composition, id> seg(init);
auto update = [&](int l, int r, int v) -> void { seg.apply(l, r, v); };
vector<S> hashs{e()};
for (int i = 0; i < n; i++) {
int x = k * (i + 1) + b;
if (x >= 0) {
hashs.emplace_back(hashs.back() + S(x));
} else {
hashs.emplace_back(hashs.back() + S(hash_impl::mod + x));
}
}
auto check = [&](int i, int len) -> int {
if (len == 0) return true;
auto R = seg.prod(i + 1, i + len + 1).x;
auto L = seg.prod(i - len, i).rx;
return R - L == hashs[len].x;
};
auto query = [&](int i) -> int {
int lb = 0, ub = min(i, n - 1 - i) + 1;
if (check(i, ub - 1)) return ub - 1;
ub--;
if (not check(i, 1)) return 0;
lb++;
if (lb < THRESHOLD and THRESHOLD < ub) (check(i, THRESHOLD) ? lb : ub) = THRESHOLD;
if (ub - THRESHOLD > lb) (check(i, ub - THRESHOLD) ? lb : ub) = ub - THRESHOLD;
while (ub - lb > 1) {
int mid = (lb + ub) >> 1;
(check(i, mid) ? lb : ub) = mid;
}
return lb;
};
for (; q--;) {
int type;
cin >> type;
if (type == 1) {
int l, r, v;
cin >> l >> r >> v;
update(--l, r, v);
} else {
int i;
cin >> i;
cout << query(--i) << "\n";
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
input:
6 6 6 2 1 5 9 10 15 18 2 2 1 3 3 -3 2 2 1 3 4 3 2 3 2 4
output:
1 0 2 0
result:
ok 4 number(s): "1 0 2 0"
Test #2:
score: 0
Accepted
time: 23ms
memory: 4144kb
input:
5000 5000 2 0 -329 -328 -327 -326 -325 -324 -323 -322 -321 -320 -319 -318 -317 -316 -315 -314 -313 -312 -311 -310 -309 -308 -307 -306 -305 -304 -303 -302 -301 -300 -299 -298 -297 -296 -295 -294 -293 -292 -291 -290 -289 -288 -287 -286 -285 -284 -283 -282 -281 -280 -279 -278 -277 -276 -275 -274 -273 -...
output:
2 304 73 29 61 292 139 48 17 99 6 5 53 93 3 91 65 29 33 306 21 24 17 21 281 12 16 1 33 7 18 96 7 40 39 13 7 46 43 16 1 72 33 16 22 5 6 189 27 1 35 107 43 34 3 27 20 21 44 56 96 36 2 27 22 30 32 6 5 105 27 37 12 58 2 21 154 17 110 57 3 7 33 15 24 94 68 25 1 14 10 4 10 2 25 39 36 33 164 11 19 181 11 3...
result:
ok 3337 numbers
Test #3:
score: 0
Accepted
time: 28ms
memory: 4296kb
input:
5000 5000 2 0 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 86...
output:
362 82 14 234 140 5 44 136 22 43 29 96 59 23 25 61 193 22 39 39 23 53 48 76 100 58 120 24 12 106 32 48 73 63 116 16 136 10 28 15 84 30 65 1 54 15 16 70 1 95 74 14 17 20 36 254 22 29 70 172 106 2 25 8 98 35 169 16 2 2 99 10 36 40 3 69 272 170 219 12 79 26 78 100 10 167 140 70 34 17 23 21 55 10 6 17 6...
result:
ok 3313 numbers
Test #4:
score: 0
Accepted
time: 32ms
memory: 4220kb
input:
5000 5000 2 0 -456 -455 -454 -453 -452 -451 -450 -449 -448 -447 -446 -445 -444 -443 -442 -441 -440 -439 -438 -437 -436 -435 -434 -433 -432 -431 -430 -429 -428 -427 -426 -425 -424 -423 -422 -421 -420 -419 -418 -417 -416 -415 -414 -413 -412 -411 -410 -409 -408 -407 -406 -405 -404 -403 -402 -401 -400 -...
output:
8 75 80 408 385 73 37 402 338 43 11 163 3 7 80 0 339 47 384 8 10 47 162 307 30 28 36 14 27 126 271 151 4 11 11 9 92 154 2 15 28 160 205 12 59 79 114 23 22 141 7 12 31 42 120 0 34 2 167 157 76 32 20 298 47 104 76 33 49 34 1 40 16 1 28 7 4 55 14 8 68 17 7 117 1 14 14 80 44 8 45 49 65 15 49 56 50 40 14...
result:
ok 3296 numbers
Test #5:
score: 0
Accepted
time: 615ms
memory: 36264kb
input:
200000 199999 -195 -119 -267 -146 191 -456 835 265 -226 -264 160 -101 739 -988 -967 890 -753 -854 514 491 -733 662 681 -362 804 -714 -1000 -790 931 -450 212 94 239 638 400 -167 -360 18 606 256 445 695 -509 643 -892 213 -32 42 400 733 -667 -986 225 493 -699 547 409 -35 394 920 -163 -908 -576 921 -997...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 133315 numbers
Test #6:
score: 0
Accepted
time: 615ms
memory: 34280kb
input:
200000 200000 -847 -858 977 -248 439 -318 -623 -838 -996 484 415 -888 550 940 -880 -224 95 666 -898 -36 922 346 538 858 619 771 234 909 182 -577 -399 -793 -217 -150 -805 -22 -35 -818 342 -469 -620 778 855 -156 699 464 923 935 -824 315 -156 -222 55 282 -800 -542 192 -358 -158 79 259 -57 842 -882 -690...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 133062 numbers
Test #7:
score: 0
Accepted
time: 635ms
memory: 34076kb
input:
199994 199991 -131 936 -384 633 390 191 -647 79 -481 -95 -719 -131 -225 654 392 -232 390 -520 671 440 814 95 945 -854 477 304 -29 -884 -823 -798 -386 -404 614 -875 -792 -630 875 -379 -412 -464 805 -749 952 -737 -765 -36 295 -20 571 419 -519 763 505 803 -14 307 -979 955 743 -210 159 935 499 13 -750 -...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 133017 numbers
Test #8:
score: -100
Wrong Answer
time: 907ms
memory: 34144kb
input:
200000 200000 448 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
1 3 3 3 3 1 1 1 1 3 3 1 3 1 3 3 1 3 1 1 3 1 3 1 3 3 1 3 1 1 1 3 1 3 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 3 3 3 1 3 1 3 3 3 3 3 3 3 1 3 1 3 3 1 1 1 3 1 1 3 3 1 3 1 1 3 1 3 1 3 1 1 1 3 3 3 3 1 3 1 3 1 3 1 3 1 3 3 3 1 3 3 3 1 1 3 1 1 1 3 1 3 0 1 3 3 1 1 1 1 1 3 1 3 3 1 1 3 3 3 1 1 3 3 3 1 1 3 1 3 3 1 3 1 1 ...
result:
wrong answer 1st numbers differ - expected: '5388', found: '1'