QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682848#9242. An Easy Geometry Problemlouhao088WA 8ms30324kbC++233.8kb2024-10-27 17:33:422024-10-27 17:33:42

Judging History

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

  • [2024-10-27 17:33:42]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:30324kb
  • [2024-10-27 17:33:42]
  • 提交

answer

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

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, mid);
        pair <ull, ull> re2 = queryf(now << 1 | 1, mid + 1, r, mid + 1, 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), re = 1;
            while (L <= R) {
                int mid = (L + R) >> 1;
                if ((T.queryg(1, 1, n, x - mid + 1, x - 1) + T.queryf(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: 30220kb

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: 8ms
memory: 30324kb

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:

1842
1019
599
800
1413
736
427
48
116
1882
362
511
313
501
632
617
302
550
600
306
591
312
1427
295
281
304
453
1049
931
653
551
96
7
555
627
13
167
48
1008
16
1
72
33
16
22
116
246
297
603
1
521
107
197
455
566
474
1049
21
44
503
96
457
537
27
151
30
32
1186
134
310
531
37
12
253
2
21
154
125
110
5...

result:

wrong answer 1st numbers differ - expected: '2', found: '1842'