QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#554255 | #9242. An Easy Geometry Problem | acceon128# | WA | 0ms | 6184kb | C++23 | 9.9kb | 2024-09-09 09:22:52 | 2024-09-09 09:22:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const unsigned long long MOD = 4179340454199820289;
template <unsigned long long M_> struct ModInt {
static constexpr unsigned long long M = M_;
long long x;
constexpr ModInt() : x(0ULL) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
constexpr ModInt operator++() { (*this) += 1; return *this; }
constexpr ModInt operator--() { (*this) -= 1; return *this; }
constexpr ModInt operator++(int) { const ModInt temp = *this; ++(*this); return temp; }
constexpr ModInt operator--(int) { const ModInt temp = *this; --(*this); return temp; }
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<__int128_t>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
return pow(MOD - 2);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0ULL; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
bool operator<(const ModInt &a) const { return (x < a.x); }
bool operator>(const ModInt &a) const { return (x > a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
friend std::istream &operator>>(std::istream &is, ModInt &a) { return is >> a.x; }
};
using Mint = ModInt<MOD>;
std::vector<Mint> P, SUM;
int BASE;
void hash_init(const int N) {
BASE = unsigned(std::chrono::steady_clock::now().time_since_epoch().count());
P = std::vector<Mint>(N + 1);
SUM = std::vector<Mint>(N + 2);
P.front() = 1;
for (int i = 1; i <= N; i++) {
P[i] = P[i - 1] * BASE;
}
for (int i = 0; i <= N; i++) {
SUM[i + 1] = SUM[i] + P[i];
}
}
struct hash_type {
Mint val;
int len;
hash_type() : val(0ULL), len(0) {}
hash_type(char c) : val(c), len(1) {}
hash_type(Mint _val, int _len) : val(_val), len(_len) {}
hash_type &operator+=(const hash_type &a) { val = val * P[a.len] + a.val; len += a.len; return *this; }
hash_type operator+(const hash_type &a) const { return (hash_type(*this) += a); }
bool operator==(const hash_type &a) const { return (val == a.val && len == a.len); }
bool operator!=(const hash_type &a) const { return (val != a.val || len != a.len); }
bool operator<(const hash_type &a) const { return (val == a.val ? len < a.len : val < a.val); }
bool operator>(const hash_type &a) const { return (val == a.val ? len > a.len : val > a.val); }
};
struct tag {
bool flg;
Mint sum;
tag() {
sum = 0;
flg = false;
}
tag(int x) {
sum = x;
flg = true;
}
void clear() {
sum = 0;
flg = false;
}
};
tag operator+(const tag &lhs, const tag &rhs) {
tag res;
res.flg = true;
res.sum = lhs.sum + rhs.sum;
return res;
}
struct info {
hash_type val;
info() {
}
info(int x) {
val = hash_type(x);
}
};
info operator+(const info &lhs, const info &rhs) {
info res;
res.val = lhs.val + rhs.val;
return res;
}
info operator+(const info &lhs, const tag &rhs) {
info res;
res.val = hash_type(lhs.val.val + SUM[lhs.val.len + 1] * rhs.sum, lhs.val.len);
return res;
}
struct LazyTagSegmentTree {
#define ls cur << 1
#define rs cur << 1 | 1
struct node {
int l, r;
info val;
tag lazy;
};
vector<node> tr;
void push_up(int cur) {
tr[cur].val = tr[ls].val + tr[rs].val;
}
void set_tag(int cur, tag t) {
tr[cur].lazy = tr[cur].lazy + t;
tr[cur].val = tr[cur].val + t;
}
void push_down(int cur) {
if (tr[cur].lazy.flg) {
set_tag(ls, tr[cur].lazy);
set_tag(rs, tr[cur].lazy);
tr[cur].lazy.clear();
}
}
void change(int cur, int pos, int val) {
if (tr[cur].l == tr[cur].r) {
tr[cur].val = info(val);
return;
}
push_down(cur);
int mid = (tr[cur].l + tr[cur].r) / 2;
if (pos <= mid) {
change(ls, pos, val);
} else {
change(rs, pos, val);
}
push_up(cur);
}
void change(int pos, int val) {
change(1, pos, val);
}
void modify(int cur, int l, int r, tag val) {
if (l <= tr[cur].l && tr[cur].r <= r) {
set_tag(cur, val);
return;
}
push_down(cur);
int mid = (tr[cur].l + tr[cur].r) / 2;
if (r <= mid) {
modify(ls, l, r, val);
} else if (l >= mid + 1) {
modify(rs, l, r, val);
} else {
modify(ls, l, r, val);
modify(rs, l, r, val);
}
push_up(cur);
}
void modify(int l, int r, tag val) {
if (l <= r) {
modify(1, l, r, val);
}
}
info query(int cur, int l, int r) {
if (l <= tr[cur].l && tr[cur].r <= r) {
return tr[cur].val;
}
push_down(cur);
int mid = (tr[cur].l + tr[cur].r) / 2;
if (r <= mid) {
return query(ls, l, r);
}
if (l >= mid + 1) {
return query(rs, l, r);
}
return query(ls, l, r) + query(rs, l, r);
}
info query(int l, int r) {
return query(1, l, r);
}
LazyTagSegmentTree(int n, int init = 0) {
tr = vector<node>(4 << __lg(n));
auto build = [&](auto &&self, int cur, int l, int r) -> void {
tr[cur].l = l;
tr[cur].r = r;
if (l == r) {
tr[cur].val = info(init);
return;
}
int mid = (l + r) / 2;
self(self, ls, l, mid);
self(self, rs, mid + 1, r);
push_up(cur);
};
build(build, 1, 0, n - 1);
}
LazyTagSegmentTree(auto &a) {
tr = vector<node>(4 << __lg(a.size()));
auto build = [&](auto &&self, int cur, int l, int r) -> void {
tr[cur].l = l;
tr[cur].r = r;
if (l == r) {
tr[cur].val = info(a[l]);
return;
}
int mid = (l + r) / 2;
self(self, ls, l, mid);
self(self, rs, mid + 1, r);
push_up(cur);
};
build(build, 1, 0, a.size() - 1);
}
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
hash_init(2e5);
int n, q, k, b;
cin >> n >> q >> k >> b;
k *= 2;
vector<int> a(n);
for (auto &i : a) {
cin >> i;
}
for (int i = 0, j = n - 1; i < n; i++, j--) {
a[j] += (i * k) / 2;
}
// for (auto i : a) {
// cout << i << ' ';
// }
// cout << '\n';
LazyTagSegmentTree S1(a);
ranges::reverse(a);
for (auto &i : a) {
i -= 2 * b;
}
LazyTagSegmentTree S2(a);
// for (auto i : a) {
// cout << i << ' ';
// }
// cout << '\n';
for (int tc = 0; tc < q; tc++) {
int op;
cin >> op;
if (op == 1) {
int l, r, v;
cin >> l >> r >> v;
l--; r--;
S1.modify(l, r, v);
S2.modify(n - 1 - r, n - 1 - l, v);
// for (int i = 0; i < n; i++) {
// cout << S1.query(i, i).val.val << ' ';
// }
// cout << '\n';
// for (int i = 0; i < n; i++) {
// cout << S2.query(i, i).val.val << ' ';
// }
// cout << '\n';
} else {
int x;
cin >> x;
x--;
auto check = [&](int val) {
if (x - val >= 0 && x + val < n) {
// x + 1...x + val
// x - val...x - 1
// n - 1 - (x - 1) ... n - 1 - (x - val)
// n - x ... n - 1 - x + val
return S1.query(x + 1, x + val).val == S2.query(n - x, n - 1 - x + val).val;
}
return false;
};
int l = 0, r = n;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (check(mid)) {
l = mid;
} else {
r = mid;
}
}
cout << l << '\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 6184kb
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 0 0
result:
wrong answer 3rd numbers differ - expected: '2', found: '0'