QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#109351#70. Bitaro, who Leaps through Timebashkort#0 533ms44404kbC++204.3kb2023-05-28 17:58:542024-05-31 13:45:50

Judging History

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

  • [2024-05-31 13:45:50]
  • 评测
  • 测评结果:0
  • 用时:533ms
  • 内存:44404kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-28 17:58:54]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int inf = 1e9 + 7;

struct SegmentTree {
    vector<pair<int, int>> t;
    vector<ll> ansL;
    int sz = 1, N;

    int cost(int x, int d, ll &ans) {
        if (t[x].first <= t[x].second) {
            ans += max(0, d - t[x].second);
            return min(t[x].second, max(d, t[x].first));
        } else if (t[x << 1].second == -inf) {
            ans += ansL[x];
            cost(x << 1, d, ans);
            return t[x].first;
        } else {
            ans += max(0, d - t[x << 1].second);
            return cost(x << 1 | 1, min(t[x << 1].second, max(d, t[x << 1].first)), ans);
        }
    }

    void pull(int x) {
        ansL[x] = 0;
        if (t[x << 1].second == -inf) {
            t[x].first = cost(x << 1 | 1, t[x << 1].first, ansL[x]);
        } else if (t[x << 1 | 1].second == -inf) {
            t[x] = t[x << 1 | 1];
        } else {
            if (t[x << 1].first > t[x << 1 | 1].second) {
                t[x].first = t[x << 1 | 1].second;
                t[x].second = -inf;
            } else if (t[x << 1].second < t[x << 1 | 1].first) {
                t[x].first = t[x << 1].first;
                t[x].second = -inf;
            } else {
                t[x].first = max(t[x << 1].first, t[x << 1 | 1].first);
                t[x].second = min(t[x << 1].second, t[x << 1 | 1].second);
                assert(t[x].first <= t[x].second);
            }
        }
    }

    void init(int n, vector<int> L, vector<int> R) {
        sz = 1 << __lg(n) + !!(n & (n - 1));
        N = n;
        t.resize(sz << 1), ansL.resize(sz << 1);
        for (int i = 0; i < n; ++i) {
            t[i + sz].first = L[i], t[i + sz].second = R[i];
        }
        for (int i = sz - 1; i > 0; --i) {
            pull(i);
        }
    }

    void rangeQuery(int l, int r, int &d, ll &ans, int x, int lx, int rx) {
        if (l >= rx || lx >= r) {
            return;
        }
        if (l <= lx && rx <= r) {
            d = cost(x, d, ans);
            return;
        }
        int mid = lx + rx >> 1;
        rangeQuery(l, r, d, ans, x << 1, lx, mid);
        rangeQuery(l, r, d, ans, x << 1 | 1, mid, rx);
    }

    ll rangeQuery(int l, int r, int &d) {
        assert(l >= 0 && l < N && l < r && r <= N);
        ll ans = 0;
        rangeQuery(l, r, d, ans, 1, 0, sz);
        return ans;
    }

    void modify(int x, int L, int R) {
        x += sz;
        t[x].first = L, t[x].second = R;
        while (x >>= 1) {
            pull(x);
        }
    }
};

//don't forget to add diff between d and needed time

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, q;
    cin >> n >> q;

    vector<int> L(n), R(n), AL(n), AR(n), BL(n), BR(n);

    for (int i = 0; i < n - 1; ++i) {
        cin >> L[i] >> R[i];
        AL[i] = L[i] - i;
        AR[i] = R[i] - i - 1;
        BL[n - i - 2] = L[i] - (n - i - 2);
        BR[n - i - 2] = R[i] - (n - i - 2) - 1;
    }

    SegmentTree A, B;
    A.init(n - 1, AL, AR);
    B.init(n - 1, BL, BR);

//    for (int i = 0; i < n - 1; ++i) {
//        cout << BL[i] << " " << BR[i] << endl;
//    }

    auto modify = [&](int i, int lx, int rx) {
        L[i] = lx, R[i] = rx;
        AL[i] = L[i] - i;
        AR[i] = R[i] - i - 1;
        BL[n - i - 2] = L[i] - (n - i - 2);
        BR[n - i - 2] = R[i] - (n - i - 2) - 1;
        A.modify(i, AL[i], AR[i]);
        B.modify(i, BL[i], BR[i]);
    };

    auto query = [&](int x, int a, int y, int b) -> ll {
        if (x == y) {
            return max(0, a - b);
        }

        ll ans = 0;

        if (x <= y) {
            a -= x;
            b -= y;
            ans = A.rangeQuery(x, y, a);
        } else {
            a -= n - x - 1;
            b -= n - y - 1;
            ans = B.rangeQuery(n - x - 1, n - y - 1, a);
        }

        ans += max(0, a - b);
        return ans;
    };

    while (q--) {
        int t;
        cin >> t;

        if (t == 1) {
            int p, s, e;
            cin >> p >> s >> e;
            modify(p - 1, s, e);
        } else {
            int a, b, c, d;
            cin >> a >> b >> c >> d;
            cout << query(a - 1, b, c - 1, d) << '\n';
        }
    }

    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3576kb

input:

20 18
115497790 671208773
326245299 528973482
100582193 437996818
89058008 771100620
768935396 842907844
187943946 997369106
455078418 542835554
536691525 970171971
564540350 570234421
657178750 753833933
386375484 979995375
389681484 772601117
634873482 897954663
87193815 139420775
259946990 394597...

output:

1588218957
286505553
517757980
236944355
561949186
106582836
0
445281781
191096499

result:

wrong answer 1st lines differ - expected: '1155445816', found: '1588218957'

Subtask #2:

score: 0
Wrong Answer

Test #42:

score: 0
Wrong Answer
time: 533ms
memory: 44404kb

input:

274318 300000
489215489 676617321
780126019 788585486
556851007 580284394
233372413 595198772
519202713 898223077
502895565 696411826
206200999 769856900
270143414 346344669
729812429 901771242
663771137 938786194
472985796 990513077
846601694 992055636
178982840 919444964
27052680 316046043
8183731...

output:

44974172292
49053170159
68620545524
80714434460
17086444974
52592647310
67886844306
100704172585
19361596464
43368424033
56267574391
79686489213
54080710541
87861557119
37005862240
59887599424
5975019815
26611818055
38294316909
45610842193
18101132930
54023440569
96673659425
46274441533
91383541067
...

result:

wrong answer 1st lines differ - expected: '2849147975708', found: '44974172292'

Subtask #3:

score: 0
Runtime Error

Test #56:

score: 0
Runtime Error

input:

270695 300000
513123795 772355425
210106247 394028231
276162603 911454418
105669187 977348162
173662950 272706156
152814457 669922258
344843731 523572913
316675910 752220119
109044474 322732409
555169512 652867118
622530606 779759913
153668285 339269709
150911093 937002300
186921016 855255616
118867...

output:

65810104028
32122160287
96562181799
25284442049
47847981815
42126347085
74555419433
28174875099
35892319920
70253907023
89418906086
38586867625
64060832170
52606326436
54414998575
45497865141
60226799902
90507090179
31624326134
51813938320
96951649810
26365155575
89658188443
37258211047
7047461639
4...

result: