QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#730328#9242. An Easy Geometry Problemphuong2222WA 15ms15884kbC++204.0kb2024-11-09 19:47:402024-11-09 19:47:41

Judging History

你现在查看的是最新测评结果

  • [2024-11-09 19:47:41]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:15884kb
  • [2024-11-09 19:47:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using lli = long long;
const lli maxN = 2e5 + 5;
const lli maxA = 0;
const lli base = 4e5 + 9;
const lli Mod = 1e9 + 7;
const lli Mod1 = 998244353;
lli a[maxN],n,c,k,q,d[maxN],g[maxN],g1[maxN],f[maxN],f1[maxN];
lli st[2 * maxN],st1[2 * 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()
{
    for (int i = n;i <= (2 * n - 2);++i)
    {
        st[i] = d[i - n + 1] * g[i - n] % Mod;
        st1[i] = d[i - n + 1] * f[i - n] % Mod1;
    }
    for (int i = n - 1;i > 0;--i)
    {
        st[i] = (st[i << 1 | 1] + st[i << 1]) % Mod;
        st1[i] = (st1[i << 1 | 1] + st1[i << 1]) % Mod1;
    }
}
void update(int i,lli val)
{
    if (i == 0) return;
    i += (n - 1);
    st[i] = ((st[i] + val * g[i - n]) % Mod + Mod) % Mod;
    st1[i] = ((st1[i] + val * f[i - n]) % Mod1 + Mod1) % Mod1;
    for (;i > 0;i >>= 1)
    {
        st[i >> 1] = ((st[i ^ 1] + st[i]) % Mod + Mod) % Mod;
        st1[i >> 1] = ((st1[i ^ 1] + st1[i]) % Mod1 + Mod1) % Mod1;
    }
}
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++]) % Mod;
        if (r & 1) res = (res + st[--r]) % Mod;
    }
    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++]) % Mod1;
        if (r & 1) res = (res + st1[--r]) % Mod1;
    }
    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) % 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();
}
bool check(int r,int i)
{
    lli h1 = get(i + 1,i + r - 1) * ((modulo(g[i],Mod) % Mod + Mod) % Mod) % Mod;
    lli h2 = get(i - r,i - 2) * ((modulo(g[i - r - 1],Mod) % Mod + Mod) % Mod) % Mod;
    lli h3 = get1(i + 1,i + r - 1) * ((modulo(f[i],Mod1) % Mod1 + Mod1) % Mod1) % Mod1;
    lli h4 = get1(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 (((h3 + h4) % Mod1 == f1[r - 2]) && ((h1 + h2) % Mod == g1[r - 2]));
}
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) + 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: 15884kb

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: 15ms
memory: 14000kb

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'