QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#584086 | #9242. An Easy Geometry Problem | hos_lyric | WA | 1214ms | 27004kb | C++14 | 10.9kb | 2024-09-23 08:12:59 | 2024-09-23 08:13:00 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
////////////////////////////////////////////////////////////////////////////////
// 2^61 - 1 = 2'305'843'009'213'693'951
struct ModLong61 {
static constexpr unsigned long long M = (1ULL << 61) - 1;
unsigned long long x;
constexpr ModLong61() : x(0ULL) {}
constexpr ModLong61(unsigned x_) : x(x_) {}
constexpr ModLong61(unsigned long long x_) : x(x_ % M) {}
constexpr ModLong61(int x_) : x((x_ < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
constexpr ModLong61(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModLong61 &operator+=(const ModLong61 &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModLong61 &operator-=(const ModLong61 &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModLong61 &operator*=(const ModLong61 &a) {
const unsigned __int128 y = static_cast<unsigned __int128>(x) * a.x;
x = (y >> 61) + (y & M);
x = (x >= M) ? (x - M) : x;
return *this;
}
ModLong61 &operator/=(const ModLong61 &a) { return (*this *= a.inv()); }
ModLong61 pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModLong61 a = *this, b = 1ULL; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModLong61 inv() const {
unsigned long long a = M, b = x; long long y = 0, z = 1;
for (; b; ) { const unsigned long long q = a / b; const unsigned long long c = a - q * b; a = b; b = c; const long long w = y - static_cast<long long>(q) * z; y = z; z = w; }
assert(a == 1ULL); return ModLong61(y);
}
ModLong61 operator+() const { return *this; }
ModLong61 operator-() const { ModLong61 a; a.x = x ? (M - x) : 0ULL; return a; }
ModLong61 operator+(const ModLong61 &a) const { return (ModLong61(*this) += a); }
ModLong61 operator-(const ModLong61 &a) const { return (ModLong61(*this) -= a); }
ModLong61 operator*(const ModLong61 &a) const { return (ModLong61(*this) *= a); }
ModLong61 operator/(const ModLong61 &a) const { return (ModLong61(*this) /= a); }
template <class T> friend ModLong61 operator+(T a, const ModLong61 &b) { return (ModLong61(a) += b); }
template <class T> friend ModLong61 operator-(T a, const ModLong61 &b) { return (ModLong61(a) -= b); }
template <class T> friend ModLong61 operator*(T a, const ModLong61 &b) { return (ModLong61(a) *= b); }
template <class T> friend ModLong61 operator/(T a, const ModLong61 &b) { return (ModLong61(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModLong61 &a) const { return (x == a.x); }
bool operator!=(const ModLong61 &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModLong61 &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////
#include <chrono>
#ifdef LOCAL
mt19937_64 rng(58);
#else
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#endif
const ModLong61 BASE = static_cast<unsigned long long>(rng());
////////////////////////////////////////////////////////////////////////////////
// T: monoid representing information of an interval.
// T() should return the identity.
// T(S s) should represent a single element of the array.
// T::push(T &l, T &r) should push the lazy update.
// T::pull(const T &l, const T &r) should pull two intervals.
template <class T> struct SegmentTreeRange {
int logN, n;
vector<T> ts;
SegmentTreeRange() : logN(0), n(0) {}
explicit SegmentTreeRange(int n_) {
for (logN = 0, n = 1; n < n_; ++logN, n <<= 1) {}
ts.resize(n << 1);
}
template <class S> explicit SegmentTreeRange(const vector<S> &ss) {
const int n_ = ss.size();
for (logN = 0, n = 1; n < n_; ++logN, n <<= 1) {}
ts.resize(n << 1);
for (int i = 0; i < n_; ++i) at(i) = T(ss[i]);
build();
}
T &at(int i) {
return ts[n + i];
}
void build() {
for (int u = n; --u; ) pull(u);
}
inline void push(int u) {
ts[u].push(ts[u << 1], ts[u << 1 | 1]);
}
inline void pull(int u) {
ts[u].pull(ts[u << 1], ts[u << 1 | 1]);
}
// Applies T::f(args...) to [a, b).
template <class F, class... Args>
void ch(int a, int b, F f, Args &&... args) {
assert(0 <= a); assert(a <= b); assert(b <= n);
if (a == b) return;
a += n; b += n;
for (int h = logN; h; --h) {
const int aa = a >> h, bb = b >> h;
if (aa == bb) {
if ((aa << h) != a || (bb << h) != b) push(aa);
} else {
if ((aa << h) != a) push(aa);
if ((bb << h) != b) push(bb);
}
}
for (int aa = a, bb = b; aa < bb; aa >>= 1, bb >>= 1) {
if (aa & 1) (ts[aa++].*f)(args...);
if (bb & 1) (ts[--bb].*f)(args...);
}
for (int h = 1; h <= logN; ++h) {
const int aa = a >> h, bb = b >> h;
if (aa == bb) {
if ((aa << h) != a || (bb << h) != b) pull(aa);
} else {
if ((aa << h) != a) pull(aa);
if ((bb << h) != b) pull(bb);
}
}
}
// Calculates the product for [a, b).
T get(int a, int b) {
assert(0 <= a); assert(a <= b); assert(b <= n);
if (a == b) return T();
a += n; b += n;
for (int h = logN; h; --h) {
const int aa = a >> h, bb = b >> h;
if (aa == bb) {
if ((aa << h) != a || (bb << h) != b) push(aa);
} else {
if ((aa << h) != a) push(aa);
if ((bb << h) != b) push(bb);
}
}
T prodL, prodR, t;
for (int aa = a, bb = b; aa < bb; aa >>= 1, bb >>= 1) {
if (aa & 1) { t.pull(prodL, ts[aa++]); prodL = t; }
if (bb & 1) { t.pull(ts[--bb], prodR); prodR = t; }
}
t.pull(prodL, prodR);
return t;
}
// Calculates T::f(args...) of a monoid type for [a, b).
// op(-, -) should calculate the product.
// e() should return the identity.
template <class Op, class E, class F, class... Args>
#if __cplusplus >= 201402L
auto
#else
decltype((std::declval<T>().*F())())
#endif
get(int a, int b, Op op, E e, F f, Args &&... args) {
assert(0 <= a); assert(a <= b); assert(b <= n);
if (a == b) return e();
a += n; b += n;
for (int h = logN; h; --h) {
const int aa = a >> h, bb = b >> h;
if (aa == bb) {
if ((aa << h) != a || (bb << h) != b) push(aa);
} else {
if ((aa << h) != a) push(aa);
if ((bb << h) != b) push(bb);
}
}
auto prodL = e(), prodR = e();
for (int aa = a, bb = b; aa < bb; aa >>= 1, bb >>= 1) {
if (aa & 1) prodL = op(prodL, (ts[aa++].*f)(args...));
if (bb & 1) prodR = op((ts[--bb].*f)(args...), prodR);
}
return op(prodL, prodR);
}
// Find min b s.t. T::f(args...) returns true,
// when called for the partition of [a, b) from left to right.
// Returns n + 1 if there is no such b.
template <class F, class... Args>
int findRight(int a, F f, Args &&... args) {
assert(0 <= a); assert(a <= n);
if ((T().*f)(args...)) return a;
if (a == n) return n + 1;
a += n;
for (int h = logN; h; --h) push(a >> h);
for (; ; a >>= 1) if (a & 1) {
if ((ts[a].*f)(args...)) {
for (; a < n; ) {
push(a);
if (!(ts[a <<= 1].*f)(args...)) ++a;
}
return a - n + 1;
}
++a;
if (!(a & (a - 1))) return n + 1;
}
}
// Find max a s.t. T::f(args...) returns true,
// when called for the partition of [a, b) from right to left.
// Returns -1 if there is no such a.
template <class F, class... Args>
int findLeft(int b, F f, Args &&... args) {
assert(0 <= b); assert(b <= n);
if ((T().*f)(args...)) return b;
if (b == 0) return -1;
b += n;
for (int h = logN; h; --h) push((b - 1) >> h);
for (; ; b >>= 1) if ((b & 1) || b == 2) {
if ((ts[b - 1].*f)(args...)) {
for (; b <= n; ) {
push(b - 1);
if (!(ts[(b <<= 1) - 1].*f)(args...)) --b;
}
return b - n - 1;
}
--b;
if (!(b & (b - 1))) return -1;
}
}
};
////////////////////////////////////////////////////////////////////////////////
using Mint = ModLong61;
struct Node {
Mint pw, sum;
Mint f, g;
Mint lz;
Node() : pw(1), sum(0), f(0), g(0) {}
Node(Mint val) : pw(BASE), sum(1), f(val), g(val) {}
void push(Node &l, Node &r) {
if (lz) {
l.add(lz);
r.add(lz);
lz = 0;
}
}
void pull(const Node &l, const Node &r) {
pw = l.pw * r.pw;
sum = l.sum + r.sum;
f = l.f + l.pw * r.f;
g = l.g * r.pw + r.g;
}
void add(Mint val) {
f += sum * val;
g += sum * val;
lz += val;
}
};
int N, Q;
Int K, B;
vector<Int> A;
int main() {
for (; ~scanf("%d%d%lld%lld", &N, &Q, &K, &B); ) {
A.resize(N);
for (int i = 0; i < N; ++i) {
scanf("%lld", &A[i]);
}
vector<Mint> tar(N + 1, 0);
{
Mint pw = 1;
for (int i = 0; i < N; ++i) {
tar[i + 1] = tar[i] + pw * (K * (i + 1) + B);
pw *= BASE;
}
}
SegmentTreeRange<Node> seg(A);
for (; Q--; ) {
int O;
scanf("%d", &O);
if (O == 1) {
int L, R;
Int V;
scanf("%d%d%lld", &L, &R, &V);
--L;
seg.ch(L, R, &Node::add, V);
} else if (O == 2) {
int I;
scanf("%d", &I);
--I;
int lo = 0, hi = min(I, N - 1 - I) + 1;
for (; lo + 1 < hi; ) {
const int mid = (lo + hi) / 2;
const auto g = seg.get(I - mid, I).g;
const auto f = seg.get(I + 1, I + 1 + mid).f;
((f - g == tar[mid]) ? lo : hi) = mid;
}
printf("%d\n", lo);
} else {
assert(false);
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4028kb
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: 6ms
memory: 3928kb
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: 9ms
memory: 4016kb
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: 9ms
memory: 3936kb
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: 1214ms
memory: 27004kb
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: 1191ms
memory: 26840kb
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: 1210ms
memory: 26824kb
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: 0
Accepted
time: 485ms
memory: 26876kb
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:
5388 1796 9803 17353 10388 6660 29833 1132 10416 3492 28995 2953 5964 9845 4293 158 931 30 224 7765 7894 2412 21159 21128 8630 4778 3830 1241 3750 795 5013 529 2176 2266 566 194 2702 4520 2348 1577 6922 372 895 667 650 5530 8798 670 2806 2395 1525 4602 1558 1278 1635 5413 2804 1167 731 3000 1663 529...
result:
ok 79952 numbers
Test #9:
score: -100
Wrong Answer
time: 436ms
memory: 15020kb
input:
100000 100000 2 0 -866 890 -406 10 512 859 494 362 -955 -475 128 553 -986 -885 763 77 449 310 787 -656 -204 -709 -270 76 -267 184 170 -985 33 -822 666 418 26 -247 898 -104 85 -146 980 631 359 908 -560 -744 -764 836 -103 -531 -116 316 681 -148 226 206 -439 -961 -792 598 -629 -705 -479 -494 -169 608 -...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 87 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1...
result:
wrong answer 1st numbers differ - expected: '5945', found: '1'