QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#730316 | #9242. An Easy Geometry Problem | phuong2222 | WA | 18ms | 16028kb | C++20 | 4.3kb | 2024-11-09 19:42:55 | 2024-11-09 19:42:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
const lli maxN = 2e5 + 5;
const lli maxA = 5e6;
const lli base = 1e9 + 3;
const lli Mod = 1e9 + 7;
const lli Mod1 = 1000000111;
lli a[maxN],n,c,k,q,d[maxN],g[maxN],g1[maxN],f[maxN],f1[maxN];
lli st[4 * maxN],st1[4 * maxN];
lli modulo(lli a,lli b)
{
lli m = a,n = b,xm = 1,xn = 0,xr,r,q;
while (n != 0)
{
q = m / n;
r = m - q * n;
xr = xm - q * xn;
xm = xn;xn = xr;
m = n;n = r;
}
return xm;
}
void build(int id,int l,int r)
{
if (l == r)
{
st[id] = g[l - 1] * d[l] % Mod;
st1[id] = f[l - 1] * d[l] % Mod1;
return;
}
int mid = (l + r) / 2;
build(id * 2,l,mid);
build(id * 2 + 1,mid + 1,r);
st[id] = (st[id * 2] + st[id * 2 + 1]) % Mod;
st1[id] = (st1[id * 2] + st1[id * 2 + 1]) % Mod1;
}
void update(int id,int l,int r,int x,lli val)
{
if (x > r || x < l) return;
if (l == r)
{
st[id] = (st[id] + (val * g[l - 1] % Mod + Mod)) % Mod;
st1[id] = (st1[id] + (val * f[l - 1] % Mod1 + Mod1)) % Mod1;
return;
}
int mid = (l + r) / 2;
update(id * 2,l,mid,x,val);
update(id * 2 + 1,mid + 1,r,x,val);
st[id] = (st[id * 2] + st[id * 2 + 1]) % Mod;
st1[id] = (st1[id * 2] + st1[id * 2 + 1]) % Mod1;
}
lli get(int id,int l,int r,int u,int v)
{
if (l > v || r < u) return 0;
if (u <= l && r <= v) return st[id];
int mid = (l + r) / 2;
return (get(id * 2,l,mid,u,v) + get(id * 2 + 1,mid + 1,r,u,v)) % Mod;
}
lli get1(int id,int l,int r,int u,int v)
{
if (l > v || r < u) return 0;
if (u <= l && r <= v) return st1[id];
int mid = (l + r) / 2;
return (get1(id * 2,l,mid,u,v) + get1(id * 2 + 1,mid + 1,r,u,v)) % Mod1;
}
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) % Mod;
f1[0] = f[0] * (k + 2 * maxA) % Mod1;
for (int i = 1;i <= n;++i)
{
g[i] = (g[i - 1] * base) % Mod;
g1[i] = (g1[i - 1] + g[i] * (k + 2 * maxA % Mod) % Mod) % Mod;
f[i] = (f[i - 1] * base) % Mod1;
f1[i] = (f1[i - 1] + f[i] * (k + 2 * maxA % Mod1) % Mod1) % Mod1;
}
build(1,1,n - 1);
}
bool check(int r,int i)
{
lli h1 = get(1,1,n - 1,i + 1,i + r - 1) * ((modulo(g[i],Mod) % Mod + Mod) % Mod) % Mod;
lli h2 = get(1,1,n - 1,i - r,i - 2) * ((modulo(g[i - r - 1],Mod) % Mod + Mod) % Mod) % Mod;
lli h3 = get1(1,1,n - 1,i + 1,i + r - 1) * ((modulo(f[i],Mod1) % Mod1 + Mod1) % Mod1) % Mod1;
lli h4 = get1(1,1,n - 1,i - r,i - 2) * ((modulo(f[i - r - 1],Mod1) % Mod1 + Mod1) % Mod1) % Mod1;
//cout << (h1 + h2) % Mod << " " << g1[r - 2] << " " << r << " AAA\n";
return (((h1 + h2) % Mod == g1[r - 2]) && ((h4 + h3) % Mod == f1[r - 2]));
}
void solve()
{
//for (int j = 1;j <= n - 1;++j) cout << (((get(1,1,n - 1,j,j) * (modulo(g[j - 1],Mod) + Mod)) % Mod - maxA) % Mod + Mod) % Mod << "\n";
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(1,1,n - 1,x - 1,v);
update(1,1,n - 1,y,-v);
d[x - 1] += v;
d[y] -= v;
//cout << (((get(4,4) * (modulo(g[3],Mod) + Mod)) % Mod) % Mod + ((get(1,1) * (modulo(g[0],Mod) + Mod)) % Mod) % Mod) % 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: 15948kb
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: 18ms
memory: 16028kb
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 297 72 9 61 159 77 40 3 81 3 3 9 81 3 54 62 21 9 297 9 23 9 21 226 3 9 1 21 7 18 81 3 9 9 3 7 45 23 3 1 62 32 3 3 3 3 170 9 1 34 54 3 9 3 9 9 9 21 56 21 9 2 21 9 9 9 5 5 75 9 36 9 23 2 3 23 3 81 21 3 7 23 9 9 94 3 23 1 9 9 3 9 2 9 39 21 23 81 9 9 179 9 9 21 21 9 21 54 3 39 39 9 43 21 3 9 3 3 2 3 1...
result:
wrong answer 2nd numbers differ - expected: '304', found: '297'