QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#88957#2587. 荣誉称号RainAir100 ✓3372ms92632kbC++232.7kb2023-03-18 02:58:412023-03-18 02:58:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-18 02:58:44]
  • 评测
  • 测评结果:100
  • 用时:3372ms
  • 内存:92632kb
  • [2023-03-18 02:58:41]
  • 提交

answer

#include <bits/stdc++.h>

#define fi first
#define se second
#define DB double
#define U unsigned
#define P std::pair
#define LL long long
#define LD long double
#define pb emplace_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

inline char nc() {
#define SIZE 1000003
    static char buf[SIZE], *p1 = buf + SIZE, *p2 = buf + SIZE;

    if (p1 == p2) {
        p1 = buf;
        p2 = buf + fread(buf, 1, SIZE, stdin);

        if (p1 == p2)
            return -1;
    }

    return *p1++;
}

template <typename T>
inline void read(T &x) {
    x = 0;
    char ch = nc();
    bool flag = 0;

    while (!isdigit(ch)) {
        if (ch == '-')
            flag = 1;

        ch = nc();
    }

    while (isdigit(ch)) {
        x = (x << 1) + (x << 3) + (ch^'0');
        ch = nc();
    }

    if (flag)
        x = -x;
}

unsigned int SA, SB, SC;
int p, A, B;
unsigned int rng61() {
    SA ^= SA << 16;
    SA ^= SA >> 5;
    SA ^= SA << 1;
    unsigned int t = SA;
    SA = SB;
    SB = SC;
    SC ^= t ^ SA;
    return SC;
}

int n, m, k;
const int MAXN = 2048 + 5;
const int MAXM = 1e7 + 5;
int ta[MAXM], tb[MAXM], mx[MAXN];
LL w[MAXN][205], s[MAXN][205];
LL f[MAXN][205];

void gen() {
    read(n);
    read(k);
    read(m);
    read(p);
    read(SA);
    read(SB);
    read(SC);
    read(A);
    read(B);
    ++k;
    FOR(i, 1, p) read(ta[i]), read(tb[i]);
    FOR(i, p + 1, n) ta[i] = rng61() % A + 1, tb[i] = rng61() % B + 1;
    FOR(i, 1, (1 << k) - 1) FOR(j, 0, m - 1) w[i][j] = s[i][j] = 0;
    FOR(i, 1, n) {
        int x = i;

        while (x >= (1 << k))
            x >>= k;

        s[x][ta[i] % m] += tb[i];
    }
    FOR(i, 1, (1 << k) - 1) {
        FOR(j, 0, m - 1) {
            FOR(k, 0, m - 1) {
                w[i][j] += 1ll * s[i][k] * ((j - k + m) % m);
            }
        }
    }
}

inline void dfs(int v) {
    FOR(i, 0, m - 1) f[v][i] = 1e18;

    if ((v << 1) >= (1 << k)) {
        FOR(i, 0, m - 1) f[v][(m - i) % m] = w[v][i];
        return;
    }

    dfs(v << 1);
    dfs(v << 1 | 1);
    FOR(i, 0, m - 1) {
        FOR(j, 0, m - 1) {
            f[v][i] = std::min(f[v][i], f[v << 1][(i + j) % m] + f[v << 1 | 1][(i + j) % m] + w[v][j]);
        }
    }
}

inline void Solve() {
    gen();
    dfs(1);
    printf("%lld\n", f[1][0]);
}

int main() {
    int T;
    read(T);

    while (T--)
        Solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 30
Accepted
time: 6ms
memory: 8524kb

input:

10
100 6 2 100 233935 922673 177972 100 100
50 10
22 68
21 75
14 95
33 60
55 83
1 92
82 65
83 88
99 58
49 82
70 42
2 59
37 20
18 85
98 76
11 67
52 28
73 66
28 24
49 98
50 1
86 78
43 38
22 94
3 35
35 96
74 37
74 64
84 5
34 38
19 58
9 11
52 77
28 48
66 47
29 12
8 49
83 50
20 31
79 43
6 53
6 68
99 11
8...

output:

315
3056
288071
6712311
6329883
15283205
19870126
15122517
19096622
20474992

result:

ok 10 lines

Test #2:

score: 40
Accepted
time: 2306ms
memory: 15156kb

input:

10
100000 8 50 100000 247575 819409 776601 100 100
89 32
56 35
20 7
49 32
42 55
32 35
24 93
93 90
54 27
5 38
14 56
29 68
10 88
76 99
93 25
21 89
100 79
48 63
81 38
52 35
96 59
12 79
100 55
16 61
90 78
31 16
27 33
22 81
79 67
74 22
60 14
51 63
60 16
27 17
90 85
94 33
16 86
88 89
40 52
37 5
44 15
35 5...

output:

116425574
2353851315
35516738695
473739227241
4728624650223
47401343950664
47560130284214
47275898551780
47480558629097
47356398623029

result:

ok 10 lines

Test #3:

score: 30
Accepted
time: 3372ms
memory: 92632kb

input:

10
1000000 10 100 100000 955891 404406 316093 100 100
35 87
53 20
85 45
70 69
93 53
52 46
11 58
11 23
62 12
32 18
35 76
39 91
78 34
37 89
40 18
93 80
40 88
4 60
68 40
52 25
68 7
58 88
60 70
25 65
38 16
66 89
8 11
69 99
15 70
69 28
33 6
82 8
64 99
57 37
99 85
55 84
65 59
6 67
7 91
64 72
69 76
68 51
5...

output:

2422031421
143313816604
3433959129294
49250634554363
492655980277329
4923481281511113
4920530936088745
4922522387109597
4922703666684114
4921961703011552

result:

ok 10 lines