QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#589163#6409. Classical Data Structure ProblemTobo#WA 2ms16160kbC++203.3kb2024-09-25 16:28:352024-09-25 16:28:37

Judging History

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

  • [2024-09-25 16:28:37]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:16160kb
  • [2024-09-25 16:28:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 5e5 + 50, mod = 1 << 30;
int n, m, all, tot, root;
mt19937 rnd(time(0));
int val[N], siz[N], tag[N], w[N], sum[N], ch[N][2], b[N];
int tree_siz[N];
int newnode(int x, int s, int l)
{
    x %= mod;
    int ret = ++tot;
    w[ret] = rnd(), b[ret] = l;
    val[ret] = x, siz[ret] = s;
    tree_siz[ret] = s;
    sum[ret] = 1ll * x * s % mod;
    return ret;
}
void pushdown(int cur)
{
    if (int lc = ch[cur][0]; lc)
    {
        tag[lc] = (tag[lc] + tag[cur]) % mod;
        sum[lc] = (sum[lc] + 1ll * siz[lc] * tag[cur] % mod) % mod;
        val[lc] = (val[lc] + tag[cur]) % mod;
    }
    if (int rc = ch[cur][1]; rc)
    {
        tag[rc] = (tag[rc] + tag[cur]) % mod;
        sum[rc] = (sum[rc] + 1ll * siz[rc] * tag[cur] % mod) % mod;
        val[rc] = (val[rc] + tag[cur]) % mod;
    }
    tag[cur] = 0;
}
void pushup(int cur)
{
    sum[cur] = 1ll * val[cur] * siz[cur] % mod;
    sum[cur] += (sum[ch[cur][0]] + sum[ch[cur][1]]) % mod;
    sum[cur] %= mod;
    tree_siz[cur] = siz[cur] + tree_siz[ch[cur][0]] + tree_siz[ch[cur][1]];
}
pair<int, int> split(int x, int z)
{
    if (!x)
        return {0, 0};

    pushdown(x);
    pair<int, int> ret;
    if (z < b[x])
    {
        ret = split(ch[x][0], z);
        ch[x][0] = ret.second;
        ret.second = x;
    }
    else
    {
        ret = split(ch[x][1], z);
        ch[x][1] = ret.first;
        ret.first = x;
    }
    pushup(x);
    return ret;
}
int merge(int x, int y)
{
    if (!x or !y)
        return x | y;

    pushdown(x), pushdown(y);
    int ret;
    if (w[x] < w[y])
    {
        ret = merge(ch[x][1], y);
        ch[x][1] = ret;
        ret = x;
    }
    else
    {
        ret = merge(x, ch[y][0]);
        ch[y][0] = ret;
        ret = y;
    }
    pushup(ret);
    return ret;
}

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

    cin >> n >> m;
    all = 1 << m;
    root = newnode(0, all, 0);

    int x = 0;
    for (int i = 1, p, q; i <= n; i++)
    {
        cin >> p >> q;
        p = (p + x) % all, q = (q + x) % all;
        if (p > q)
            swap(p, q);

        auto dfs = [&](auto &dfs, int x, int v) -> void
        {
            pushdown(x);
            if (ch[x][1])
            {
                dfs(dfs, ch[x][1], v);
                pushup(x);
                return;
            }
            if (b[x] + siz[x] == v)
                return;
            int cur = newnode(val[x], siz[x] - (v - b[x]), v);
            siz[x] = v - b[x], ch[x][1] = cur;
            pushup(x);
        };
        auto r1 = split(root, p - 1);
        dfs(dfs, r1.first, p);
        root = merge(r1.first, r1.second);
        auto r2 = split(root, q);
        dfs(dfs, r2.first, q + 1);
        root = merge(r2.first, r2.second);

        r1 = split(root, p - 1), r2 = split(r1.second, q);
        tag[r2.first] = (tag[r2.first] + i) % mod;
        val[r2.first] = (val[r2.first] + i) % mod;
        sum[r2.first] = (sum[r2.first] + 1ll * i * tree_siz[r2.first] % mod) % mod;
        x = (x + sum[r2.first]) % mod;
        root = merge(r1.first, merge(r2.first, r2.second));
    }

    cout << x << '\n';
}
/*
 5 2
 2 1
 1 3
 3 2
 1 0
 0 2
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 15964kb

input:

5 2
2 1
1 3
3 2
1 0
0 2

output:

87

result:

ok 1 number(s): "87"

Test #2:

score: 0
Accepted
time: 0ms
memory: 16100kb

input:

1 1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 16028kb

input:

1 2
3 1

output:

3

result:

ok 1 number(s): "3"

Test #4:

score: 0
Accepted
time: 2ms
memory: 16088kb

input:

1 5
31 15

output:

17

result:

ok 1 number(s): "17"

Test #5:

score: 0
Accepted
time: 0ms
memory: 16160kb

input:

1 20
366738 218765

output:

147974

result:

ok 1 number(s): "147974"

Test #6:

score: 0
Accepted
time: 0ms
memory: 16052kb

input:

1 30
86669484 41969116

output:

44700369

result:

ok 1 number(s): "44700369"

Test #7:

score: 0
Accepted
time: 1ms
memory: 15960kb

input:

10 5
20 31
2 2
14 18
13 25
26 4
22 9
15 9
19 16
15 27
9 20

output:

1414

result:

ok 1 number(s): "1414"

Test #8:

score: -100
Wrong Answer
time: 2ms
memory: 16028kb

input:

100 10
245 987
817 813
743 560
548 504
116 479
223 199
775 998
126 542
791 823
96 318
69 349
0 584
245 601
119 513
93 820
115 307
838 978
249 767
433 287
240 8
22 683
169 720
395 592
903 866
919 652
510 563
858 345
938 250
550 239
981 7
784 926
212 644
272 365
490 871
470 987
571 53
65 593
515 370
1...

output:

21401867

result:

wrong answer 1st numbers differ - expected: '20383734', found: '21401867'