QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#244594#4477. Pandaemonium Asphodelos: The First Circle (Savage)ucup-team203#AC ✓523ms48676kbC++205.6kb2023-11-09 12:58:142023-11-09 12:58:15

Judging History

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

  • [2023-11-09 12:58:15]
  • 评测
  • 测评结果:AC
  • 用时:523ms
  • 内存:48676kb
  • [2023-11-09 12:58:14]
  • 提交

answer

#include <bits/stdc++.h>
using i64 = long long;
using namespace std;
const int N = 1e5 + 5;
// const int B = 400;
// const int M = 4e6 + 5;
// const int base = 15171;
// const int mod = 998244353;
// const i64 mod = (i64)1e18 + 7;
// const double pi = acos(-1);

struct SegmentTree
{
    int tot, root;
    struct node
    {
        int l, r;
        i64 tag, val;
    } st[N << 6];
#define lc st[cur].l
#define rc st[cur].r
    void pushdown(int cur)
    {
        if (!st[cur].tag)
            return;
        if (!lc)
            lc = ++tot;
        if (!rc)
            rc = ++tot;
        st[lc].tag += st[cur].tag;
        st[rc].tag += st[cur].tag;
        st[lc].val += st[cur].tag;
        st[rc].val += st[cur].tag;
        st[cur].tag = 0;
    }
    void update(int &cur, int l, int r, int a, int b, i64 x)
    {
        if (!cur)
            cur = ++tot;
        if (a <= l && r <= b)
        {
            st[cur].tag += x;
            st[cur].val += x;
            return;
        }
        pushdown(cur);
        int mid = l + r >> 1;
        if (a <= mid)
            update(lc, l, mid, a, b, x);
        if (b > mid)
            update(rc, mid + 1, r, a, b, x);
    }
    void update(int a, int b, i64 x) { update(root, 1, 1e8, a, b, x); }
    i64 query(int cur, int l, int r, int p)
    {
        if (!cur || l == r)
            return st[cur].val;
        pushdown(cur);
        int mid = l + r >> 1;
        if (p <= mid)
            return query(lc, l, mid, p);
        else
            return query(rc, mid + 1, r, p);
    }
    i64 query(int p) { return query(root, 1, 1e8, p); }
    void clear()
    {
        for (int i = 1; i <= tot; i++)
            st[i] = {0, 0, 0, 0};
        tot = root = 0;
    }
} tr;
set<pair<i64, i64>> col[N];
i64 tag[N];
void solve()
{
    int n, m;
    cin >> n >> m;
    set<array<i64, 3>> st;
    st.insert({1, n, 0});
    col[0].insert({1, n});
    i64 ans = 0, opt, x, y;
    for (int i = 1; i <= m; i++)
    {
        cin >> opt >> x;
        if (opt == 1)
        {
            cin >> y;
            x = ((x - 1) ^ ans) % n + 1;
            y = ((y - 1) ^ ans) % ((n - 1) / 2) + 1;
            tie(x, y) = pair<i64, i64>{x - y, x + y};
            if (x < 1)
                y += 1 - x, x = 1;
            if (y > n)
                x -= y - n, y = n;
            vector<array<i64, 3>> add, del;
            for (auto it = prev(st.lower_bound({x + 1, 0, 0})); it != st.end() && (*it)[0] <= y; it++)
            {
                auto [l, r, _] = *it;
                del.push_back({l, r, _});
                if (x <= l && r <= y)
                {
                    tr.update(l, r, tag[_]);
                    continue;
                }
                if (l < x && r > y)
                {
                    add.push_back({l, x - 1, _});
                    add.push_back({y + 1, r, _});
                    tr.update(x, y, tag[_]);
                    continue;
                }
                if (l < x)
                {
                    add.push_back({l, x - 1, _});
                    tr.update(x, r, tag[_]);
                }
                else if (r > y)
                {
                    add.push_back({y + 1, r, _});
                    tr.update(l, y, tag[_]);
                }
            }
            for (auto [l, r, c] : del)
                col[c].erase({l, r}), st.erase({l, r, c});
            for (auto [l, r, c] : add)
                col[c].insert({l, r}), st.insert({l, r, c});
            col[i].insert({x, y});
            st.insert({x, y, i});
        }
        else if (opt == 2)
        {
            cin >> y;
            x = ((x - 1) ^ ans) % n + 1;
            y = ((y - 1) ^ ans) % n + 1;
            auto it = prev(st.lower_bound({y + 1, 0, 0}));
            auto [l, r, c] = *it;
            it = prev(st.lower_bound({x + 1, 0, 0}));
            int d = (*it)[2];
            if (c == d)
                continue;
            st.erase({l, r, c});
            tr.update(l, r, tag[c]);
            col[c].erase({l, r});
            tr.update(l, r, -tag[d]);
            auto it1 = col[d].upper_bound({r, 0});
            if (it1 != col[d].end())
            {
                if (it1->first == r + 1)
                {
                    r = it1->second;
                    st.erase({it1->first, it1->second, d});
                    col[d].erase(it1);
                }
            }
            it1 = col[d].lower_bound({l, 0});
            if (it1 != col[d].begin())
            {
                it1--;
                if (it1->second + 1 == l)
                {
                    l = it1->first;
                    st.erase({it1->first, it1->second, d});
                    col[d].erase(it1);
                }
            }
            st.insert({l, r, d});
            col[d].insert({l, r});
        }
        else if (opt == 3)
        {
            cin >> y;
            x = ((x - 1) ^ ans) % n + 1;
            int c = (*prev(st.lower_bound({x + 1, 0, 0})))[2];
            tag[c] += y;
        }
        else
        {
            x = ((x - 1) ^ ans) % n + 1;
            int c = (*prev(st.lower_bound({x + 1, 0, 0})))[2];
            ans = tag[c] + tr.query(x);
            cout << ans << '\n';
            ans &= 1073741823;
        }
    }
    for (int i = 0; i <= m; i++)
        col[i].clear(), tag[i] = 0;
    tr.clear();
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    cin >> t;
    // cout << fixed << setprecision(10);
    while (t--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 523ms
memory: 48676kb

input:

16
16 12
3 10 16
4 2
1 1 6
1 5 6
1 9 7
1 15 7
2 2 10
2 2 13
3 1 16
4 16
4 9
4 4
100 10
3 52 336470888
2 46 95
4 98
3 3 971207868
2 6 18
2 27 38
3 68 717268783
4 69
4 30
2 2 54
100000000 100
3 23264237 374288891
1 51244358 31960832
3 66089174 543529670
3 19728747 580543238
3 68188689 490702144
1 3862...

output:

16
32
32
16
336470888
2024947539
2024947539
1989063943
1989063943
3947292200
2332517148
3947292200
2332517148
2332517148
2173902728
3154913316
3154913316
7792501902
5025837134
5196716262
7081781397
5196716262
6177726850
7031735014
7081781397
7081781397
7589349584
10153736164
9944646904
12358787010
9...

result:

ok 166382 lines