1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
| #include <bits/stdc++.h>
using i64 = long long;
template <class T> constexpr T power(T a, i64 b) { T res = 1; for (; b; b /= 2, a *= a) { if (b % 2) { res *= a; } } return res; }
constexpr i64 mul(i64 a, i64 b, i64 p) { i64 res = a * b - i64(1.L * a * b / p) * p; res %= p; if (res < 0) { res += p; } return res; } template <i64 P> struct MLong { i64 x; constexpr MLong() : x{} { } constexpr MLong(i64 x) : x{norm(x % getMod())} { }
static i64 Mod; constexpr static i64 getMod() { if (P > 0) { return P; } else { return Mod; } } constexpr static void setMod(i64 Mod_) { Mod = Mod_; } constexpr i64 norm(i64 x) const { if (x < 0) { x += getMod(); } if (x >= getMod()) { x -= getMod(); } return x; } constexpr i64 val() const { return x; } explicit constexpr operator i64() const { return x; } constexpr MLong operator-() const { MLong res; res.x = norm(getMod() - x); return res; } constexpr MLong inv() const { assert(x != 0); return power(*this, getMod() - 2); } constexpr MLong &operator*=(MLong rhs) & { x = mul(x, rhs.x, getMod()); return *this; } constexpr MLong &operator+=(MLong rhs) & { x = norm(x + rhs.x); return *this; } constexpr MLong &operator-=(MLong rhs) & { x = norm(x - rhs.x); return *this; } constexpr MLong &operator/=(MLong rhs) & { return *this *= rhs.inv(); } friend constexpr MLong operator*(MLong lhs, MLong rhs) { MLong res = lhs; res *= rhs; return res; } friend constexpr MLong operator+(MLong lhs, MLong rhs) { MLong res = lhs; res += rhs; return res; } friend constexpr MLong operator-(MLong lhs, MLong rhs) { MLong res = lhs; res -= rhs; return res; } friend constexpr MLong operator/(MLong lhs, MLong rhs) { MLong res = lhs; res /= rhs; return res; } friend constexpr std::istream &operator>>(std::istream &is, MLong &a) { i64 v; is >> v; a = MLong(v); return is; } friend constexpr std::ostream &operator<<(std::ostream &os, const MLong &a) { return os << a.val(); } friend constexpr bool operator==(MLong lhs, MLong rhs) { return lhs.val() == rhs.val(); } friend constexpr bool operator!=(MLong lhs, MLong rhs) { return lhs.val() != rhs.val(); } };
template <> i64 MLong<0LL>::Mod = i64(1E18) + 9;
template <int P> struct MInt { int x; constexpr MInt() : x{} { } constexpr MInt(i64 x) : x{norm(x % getMod())} { }
static int Mod; constexpr static int getMod() { if (P > 0) { return P; } else { return Mod; } } constexpr static void setMod(int Mod_) { Mod = Mod_; } constexpr int norm(int x) const { if (x < 0) { x += getMod(); } if (x >= getMod()) { x -= getMod(); } return x; } constexpr int val() const { return x; } explicit constexpr operator int() const { return x; } constexpr MInt operator-() const { MInt res; res.x = norm(getMod() - x); return res; } constexpr MInt inv() const { assert(x != 0); return power(*this, getMod() - 2); } constexpr MInt &operator*=(MInt rhs) & { x = 1LL * x * rhs.x % getMod(); return *this; } constexpr MInt &operator+=(MInt rhs) & { x = norm(x + rhs.x); return *this; } constexpr MInt &operator-=(MInt rhs) & { x = norm(x - rhs.x); return *this; } constexpr MInt &operator/=(MInt rhs) & { return *this *= rhs.inv(); } friend constexpr MInt operator*(MInt lhs, MInt rhs) { MInt res = lhs; res *= rhs; return res; } friend constexpr MInt operator+(MInt lhs, MInt rhs) { MInt res = lhs; res += rhs; return res; } friend constexpr MInt operator-(MInt lhs, MInt rhs) { MInt res = lhs; res -= rhs; return res; } friend constexpr MInt operator/(MInt lhs, MInt rhs) { MInt res = lhs; res /= rhs; return res; } friend constexpr std::istream &operator>>(std::istream &is, MInt &a) { i64 v; is >> v; a = MInt(v); return is; } friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a) { return os << a.val(); } friend constexpr bool operator==(MInt lhs, MInt rhs) { return lhs.val() == rhs.val(); } friend constexpr bool operator!=(MInt lhs, MInt rhs) { return lhs.val() != rhs.val(); } };
template <> int MInt<0>::Mod = 1E9 + 7;
template <int V, int P> constexpr MInt<P> CInv = MInt<P>(V).inv();
constexpr int P = 1E9 + 7; using Z = MInt<P>; constexpr int mod1 = 998244353;
std::vector<Z> p, pre;
struct Info { Z v = 0; int len = 0; Info() { v = 0; len = 0; } };
struct Tag { int add = 0; };
Info operator+(const Info &a, const Info &b) { Info res; res.len = a.len + b.len; res.v = a.v * p[b.len] + b.v; return res; }
void apply(Info &x, Tag &a, Tag f) { x.v = x.v + pre[x.len - 1] * f.add; a.add += f.add; }
template <class Info, class Tag> struct LazySegmentTree { int n; std::vector<Info> info; std::vector<Tag> tag;
LazySegmentTree() { }
LazySegmentTree(int n, Info _init = Info()) { init(std::vector<Info>(n, _init)); }
LazySegmentTree(const std::vector<Info> &_init) { init(_init); }
void init(const std::vector<Info> &_init) { n = (int)_init.size(); info.assign((n << 2) + 1, Info()); tag.assign((n << 2) + 1, Tag()); std::function<void(int, int, int)> build = [&](int p, int l, int r) { if (l == r) { info[p] = _init[l - 1]; return; } int m = (l + r) / 2; build(2 * p, l, m); build(2 * p + 1, m + 1, r); pull(p); }; build(1, 1, n); }
void pull(int p) { info[p] = info[2 * p] + info[2 * p + 1]; }
void apply(int p, const Tag &v) { ::apply(info[p], tag[p], v); }
void push(int p) { apply(2 * p, tag[p]); apply(2 * p + 1, tag[p]); tag[p] = Tag(); }
void modify(int p, int l, int r, int x, const Info &v) { if (l == r) { info[p] = v; return; } int m = (l + r) / 2; push(p); if (x <= m) { modify(2 * p, l, m, x, v); } else { modify(2 * p + 1, m + 1, r, x, v); } pull(p); }
void modify(int p, const Info &v) { modify(1, 1, n, p, v); }
Info query(int p, int l, int r, int x, int y) { if (l > y || r < x) { return Info(); } if (l >= x && r <= y) { return info[p]; } int m = (l + r) / 2; push(p); return query(2 * p, l, m, x, y) + query(2 * p + 1, m + 1, r, x, y); }
Info query(int l, int r) { return query(1, 1, n, l, r); }
void modify(int p, int l, int r, int x, int y, const Tag &v) { if (l > y || r < x) { return; } if (l >= x && r <= y) { apply(p, v); return; } int m = (l + r) / 2; push(p); modify(2 * p, l, m, x, y, v); modify(2 * p + 1, m + 1, r, x, y, v); pull(p); }
void modify(int l, int r, const Tag &v) { return modify(1, 1, n, l, r, v); } };
void solve() { int n, q, k, b; std::cin >> n >> q >> k >> b; p.assign(n + 1, 0); pre.assign(n + 1, 0); p[0] = 1; pre[0] = 1; for (int i = 1; i <= n; i++) { p[i] = p[i - 1] * mod1; pre[i] = pre[i - 1] + p[i]; } std::vector<int> a(n + 1); for (int i = 1; i <= n; i++) { std::cin >> a[i]; } std::vector<Info> init1(n); for (int i = 1; i <= n; i++) { init1[i - 1].v = 2 * a[i] - k * i; init1[i - 1].len = 1; } LazySegmentTree<Info, Tag> segpre(init1); std::vector<Info> init2(n); for (int i = n; i > 0; i--) { init2[n - i].v = 2 * a[i] - k * i - 2 * b; init2[n - i].len = 1; } LazySegmentTree<Info, Tag> segsf(init2);
while (q--) { int op; std::cin >> op; if (op == 1) { int l, r, v; std::cin >> l >> r >> v; Tag tag{2 * v}; segpre.modify(l, r, tag); segsf.modify(n - r + 1, n - l + 1, tag); } else { int i; std::cin >> i; int l = 0, r = std::min(n - i, i - 1); while (l < r) { int mid = l + r + 1 >> 1; Info respre = segpre.query(i - mid, i - 1); Info ressf = segsf.query(n - (i + mid) + 1, n - (i + 1) + 1); if (respre.v == ressf.v) { l = mid; } else { r = mid - 1; } } std::cout << l << "\n"; } } }
int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
int t = 1; while (t--) solve();
return 0; }
|