QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#109364#70. Bitaro, who Leaps through Timebashkort#0 788ms44428kbC++205.2kb2023-05-28 18:34:422024-05-31 13:46:22

Judging History

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

  • [2024-05-31 13:46:22]
  • 评测
  • 测评结果:0
  • 用时:788ms
  • 内存:44428kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-28 18:34:42]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int inf = 1e9 + 7;

void massert(bool f) {
    while (!f) {
        cout << "mda" << endl;
    }
}

struct SegmentTree {
    vector<pair<int, int>> t;
    vector<ll> ansL;

    int sz = 1, N;

    int cost(int x, int d, ll &ans) {
        massert(x < sz * 2);
        if (t[x].first == -inf) {
            return d;
        }
        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) {
        massert(x < sz * 2);
        ansL[x] = 0;
        if (t[x << 1 | 1].first == -inf) {
            t[x] = t[x << 1];
            return;
        }
        if (t[x << 1].second == -inf) {
            t[x].first = cost(x << 1 | 1, t[x << 1].first, ansL[x]);
            t[x].second = -inf;
        } else if (t[x << 1 | 1].second == -inf) {
            t[x] = t[x << 1 | 1];
        } else {
            assert(t[x << 1].first <= t[x << 1].second);
            assert(t[x << 1 | 1].first <= t[x << 1 | 1].second);
            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);
                massert(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.assign(sz << 1, {-inf, -inf}), 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;
    if (n > 1) {
        A.init(n - 1, AL, AR);
        B.init(n - 1, BL, BR);
    }

    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(n - i - 2, BL[n - i - 2], BR[n - i - 2]);
    };

    auto stupid = [&n](int x, int y, int a, int b, vector<int> &L, vector<int> &R) {
        ll ans = 0;
        for (int i = x; i < y; ++i) {
            ans += max(0, a - R[i]);
            a = min(R[i], max(a, L[i]));
        }
        ans += max(0, a - b);
        return ans;
    };

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

        ll ans = 0;
        ll stup = 0;

        if (x <= y) {
            a -= x;
            b -= y;
//            stup = stupid(x, y, a, b, AL, AR);
            ans = A.rangeQuery(x, y, a);
        } else {
            a -= n - x - 1;
            b -= n - y - 1;
//            stup = stupid(n - x - 1, n - y - 1, a, b, BL, BR);
            ans = B.rangeQuery(n - x - 1, n - y - 1, a);
        }


        ans += max(0, a - b);
//        return stup;
        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;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3840kb

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:

1133140545
286505553
517757980
236944355
561949186
106582836
0
304461403
191096499

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #42:

score: 0
Wrong Answer
time: 552ms
memory: 44428kb

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:

2332017664654
3146923337014
3348886982922
7434538419582
352734662211
3640537765532
5483561680832
8766262413387
478261051254
3684308418083
3198853253710
7210613878266
5033130732316
5505384378567
5666733482236
6355892230597
39844721211
901745289299
1753192517389
4229169994943
369129457262
426553249750...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #56:

score: 0
Wrong Answer
time: 788ms
memory: 44380kb

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:

5354767852101
934309781772
8032746571463
926086642162
2959978892329
2745984542702
7131233264443
992368751597
2458316515072
4943897155430
8962578553884
2813731084055
4636146825241
3502456016344
4019344961195
2380889772298
4807445673847
8345688055371
1935030499056
4818735443141
6312710133716
364542371...

result:

wrong answer 1st lines differ - expected: '6546523326977', found: '5354767852101'