QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#642630#8471. Lines on a Phone ScreenSecret Sealing Club (Fei Pan, Jialong Li, Shiyang Xiong)#WA 16ms3772kbC++172.1kb2024-10-15 15:23:102024-10-15 15:23:12

Judging History

This is the latest submission verdict.

  • [2024-10-15 15:23:12]
  • Judged
  • Verdict: WA
  • Time: 16ms
  • Memory: 3772kb
  • [2024-10-15 15:23:10]
  • Submitted

answer

#include <bits/stdc++.h>

constexpr int MAXN = 1e5 + 19;
constexpr int MAX_LEN = 24;

struct Node {
    int n_line[MAX_LEN], last[MAX_LEN];
    friend Node operator*(const Node &lhs, const Node &rhs) {
        Node res;
        for (int i = 0; i < MAX_LEN; ++i) {
            int last = lhs.last[i];
            res.n_line[i] = lhs.n_line[i] + rhs.n_line[last] - 1;
            res.last[i] = rhs.last[last];
        }
        return res;
    }
    static Node from_int(int x) {
        Node res;
        for (int i = 0; i < MAX_LEN; ++i) {
            res.n_line[i] = (i + x) / MAX_LEN + 1;
            res.last[i] = (i + x) % MAX_LEN;
        }
        return res;
    }
} tr[MAXN << 2];

void modify(int node, int L, int R, int x, const Node &val) {
    if (L == R) {
        tr[node] = val;
        return;
    }
    int mid = (L + R) / 2;
    if (x <= mid) {
        modify(node << 1, L, mid, x, val);
    } else {
        modify(node << 1 | 1, mid + 1, R, x, val);
    }
    tr[node] = tr[node << 1] * tr[node << 1 | 1];
}

Node query(int node, int L, int R, int l, int r) {
    if (l <= L && R <= r) {
        return tr[node];
    }
    int mid = (L + R) / 2;
    if (r <= mid) {
        return query(node << 1, L, mid, l, r);
    } else if (l > mid) {
        return query(node << 1 | 1, mid + 1, R, l, r);
    } else {
        return query(node << 1, L, mid, l, r) * query(node << 1 | 1, mid + 1, R, l, r);
    }
}

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

    int n, m;
    std::cin >> n >> m;

    std::vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        std::cin >> a[i];
        modify(1, 1, n, i, Node::from_int(a[i]));
    }

    while (m--) {
        int op;
        std::cin >> op;
        if (op == 1) {
            int x, c;
            std::cin >> x >> c;
            modify(1, 1, n, x, Node::from_int(c));
        } else {
            int l, r;
            std::cin >> l >> r;
            auto res = query(1, 1, n, l, r);
            std::cout << res.n_line[0] - 1 + bool(res.last[0]) << '\n';
        }
    }
}

詳細信息

Test #1:

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

input:

5 5
8 8 9 12 13
2 1 5
2 2 4
1 5 3
2 1 5
2 2 5

output:

3
2
2
2

result:

ok 4 number(s): "3 2 2 2"

Test #2:

score: 0
Accepted
time: 12ms
memory: 3548kb

input:

1 100000
1
2 1 1
2 1 1
2 1 1
1 1 5
2 1 1
1 1 4
1 1 22
2 1 1
2 1 1
2 1 1
1 1 7
1 1 8
1 1 9
1 1 21
2 1 1
2 1 1
2 1 1
1 1 4
2 1 1
1 1 4
2 1 1
2 1 1
1 1 20
1 1 1
2 1 1
2 1 1
1 1 4
2 1 1
1 1 18
2 1 1
2 1 1
2 1 1
1 1 8
2 1 1
2 1 1
2 1 1
1 1 8
2 1 1
2 1 1
1 1 11
2 1 1
1 1 4
1 1 4
2 1 1
2 1 1
1 1 3
1 1 11
1...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 49984 numbers

Test #3:

score: -100
Wrong Answer
time: 16ms
memory: 3772kb

input:

5 100000
16 3 4 14 7
2 1 1
2 1 2
2 1 5
2 2 3
2 1 5
1 1 15
2 3 5
2 2 5
1 2 9
1 3 16
1 1 17
1 2 15
1 5 13
2 1 3
2 1 4
2 2 5
2 5 5
2 2 4
1 4 5
1 2 2
1 4 3
2 3 4
1 1 13
1 1 19
1 4 24
2 3 4
1 2 18
2 5 5
1 5 10
2 2 3
2 4 5
2 1 4
1 1 14
2 1 5
2 3 4
1 4 21
1 2 10
2 1 4
1 2 22
2 4 4
2 1 3
2 1 3
1 3 20
2 2 3
...

output:

1
1
2
1
2
2
2
2
3
3
1
2
1
2
1
2
2
4
4
2
3
1
3
3
2
2
1
3
2
3
3
3
3
3
2
2
2
2
2
2
1
2
2
1
1
1
1
2
1
1
3
2
3
3
1
4
1
2
2
2
1
1
1
2
1
1
2
1
1
2
1
2
2
2
1
2
3
1
4
3
2
3
3
4
4
4
3
2
3
1
3
2
2
3
1
2
1
2
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
2
2
3
2
2
1
2
2
1
2
2
2
2
1
2
1
1
2
3
2
2
1
1
2
2
1
2
2
2
1
1
2
2
1
2
2
1
...

result:

wrong answer 8th numbers differ - expected: '3', found: '2'