QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#884860#9877. Segment Treew4p3rCompile Error//C++202.9kb2025-02-06 11:20:552025-02-06 11:21:03

Judging History

This is the latest submission verdict.

  • [2025-02-06 11:21:03]
  • Judged
  • [2025-02-06 11:20:55]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 5e8;
#define int ll

#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(sl, min(slL, srL + dis[rs] + c[x]));
        sr = min(sr, min(srL + dis[rs], slL + c[x]));
    }
    if (s >= mid && s <= r)
    {
        sl = min(sl, min(slR + dis[ls], srR + c[x]));
        sr = min(sr, min(srR, slR + dis[ls] + c[x]));
    }

    if (t >= l - 1 && t <= mid)
    {
        tl = min(tl, min(tlL, trL + dis[rs] + c[x]));
        tr = min(tr, min(trL + dis[rs], tlL + c[x]));
    }
    if (t >= mid && t <= r)
    {
        tl = min(tl, min(tlR + dis[ls], trR + c[x]));
        tr = min(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 x, v;
            cin >> x >> v;
            c[x] = v;
            while (x) {pushup(x); x >>= 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;
}

详细

answer.code:9:13: error: ‘::main’ must return ‘int’
    9 | #define int ll
      |             ^~
answer.code:115:1: note: in expansion of macro ‘int’
  115 | int main()
      | ^~~