QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#554164 | #9242. An Easy Geometry Problem | ucup-team4757 | WA | 8ms | 10056kb | C++14 | 4.0kb | 2024-09-09 08:10:06 | 2024-09-09 08:10:06 |
Judging History
answer
#include <bits/stdc++.h>
const int MAXN = 100005;
const int32_t base = 31;
int32_t n, q, k, b;
int32_t a[MAXN], c[MAXN], d[MAXN];
uint64_t p[MAXN], w[MAXN];
namespace Segtree1 {
struct node {
int32_t len;
uint64_t hsh;
inline node operator + (const node & a) const {
return {len + a.len, hsh * w[a.len] + a.hsh};
}
} T[MAXN << 2];
#define LC (x << 1)
#define RC (x << 1 | 1)
#define m ((l + r) >> 1)
inline void Build (const int32_t l = 1, const int32_t r = n, const int32_t x = 1) {
T[x].len = r - l + 1;
if (l == r) return T[x].hsh = c[l], void ();
Build (l, m, LC), Build (m + 1, r, RC), T[x] = T[LC] + T[RC];
}
inline void Modify (const int32_t p, const int32_t val, const int32_t l = 1, const int32_t r = n, const int32_t x = 1) {
if (l == r) return T[x].hsh += val, void ();
p <= m ? Modify (p, val, l, m, LC) : Modify (p, val, m + 1, r, RC); T[x] = T[LC] + T[RC];
}
inline node Sum (const int32_t L, const int32_t R, const int32_t l = 1, const int32_t r = n, const int32_t x = 1) {
// std::cerr << L << ' ' << R << ' ' << l << ' ' << r << ' ' << T[x].hsh << '\n';
if (L <= l && r <= R) return T[x];
if (L <= m && R > m) return Sum (L, R, l, m, LC) + Sum (L, R, m + 1, r, RC);
if (L <= m) return Sum (L, R, l, m, LC);
if (R > m) return Sum (L, R, m + 1, r, RC);
return (node) {0, 0};
}
}
namespace Segtree2 {
struct node {
int32_t len;
uint64_t hsh;
inline node operator + (const node & a) const {
return {len + a.len, a.hsh * w[len] + hsh};
}
} T[MAXN << 2];
#define LC (x << 1)
#define RC (x << 1 | 1)
#define m ((l + r) >> 1)
inline void Build (const int32_t l = 1, const int32_t r = n, const int32_t x = 1) {
T[x].len = r - l + 1;
if (l == r) return T[x].hsh = d[l], void ();
Build (l, m, LC), Build (m + 1, r, RC), T[x] = T[LC] + T[RC];
}
inline void Modify (const int32_t p, const int32_t val, const int32_t l = 1, const int32_t r = n, const int32_t x = 1) {
if (l == r) return T[x].hsh += val, void ();
p <= m ? Modify (p, val, l, m, LC) : Modify (p, val, m + 1, r, RC); T[x] = T[LC] + T[RC];
}
inline node Sum (const int32_t L, const int32_t R, const int32_t l = 1, const int32_t r = n, const int32_t x = 1) {
if (L <= l && r <= R) return T[x];
if (L <= m && R > m) return Sum (L, R, l, m, LC) + Sum (L, R, m + 1, r, RC);
if (L <= m) return Sum (L, R, l, m, LC);
if (R > m) return Sum (L, R, m + 1, r, RC);
return {0, 0};
}
}
int32_t opt, l, r, x, val, ans;
int main () {
std::ios::sync_with_stdio (0);
std::cin.tie (0), std::cout.tie (0);
std::cin >> n >> q >> k >> b, w[0] = 1;
for (int i = 1; i <= n; ++ i)
std::cin >> a[i];
for (int i = 1; i <= n; ++ i)
c[i] = a[i] - a[i - 1], d[i] = a[i] - a[i + 1];
for (int i = 1; i <= n; ++ i)
w[i] = w[i - 1] * base;
p[1] = k + b;
for (int i = 2; i <= n; ++ i)
p[i] = p[i - 1] * base + k;
Segtree1::Build (1, n), Segtree2::Build (1, n);
for (int i = 1; i <= q; ++ i) {
std::cin >> opt;
if (opt == 1) std::cin >> l >> r >> val;
if (opt == 2) std::cin >> x;
if (opt == 1) {
c[l] += val, c[r + 1] -= val;
d[l - 1] -= val, d[r] += val;
Segtree1::Modify (l, + val), Segtree1::Modify (r + 1, - val);
Segtree2::Modify (l - 1, - val), Segtree2::Modify (r, + val);
} else {
l = 1, r = std::min (x, n - x), ans = 0;
// std::cerr << p[3] << ' ' << Segtree1::Sum (x + 1, x + 3).hsh << '\n';
if (l == r)
ans = (Segtree1::Sum (x + 1, x + l).hsh - Segtree2::Sum (x - l, x - 1).hsh == p[m]) * l;
while (l <= r) {
// std::cerr << i << ' ' << l << ' ' << r << ' ' << m << ' ' << Segtree1::Sum (x + 1, x + m).hsh - Segtree2::Sum (x - m, x - 1).hsh << ' ' << p[m] << '\n';
if (Segtree1::Sum (x + 1, x + m).hsh - Segtree2::Sum (x - m, x - 1).hsh == p[m]) ans = m, l = m + 1;
else r = m - 1;
}
std::cout << ans << '\n';
// std::cerr << now << ' ' << p[1] << '\n';
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 9840kb
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: -100
Wrong Answer
time: 8ms
memory: 10056kb
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:
wrong answer 2631st numbers differ - expected: '0', found: '1'