QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#884808#9877. Segment Treew4p3rWA 21ms5732kbC++202.8kb2025-02-06 10:59:142025-02-06 10:59:22

Judging History

This is the latest submission verdict.

  • [2025-02-06 10:59:22]
  • Judged
  • Verdict: WA
  • Time: 21ms
  • Memory: 5732kb
  • [2025-02-06 10:59:14]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 5e8;

#define N 20

#define ls (x << 1)
#define rs (x << 1 | 1)
#define mid ((l + r) >> 1)

int c[1 << N], dis[1 << N];
int n, q;

void pushup(int x)
{
    dis[x] = min(c[x], dis[ls] + dis[rs]);
}

void build(int l, int r, int x)
{
    if (l == r) {dis[x] = c[x]; return ;}
    build(l, mid, ls); build(mid + 1, r, rs);
    pushup(x);
}

void qry(int l, int r, int x, int s, int t, int &ans, int &sl, int &sr, int &tl, int &tr)
{
    if (((s < l - 1) || (s > r)) && ((t < l - 1) || (t > r))) return ;
    if (l == r)
    {
        if (s == l - 1)sl = 0, sr = c[x];
        if (s == r)sl = c[x], sr = 0;

        if (t == l - 1)tl = 0, tr = c[x];
        if (t == r)tl = c[x], tr = 0;

        if (s == l - 1 && t == r)ans = c[x];

        return ;
    }
    int ansL, slL, srL, tlL, trL;
    int ansR, slR, srR, tlR, trR;

    ansL = slL = srL = tlL = trL = ansR = slR = srR = tlR = trR = inf;
    qry(l, mid, ls, s, t, ansL, slL, srL, tlL, trL);
    qry(mid + 1, r, rs, s, t, ansR, slR, srR, tlR, trR);

    ans = min(ansL, ansR);
    if (s >= l - 1 && s <= mid)
    {
        sl = min(slL, srL + dis[rs] + c[x]);
        sr = min(srL + dis[rs], slL + c[x]);
    }
    if (s >= mid && s <= r)
    {
        sl = min(slR + dis[ls], srR + c[x]);
        sr = min(srR, slR + dis[ls] + c[x]);
    }

    if (t >= l - 1 && t <= mid)
    {
        tl = min(tlL, trL + dis[rs] + c[x]);
        tr = min(trL + dis[rs], tlL + c[x]);
    }
    if (t >= mid && t <= r)
    {
        tl = min(tlR + dis[ls], trR + c[x]);
        tr = min(trR, tlR + dis[ls] + c[x]);
    }

    ans = min(ans, sl + c[x] + tr);
    ans = min(ans, sr + c[x] + tl);
    ans = min(ans, srL + tlR);
    ans = min(ans, trL + slR);
    // cout << "EEE:" << l << ' ' << r << ' ' << c[x] << endl;
    // cout << ans << ' ' << sl << ' ' << sr << ' ' << tl << ' ' << tr << endl;
}

void sol()
{
    cin >> n;
    for (int i = 1; i <= (1 << n + 1) - 1; i ++)cin >> c[i];
    build(1, (1 << n), 1);

    cin >> q;
    while (q --)
    {
        int op; cin >> op;
        if (op == 1)
        {
            int j, x;
            cin >> j >> x;
            c[j] = x;
            while (j) {pushup(j); j >>= 1;}
        }
        if (op == 2)
        {
            int s, t;
            cin >> s >> t;
            int ans, sl, sr, tl, tr;
            ans = sl = sr = tl = tr = inf;
            qry(1, (1 << n), 1, s, t, ans, sl, sr, tl, tr);

            cout << ans << '\n';
        }
    }
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int T = 1;
    // cin >> T;
    while (T --) sol();

    return 0;
}

详细

Test #1:

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

input:

3
7 1 14 3 9 4 8 2 6 5 5 13 8 2 3
10
2 0 1
2 0 4
2 4 6
2 4 8
2 3 5
1 6 30
2 3 5
2 4 6
1 1 10000000
2 0 8

output:

2
1
4
8
17
18
13
15

result:

ok 8 tokens

Test #2:

score: -100
Wrong Answer
time: 21ms
memory: 5732kb

input:

1
7914575 2436426 4979445
199989
1 1 6190629
1 1 1407775
1 1 2804784
1 2 2631932
1 1 3078537
1 3 286918
1 2 3238506
1 3 3361868
1 2 9296263
1 3 4836991
1 3 2177068
1 3 4291757
1 1 594328
1 2 8996221
1 1 5531545
1 3 3575467
1 3 3206504
1 1 8344965
1 3 6045895
2 0 2
1 2 6248153
1 1 5797489
1 1 9766466...

output:

8344965
5684734
187581
2512448
130126
6420140
2615908
6363152
6668726
4380822
8809904
4042733
6472110
8653391
2905234
7013656
8583126
371692
743384
2539201
7188565
8465921
4517278
1913351
7400947
3327130
1759308
6081288
2783848
3409112
2827247
6571404
4704960
5280672
7152753
1622556
2599805
1833019
...

result:

wrong answer 3rd words differ - expected: '2756417', found: '187581'