QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#567467 | #9242. An Easy Geometry Problem | ucup-team3519 | WA | 5ms | 7004kb | C++20 | 4.4kb | 2024-09-16 12:09:23 | 2024-09-16 12:09:24 |
Judging History
answer
#pragma GCC O(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pi;
#define V vector
#define fi first
#define se second
#define pb push_back
#define all1(x) (x).begin() + 1, (x).end()
const int MN = 2e5 + 1000;
const LL mod = 444445555566666677;
const int base = 233;
LL pbase[MN];
LL tot1[MN];
LL mul(LL a, LL b) {
LL res = a * b - LL(1.L * a * b / mod) * mod;
res %= mod;
if (res < 0) {
res += mod;
}
return res;
}
LL posi(LL x) {
if(x < 0) x += mod;
return x;
}
LL add(LL a, LL b) {
LL ans = a + b;
if(ans >= mod) ans -= mod;
return ans;
}
LL MOD(LL x) {
if(x < 0) return x + mod;
if(x >= mod) return x - mod;
return x;
}
struct node {
LL hs, rhs;
LL tag, len;
}seg[MN * 4];
void upd(int x) {
seg[x].hs = MOD(seg[x * 2].hs + mul(pbase[seg[x * 2 + 1].len], seg[x * 2 + 1].hs));
seg[x].rhs = MOD(seg[x * 2 + 1].rhs + mul(pbase[seg[x * 2].len], seg[x * 2].rhs));
seg[x].len = seg[x * 2].len + seg[x * 2 + 1].len;
}
void apply(int x, LL t) {
seg[x].hs = MOD(seg[x].hs + mul(t, tot1[seg[x].len]));
seg[x].rhs = MOD(seg[x].rhs + mul(t, tot1[seg[x].len]));
seg[x].tag += t;
}
void push_down(int x) {
if(seg[x].tag == 0) return;
apply(x * 2, seg[x].tag);
apply(x * 2 + 1, seg[x].tag);
seg[x].tag = 0;
}
void build(V<int> v) {
int n = v.size() - 1;
auto dfs = [&](int x, int l, int r, auto dfs) -> void {
if(l == r) {
seg[x].hs = seg[x].rhs = mul(v[l], base);
seg[x].len = 1;
}
else {
int mid = l + r >> 1;
dfs(x * 2, l, mid, dfs), dfs(x * 2 + 1, mid + 1, r, dfs);
upd(x);
}
};
dfs(1, 1, n, dfs);
}
LL query_hs(int x, int l, int r, int ql, int qr) {
if(ql <= l && qr >= r) {
return seg[x].hs;
}
int mid = l + r >> 1;
push_down(x);
LL ans = 0;
int len = 0;
if(ql <= mid) ans += query_hs(x * 2, l, mid, ql, qr), len = mid - l + 1;
if(qr >= mid + 1) ans = MOD(ans + mul(query_hs(x * 2 + 1, mid + 1, r, ql, qr), pbase[len]));
return ans;
}
LL query_rhs(int x, int l, int r, int ql, int qr) {
if(ql <= l && qr >= r) {
return seg[x].rhs;
}
int mid = l + r >> 1;
push_down(x);
LL ans = 0;
int len = 0;
if(qr >= mid + 1)
ans += query_hs(x * 2 + 1, mid + 1, r, ql, qr), len = r - mid;
if(ql <= mid)
ans = MOD(ans + mul(query_hs(x * 2, l, mid, ql, qr), pbase[len]));
return ans;
}
void modify(int x, int l, int r, int ql, int qr, LL t) {
if(ql <= l && qr >= r) {
apply(x, t);
return;
}
int mid = l + r >> 1;
push_down(x);
if(ql <= mid) modify(x * 2, l, mid, ql, qr, t);
if(qr >= mid + 1) modify(x * 2 + 1, mid + 1, r, ql, qr, t);
upd(x);
}
void solve() {
int n; cin >> n;
int q; cin >> q;
int k, b; cin >> k >> b;
V<int> a(n + 1);
V<LL> should(n + 1);
should[0] = 0;
for(int i = 1; i <= n; i++) should[i] = add(mul(posi(k * i + b), pbase[i]), should[i - 1]);
for(int i = 1; i <= n; i++) cin >> a[i];
V<int> ini_tree(n + 1);
for(int i = 1; i <= n; i++) {
ini_tree[i] = a[i];
}
build(ini_tree);
for(int i = 1; i <= q; i++) {
int t; cin >> t;
if(t == 1) {
int l, r, v; cin >> l >> r >> v;
modify(1, 1, n, l, r, {v});
} else {
int i; cin >> i;
int l = 0, r = i;
while(l != r - 1) {
int mid = l + r >> 1;
bool ok;
int len = i - mid;
if(2 * i - mid > n) ok = 0;
else {
LL hs1 = query_rhs(1, 1, n, mid, i - 1);
LL hs2 = query_hs(1, 1, n, i + 1, 2 * i - mid);
if(add(mod - hs1, hs2) == should[len]) ok = 1;
else ok = 0;
}
if(ok) r = mid;
else l = mid;
}
cout << i - r << "\n";
}
}
}
int main() {
pbase[0] = 1;
for(int i = 1; i <= 2e5 + 10; i++) pbase[i] = mul(pbase[i - 1], base);
tot1[0] = 0;
for(int i = 1; i <= 2e5 + 10; i++) tot1[i] = add(tot1[i - 1], pbase[i]);
ios::sync_with_stdio(0), cin.tie(0);
// int t; cin >> t;
int t = 1;
while(t--) solve();
}
详细
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 7004kb
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 1 0
result:
wrong answer 3rd numbers differ - expected: '2', found: '1'