QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682715#9242. An Easy Geometry Problemlouhao088WA 3ms30380kbC++233.8kb2024-10-27 17:03:482024-10-27 17:03:49

Judging History

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

  • [2024-10-27 17:03:49]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:30380kb
  • [2024-10-27 17:03:48]
  • 提交

answer

#include<vector>
#include<cstdio>
#include<queue>
#define ull unsigned long long
#define di1 131
#define di2 13331

using namespace std;

const int N = 2e5 + 100;
int n, q, k, b, a[N];
ull ds1[N], ds2[N];

struct XD_tree {
    int sz[N << 2];
    pair <ull, ull> f[N << 2], g[N << 2];

    void up(int now) {
        f[now].first = f[now << 1].first * ds1[sz[now << 1 | 1]] + f[now << 1 | 1].first;
        f[now].second = f[now << 1].second * ds2[sz[now << 1 | 1]] + f[now << 1 | 1].second;

        g[now].first = g[now << 1 | 1].first * ds1[sz[now << 1]] + g[now << 1].first;
        g[now].second = g[now << 1 | 1].second * ds2[sz[now << 1]] + g[now << 1].second;
    }

    void build(int now, int l, int r) {
        sz[now] = r - l + 1;
        if (l == r) {
            f[now] = g[now] = make_pair(a[l] - a[l - 1], a[l] - a[l - 1]);
            return ;
        }
        int mid = (l + r) >> 1;
        build(now << 1, l, mid); build(now << 1 | 1, mid + 1, r);
        up(now);
    }

    void insert(int now, int l, int r, int x, int val) {
        if (l == r) {
            f[now].first += val; f[now].second += val;
            g[now].first += val; g[now].second += val;
            return ;
        }
        int mid = (l + r) >> 1;
        if (x <= mid) insert(now << 1, l, mid, x, val);
            else insert(now << 1 | 1, mid + 1, r, x, val);
        up(now);
    }

    pair <ull, ull> queryf(int now, int l, int r, int L, int R) {
        if (L <= l && r <= R) return f[now];
        int mid = (l + r) >> 1;
        if (L > mid) return queryf(now << 1 | 1, mid + 1, r, L, R);
        if (mid >= R) return queryf(now << 1, l, mid, L, R);
        pair <ull, ull> re1 = queryf(now << 1, l, mid, L, R);
        pair <ull, ull> re2 = queryf(now << 1 | 1, mid + 1, r, L, R);
        return make_pair(re1.first * ds1[R - mid] + re2.first, re1.second * ds2[R - mid] + re2.second);
    }

    pair <ull, ull> queryg(int now, int l, int r, int L, int R) {
        if (L <= l && r <= R) return g[now];
        int mid = (l + r) >> 1;
        if (L > mid) return queryg(now << 1 | 1, mid + 1, r, L, R);
        if (mid >= R) return queryg(now << 1, l, mid, L, R);
        pair <ull, ull> re1 = queryg(now << 1, l, mid, L, R);
        pair <ull, ull> re2 = queryg(now << 1 | 1, mid + 1, r, L, R);
        return make_pair(re2.first * ds1[mid - L + 1] + re1.first, re2.second * ds2[mid - L + 1] + re1.second);
    }
}T;

pair <ull, ull> operator +(pair <ull, ull> a, pair <ull, ull> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

int main() {
    scanf("%d %d %d %d", &n, &q, &k, &b);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), a[i] = 2 * a[i] - k * i;

    ds1[0] = 1; ds2[0] = 1;
    for (int i = 1; i <= n; i++) ds1[i] = ds1[i - 1] * di1;
    for (int i = 1; i <= n; i++) ds2[i] = ds2[i - 1] * di2;
    T.build(1, 1, n);

    while (q--) {
        int op; scanf("%d", &op);
        if (op == 1) {
            int l, r, v; scanf("%d %d %d", &l, &r, &v); v = v * 2;
            T.insert(1, 1, n, l, v);
            if (r < n) T.insert(1, 1, n, r + 1, -v);
        }
        if (op == 2) {
            int x; scanf("%d", &x);
            if (x == 1 || x == n) {printf("0\n"); continue;}
            if ((T.queryf(1, 1, n, x, x) + T.queryf(1, 1, n, x + 1, x + 1)) != make_pair((ull)2 * b, (ull)2 * b)) {printf("0\n"); continue;}
            int L = 2, R = min(n - x, x - 1), re = 1;
            while (L <= R) {
                int mid = (L + R) >> 1;
                if ((T.queryf(1, 1, n, x - mid + 1, x - 1) + T.queryg(1, 1, n, x + 2, x + mid)) == make_pair(0llu, 0llu)) re = mid, L = mid + 1;
                    else R = mid - 1;
            }
            printf("%d\n", re);
        }
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 30272kb

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: 3ms
memory: 30380kb

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 525th numbers differ - expected: '12', found: '20'