QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#730463 | #9242. An Easy Geometry Problem | phuong2222 | WA | 2ms | 15984kb | C++20 | 3.3kb | 2024-11-09 20:20:29 | 2024-11-09 20:20:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using lli = unsigned long long;
const lli maxN = 2e5 + 5;
const lli maxA = 1e11;
const lli base = 1000000000003;
lli a[maxN],n,c,k,q,d[maxN],g[maxN],g1[maxN],f[maxN],f1[maxN];
lli st[2 * maxN],st1[2 * maxN];
void build()
{
for (int i = n;i <= (2 * n - 2);++i)
{
st[i] = d[i - n + 1] * g[i - n];
st1[i] = d[i - n + 1] * f[i - n];
}
for (int i = n - 1;i > 0;--i)
{
st[i] = (st[i << 1 | 1] + st[i << 1]);
st1[i] = (st1[i << 1 | 1] + st1[i << 1]);
}
}
void update(int i,lli val)
{
if (i == 0 || i == n) return;
i += (n - 1);
st[i] = ((st[i] + val * g[i - n]));
st1[i] = ((st1[i] + val * f[i - n]));
for (;i > 0;i >>= 1)
{
st[i >> 1] = ((st[i ^ 1] + st[i]));
st1[i >> 1] = ((st1[i ^ 1] + st1[i]));
}
}
lli get(int l,int r)
{
lli res = 0;
++r;
for (l += (n - 1),r += (n - 1);l < r;l >>= 1,r >>= 1)
{
if (l & 1) res = (res + st[l++]);
if (r & 1) res = (res + st[--r]);
}
return res;
}
lli get1(int l,int r)
{
lli res = 0;
++r;
for (l += (n - 1),r += (n - 1);l < r;l >>= 1,r >>= 1)
{
if (l & 1) res = (res + st1[l++]);
if (r & 1) res = (res + st1[--r]);
}
return res;
}
void input()
{
cin >> n >> q >> k >> c;
for (int i = 1;i <= n;++i)
{
cin >> a[i];
}
for (int i = 1;i < n;++i) d[i] = a[i + 1] - a[i] + maxA;
g[0] = 1;f[0] = 1;
g1[0] = g[0] * (k + 2 * maxA);
f1[0] = f[0] * (k + 2 * maxA);
for (int i = 1;i <= n;++i)
{
g[i] = (g[i - 1] * base);
g1[i] = (g1[i - 1] + g[i] * (k + 2 * maxA));
f[i] = (f[i - 1] * base);
f1[i] = (f1[i - 1] + f[i] * (k + 2 * maxA));
}
//cout << (g1[3] - g1[2]) << "\n";
build();
}
bool check(int r,int i)
{
lli h1 = get(i + 1,i + r - 1);
lli h2 = get(i - r,i - 2) * g[r + 1];
lli h3 = get1(i + 1,i + r - 1);
lli h4 = get1(i - r,i - 2) * f[r + 1];
return (((h1 + h2) == ((g1[i + r - 2] - g1[i - 1]))) && ((h3 + h4) == ((f1[i + r - 2] - f1[i - 1]))));
}
void solve()
{
for (int i = 1;i <= q;++i)
{
lli t,x,y,v;
cin >> t;
if (t == 2)
{
cin >> x;
if (d[x] + d[x - 1] != k + c + 2 * maxA) {cout << 0 << "\n";continue;}
int dist = min(x - 1,n - x);
int l = 2,r = dist,res = 1;
while (l <= r)
{
int mid = (l + r) / 2;
if (check(mid,x))
{
res = mid;
l = mid + 1;
}
else r = mid - 1;
}
cout << res << "\n";
}
else
{
cin >> x >> y >> v;
update(x - 1,v);
update(y,-v);
d[x - 1] += v;
d[y] -= v;
//cout << (((get(4,4) * (modulo(g[3],Mod)))) + ((get(1,1) * (modulo(g[0],Mod))))) << " " << g1[0] << "A ";
//cout << "\n";
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("C1.inp","r",stdin);
// freopen("C1.out","w",stdout);
input();
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 15924kb
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: 2ms
memory: 15984kb
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 349th numbers differ - expected: '25', found: '2'