QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#719780#8648. TowerhhoppitreeCompile Error//C++174.2kb2024-11-07 08:51:382024-11-07 08:51:38

Judging History

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

  • [2024-11-07 08:51:38]
  • 评测
  • [2024-11-07 08:51:38]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

long long res[N], id[N], mn[1 << 21], lz[1 << 21];

void build(int k, int l, int r) {
    mn[k] = (l == 1 ? 0 : 3e18);
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(k << 1, l, mid);
    build(k << 1 | 1, mid + 1, r);
}

void pushdown(int k) {
    if (!lz[k]) return;
    mn[k << 1] = 3e18, lz[k << 1] = 1;
    mn[k << 1 | 1] = 3e18, lz[k << 1 | 1] = 1;
    lz[k] = 0;
}

void modify(int k, int l, int r, int x, int y) {
    if (l > y || r < x) return;
    if (l >= x && r <= y) {
        mn[k] = 3e18, lz[k] = 1;
        return;
    }
    pushdown(k);
    int mid = (l + r) >> 1;
    modify(k << 1, l, mid, x, y);
    modify(k << 1 | 1, mid + 1, r, x, y);
    mn[k] = min(mn[k << 1], mn[k << 1 | 1]);
}

void update(int k, int l, int r, int x, long long y) {
    mn[k] = min(mn[k], y);
    if (l == r) return;
    pushdown(k);
    int mid = (l + r) >> 1;
    if (x <= mid) update(k << 1, l, mid, x, y);
    else update(k << 1 | 1, mid + 1, r, x, y);
}

long long query(int k, int l, int r, int x, int y) {
    if (l > y || r < x) return 3e18;
    if (l >= x && r <= y) return mn[k];
    pushdown(k);
    int mid = (l + r) >> 1;
    return min(query(k << 1, l, mid, x, y), query(k << 1 | 1, mid + 1, r, x, y));
}

signed main() {
    int n, q;
    long long D, A, B;
    scanf("%d%d%lld%lld%lld", &n, &q, &D, &A, &B);
    vector< pair<long long, int> > p;
    vector<long long> lsh;
    for (int i = 1; i <= n; ++i) {
        long long l, r; scanf("%lld%lld", &l, &r);
        p.push_back({l, 0}), p.push_back({r + 1, 0});
        lsh.push_back(l % D), lsh.push_back((r + 1) % D);
    }
    lsh.push_back(0), lsh.push_back(D - 1);
    p.push_back({0, q + 1});
    for (int i = 1; i <= q; ++i) {
        long long x; scanf("%lld", &x);
        id[i] = x;
        p.push_back({x, i});
        lsh.push_back(x % D);
        res[i] = 3e18;
    }
    sort(lsh.begin(), lsh.end());
    lsh.erase(unique(lsh.begin(), lsh.end()), lsh.end());
    sort(p.begin(), p.end());
    auto getId = [&](long long x) {
        return lower_bound(lsh.begin(), lsh.end(), x) - lsh.begin() + 1;
    };
    build(1, 1, lsh.size());
    set< pair<int, int> > S = {{1, lsh.size()}};
    long long tag = 0;
    for (int m = p.size(), i = 0, j, nw = 0; i < m; ) {
        j = i;
        auto preMax = [&](int x) {
            int val = 1;
            if (!S.empty() && (S.begin() -> first) <= x) {
                auto it = --S.lower_bound({x + 1, 0});
                val = (it -> second) + 1;
            }
            update(1, 1, lsh.size(), x, query(1, 1, lsh.size(), val, x));
        };
        while (j < m && p[j].first / D == p[i].first / D) {
            preMax(getId(p[j++].first % D));
        }
        preMax(lsh.size());
        if (i) update(1, 1, lsh.size(), 1, query(1, 1, lsh.size(), lsh.size(), lsh.size()) + A * D - B);
        S.clear();
        int lst = 1;
        vector< pair<long long, int> > qr;
        while (i < j) {
            int tid = getId(p[i].first % D);
            if (nw) {
                modify(1, 1, lsh.size(), lst, tid - 1);
                if (lst <= tid - 1) S.insert({lst, tid - 1});
            }
            nw ^= !p[i].second;
            lst = tid;
            if (p[i].second) qr.push_back({p[i].first, p[i].second});
            ++i;
        }
        if (nw) {
            modify(1, 1, lsh.size(), lst, lsh.size());
            S.insert({lst, lsh.size()});
        }
        for (auto [x, y] : qr) {
            int tid = getId(x % D);
            preMax(tid), res[y] = tag + query(1, 1, lsh.size(), tid, tid);
        }
        if (i != m && p[i].first / D != p[i - 1].first / D + 1) {
            if (nw) break;
            S.clear(), preFix(lsh.size()), update(1, 1, lsh.size(), 1, query(1, 1, lsh.size(), lsh.size(), lsh.size()) + A * D - B);
            tag += (p[i].first / D - p[i - 1].first / D - 1) * min(A * D - B, 0ll);
        }
    }
    for (int i = 1; i <= q; ++i) {
        if (res[i] > 2e18) puts("-1");
        else printf("%lld\n", res[i] + id[i] % D * A + id[i] / D * B);
    }
    return 0;
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:122:24: error: ‘preFix’ was not declared in this scope; did you mean ‘preMax’?
  122 |             S.clear(), preFix(lsh.size()), update(1, 1, lsh.size(), 1, query(1, 1, lsh.size(), lsh.size(), lsh.size()) + A * D - B);
      |                        ^~~~~~
      |                        preMax
answer.code:57:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   57 |     scanf("%d%d%lld%lld%lld", &n, &q, &D, &A, &B);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:61:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   61 |         long long l, r; scanf("%lld%lld", &l, &r);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~
answer.code:68:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |         long long x; scanf("%lld", &x);
      |                      ~~~~~^~~~~~~~~~~~