QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#57988#1085. Brave Seekers of UnicornsSa3tElSefrAC ✓74ms11660kbC++201.5kb2022-10-24 06:41:092022-10-24 06:41:10

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-24 06:41:10]
  • 评测
  • 测评结果:AC
  • 用时:74ms
  • 内存:11660kb
  • [2022-10-24 06:41:09]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>

#define ll long long
#define ld  double
using namespace std;

const int N = 3e5 + 5, mod = 998244353;


int tree[(1 << 21) + 1];

void update(int node, int bit, int mask, int val) {
    tree[node] += val;
    if(tree[node] >= mod) tree[node] -= mod;
    if(bit == -1) return;
    if(mask >> bit & 1 ^ 1) update(node << 1, bit - 1, mask, val);
    else update(node << 1 | 1, bit - 1, mask, val);
}

void update(int mask, int val) {
    update(1, 19, mask, val);
}


int get(int node, int bit, int mask, bool f) {
    if(bit == -1) return 0;
    if(mask >> bit & 1) {
        if(f) {
            return get(node << 1, bit - 1, mask, 0);
        }
        else {
            int ret = tree[node << 1 | 1];
            ret += get(node << 1, bit - 1, mask, f);
            if(ret >= mod) ret -= mod;
            return ret;
        }
    }
    else {
        return get(node << 1, bit - 1, mask, f);
    }
}

int get(int mask) {
    return get(1, 19, mask, 1);
}

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

    int n;
    cin >> n;

    update(1, 1);
    int total = 1;
    for(int i = 2; i <= n; i++) {
        int z = get(i);
        int curAns = (1 + total - z + mod);
        if(curAns >= mod) curAns -= mod;

        update(i, curAns);

        total += curAns;
        if(total >= mod) total -= mod;
    }
    cout << total;


    return 0;
}


详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 7836kb

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

2

output:

3

result:

ok 1 number(s): "3"

Test #3:

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

input:

3

output:

6

result:

ok 1 number(s): "6"

Test #4:

score: 0
Accepted
time: 3ms
memory: 7876kb

input:

5

output:

26

result:

ok 1 number(s): "26"

Test #5:

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

input:

322

output:

782852421

result:

ok 1 number(s): "782852421"

Test #6:

score: 0
Accepted
time: 3ms
memory: 7656kb

input:

10

output:

728

result:

ok 1 number(s): "728"

Test #7:

score: 0
Accepted
time: 3ms
memory: 7860kb

input:

100

output:

234222727

result:

ok 1 number(s): "234222727"

Test #8:

score: 0
Accepted
time: 3ms
memory: 7872kb

input:

10000

output:

348787098

result:

ok 1 number(s): "348787098"

Test #9:

score: 0
Accepted
time: 70ms
memory: 11640kb

input:

1000000

output:

246427510

result:

ok 1 number(s): "246427510"

Test #10:

score: 0
Accepted
time: 74ms
memory: 11524kb

input:

999999

output:

525546416

result:

ok 1 number(s): "525546416"

Test #11:

score: 0
Accepted
time: 69ms
memory: 11660kb

input:

950000

output:

154241852

result:

ok 1 number(s): "154241852"

Test #12:

score: 0
Accepted
time: 73ms
memory: 11608kb

input:

999888

output:

254589934

result:

ok 1 number(s): "254589934"

Test #13:

score: 0
Accepted
time: 68ms
memory: 11600kb

input:

999423

output:

917909701

result:

ok 1 number(s): "917909701"

Test #14:

score: 0
Accepted
time: 46ms
memory: 10636kb

input:

600000

output:

546076071

result:

ok 1 number(s): "546076071"

Test #15:

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

input:

1337

output:

616951443

result:

ok 1 number(s): "616951443"