QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#358414#3503. MisspellingRikku_eq37 3222ms462908kbC++143.9kb2024-03-19 19:45:182024-03-19 19:45:19

Judging History

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

  • [2024-03-19 19:45:19]
  • 评测
  • 测评结果:37
  • 用时:3222ms
  • 内存:462908kb
  • [2024-03-19 19:45:18]
  • 提交

answer

#include <bits/stdc++.h>
#define sum(u) (tr[u].cnt[0]+tr[u].cnt[1])
#define ls(u) tr[u].ls
#define rs(u) tr[u].rs
#define N 500005
#define M 30
#define mod 1000000007
using namespace std;
typedef long long ll;

int n, m, rt, tot, rec[2];

struct Seg { int ls, rs, cnt[2]; } tr[N*2];

struct Pnt { int u, l, r; };
vector <Pnt> vec;

struct Lim { int l, r, tg; } p[N];
vector <int> lim[N];

int f[N][M], g[N][M], pr[2][N][M], sumg[N][M], sump[2][N][M];
ll ans;

void buildST (int &u, int l, int r)
{
    if (!u) { u=++tot; }
    if (l==r) { return; }
    int md=(l+r)/2;
    buildST(ls(u), l, md);
    buildST(rs(u), md+1, r);
}
void add (int u, int l, int r, int id, int tg, int num)
{
    if (l==r) { tr[u].cnt[tg]+=num; return; }
    int md=(l+r)/2;
    if (id<=md) { add(ls(u), l, md, id, tg, num); }
    else { add(rs(u), md+1, r, id, tg, num); }
    tr[u].cnt[tg]=tr[ls(u)].cnt[tg]+tr[rs(u)].cnt[tg];
}

void dfs (int u, int l, int r, int ql, int qr)
{
    if (l>qr || r<ql) { return; }
    if (ql<=l && r<=qr) { vec.push_back((Pnt){ u, l, r }); return; }
    int md=(l+r)/2;
    dfs(ls(u), l, md, ql, qr);
    dfs(rs(u), md+1, r, ql, qr);
}

int qry0 (int u, int l, int r)
{
    if (l==r) { rec[0]=(tr[u].cnt[0]!=0); rec[1]=(tr[u].cnt[1]!=0); return l; }
    int md=(l+r)/2;
    if (sum(rs(u))) { return qry0(rs(u), md+1, r); }
    else { return qry0(ls(u), l, md); }
}
int find0 (int ql, int qr)
{
    vec.clear();
    dfs(rt, 1, n, ql, qr);
    for (int i=vec.size()-1; i>=0; i--) {
        int u=vec[i].u, l=vec[i].l, r=vec[i].r;
        if (sum(u)!=0) { return qry0(u, l, r); }
    }
    return 0;
}

int qry1 (int u, int l, int r, int tg)
{
    if (l==r) { return l; }
    int md=(l+r)/2;
    if (tr[rs(u)].cnt[tg]) { return qry1(rs(u), md+1, r, tg); }
    else { return qry1(ls(u), l, md, tg); }
}
int find1 (int ql, int qr, int tg)
{
    vec.clear();
    dfs(rt, 1, n, ql, qr);
    for (int i=vec.size()-1; i>=0; i--) {
        int u=vec[i].u, l=vec[i].l, r=vec[i].r;
        if (tr[u].cnt[tg^1]) { return qry1(u, l, r, tg^1); }
    }
    return 0;
}

int cal (int i)
{
    for (int j=2; j<=26; j++) { pr[1][i][j]=(pr[1][i][j-1]+f[i][j-1])%mod; }
    ll tmp=(pr[1][i][26]+f[i][26])%mod;
    for (int j=25; j>=1; j--) { pr[0][i][j]=(pr[0][i][j+1]+f[i][j+1])%mod; }
    for (int j=1; j<=26; j++) { g[i][j]=(tmp-f[i][j])%mod; }

    for (int j=1; j<=26; j++) { sump[0][i][j]=((i ? sump[0][i-1][j] : 0)+pr[0][i][j])%mod; }
    for (int j=1; j<=26; j++) { sump[1][i][j]=((i ? sump[1][i-1][j] : 0)+pr[1][i][j])%mod; }
    for (int j=1; j<=26; j++) { sumg[i][j]=((i ? sumg[i-1][j] : 0)+g[i][j])%mod; }

    return tmp;
}

int main ()
{
    // freopen("0test.in", "r", stdin);
    // freopen("0test.out", "w", stdout);

    scanf("%d %d", &n, &m);
    buildST(rt, 1, n);
    for (int i=1; i<=m; i++) {
        int u, v; scanf("%d %d", &u, &v);
        if (u<v) { p[i]=(Lim){ u, v, 0 }; }
        else { p[i]=(Lim){ v, u, 1 }; }
        lim[p[i].r].push_back(i);
        add(rt, 1, n, p[i].l, p[i].tg, 1);
    }

    for (int i=1; i<=26; i++) { f[0][i]=1; }
    ans+=cal(0); ans%=mod;
    for (int i=1; i<=n; i++) {
        for (int j=0; j<(int)lim[i].size(); j++) {
            int id=lim[i][j];
            add(rt, 1, n, p[id].l, p[id].tg, -1);
        }
        for (int j=1; j<=26; j++) {
            int pos0=find0(1, i);
            if (!pos0) { f[i][j]+=sumg[i-1][j]; f[i][j]%=mod; continue; }
            else { f[i][j]+=sumg[i-1][j]-sumg[pos0-1][j]; f[i][j]%=mod; }

            if (rec[0] && rec[1]) { continue; }

            bool cur=(rec[0] ? 0 : 1);
            int pos1=find1(1, i, cur);
            if (!pos1) { f[i][j]+=sump[cur][pos0-1][j]; f[i][j]%=mod; }
            else { f[i][j]+=sump[cur][pos0-1][j]-sump[cur][pos1-1][j]; f[i][j]%=mod; }
        }

        if (i<n) { ans+=cal(i); ans%=mod; }
    }
    ans=(ans+mod)%mod;

    printf("%lld\n", ans);

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 3ms
memory: 28556kb

input:

10 9
3 4
4 2
6 2
7 6
7 8
8 5
5 10
10 9
9 1

output:

344750796

result:

ok single line: '344750796'

Test #2:

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

input:

10 9
3 7
7 4
4 9
6 9
8 6
8 5
5 10
10 1
1 2

output:

1506401

result:

ok single line: '1506401'

Test #3:

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

input:

10 10
2 8
1 5
9 3
3 9
2 9
7 10
7 3
7 8
4 1
5 6

output:

351

result:

ok single line: '351'

Test #4:

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

input:

10 90
5 2
4 2
3 6
1 10
7 1
10 9
1 7
2 3
10 3
7 6
8 5
5 3
9 1
6 3
8 1
3 5
6 2
5 1
2 10
2 8
8 7
3 4
6 7
3 10
4 8
7 3
1 8
2 9
9 2
3 2
9 6
2 1
1 9
1 5
8 3
4 5
8 10
4 3
9 8
2 6
10 2
3 7
4 9
8 9
7 5
5 7
10 5
9 4
1 4
10 7
9 10
9 7
6 10
7 9
2 4
5 9
2 7
1 3
3 9
6 9
2 5
6 1
9 3
7 10
5 10
8 4
8 6
3 8
8 2
3 1
5...

output:

26

result:

ok single line: '26'

Test #5:

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

input:

10 1
4 2

output:

960864167

result:

ok single line: '960864167'

Test #6:

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

input:

10 5
6 3
9 4
4 10
9 5
9 2

output:

1682226

result:

ok single line: '1682226'

Test #7:

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

input:

2 1
1 2

output:

351

result:

ok single line: '351'

Test #8:

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

input:

2 2
2 1
1 2

output:

26

result:

ok single line: '26'

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #9:

score: 20
Accepted
time: 3ms
memory: 28628kb

input:

200 100
1 30
10 179
12 115
15 117
17 161
19 84
22 146
23 46
27 188
29 108
37 69
39 48
41 55
44 158
47 63
50 71
51 91
54 107
55 148
56 61
58 71
61 186
62 92
63 168
65 158
66 145
67 90
71 95
73 125
76 101
79 196
80 104
82 153
84 98
85 111
86 143
88 107
90 177
91 111
92 99
93 177
94 123
95 113
96 128
9...

output:

141223392

result:

ok single line: '141223392'

Test #10:

score: -20
Wrong Answer
time: 0ms
memory: 26576kb

input:

200 100
2 182
3 188
4 67
5 177
7 189
10 123
11 33
13 155
15 58
20 33
22 158
23 47
25 143
26 153
29 158
32 98
35 178
38 64
39 63
41 186
43 134
45 158
46 196
47 119
52 130
55 89
56 109
59 111
60 161
62 161
66 84
69 142
76 105
78 147
79 200
81 162
85 105
86 132
87 177
89 105
90 102
91 161
92 104
93 194...

output:

422839226

result:

wrong answer 1st lines differ - expected: '324576383', found: '422839226'

Subtask #3:

score: 29
Accepted

Test #19:

score: 29
Accepted
time: 3222ms
memory: 462900kb

input:

500000 499999
5 6
6 7
7 11
11 15
15 18
18 20
20 21
21 22
22 23
23 27
27 28
28 29
29 30
30 32
32 33
33 35
35 36
36 37
37 43
43 44
44 46
46 47
47 48
48 49
49 51
51 52
52 53
53 54
54 58
58 61
61 63
63 64
64 65
65 66
66 69
69 70
70 76
76 77
77 78
78 80
80 81
81 83
83 87
87 88
88 90
90 92
92 93
93 96
96 ...

output:

19934265

result:

ok single line: '19934265'

Test #20:

score: 0
Accepted
time: 3184ms
memory: 462828kb

input:

500000 499999
2 4
4 5
5 7
7 8
8 9
9 10
10 13
13 14
14 15
15 16
16 19
19 27
27 29
29 30
30 35
35 37
37 39
39 42
42 44
44 45
45 48
48 51
51 54
54 56
56 57
57 58
58 60
60 62
62 63
63 64
64 65
65 66
66 70
70 71
71 74
74 75
75 76
76 77
77 80
80 82
82 85
85 86
86 93
93 94
94 96
96 98
98 100
100 101
101 10...

output:

564937410

result:

ok single line: '564937410'

Test #21:

score: 0
Accepted
time: 3174ms
memory: 462908kb

input:

500000 499999
1 2
2 4
4 5
5 6
6 8
8 9
9 11
11 12
12 14
14 18
18 19
19 20
20 21
21 24
24 25
25 27
27 29
29 30
30 31
31 33
33 37
37 38
38 39
39 41
41 42
42 46
46 49
49 50
50 52
52 55
55 57
57 59
59 60
60 61
61 62
62 63
63 66
66 69
69 70
70 71
71 75
75 76
76 80
80 84
84 87
87 91
91 93
93 94
94 96
96 10...

output:

502112931

result:

ok single line: '502112931'

Test #22:

score: 0
Accepted
time: 3210ms
memory: 462776kb

input:

500000 499999
4 7
7 8
8 9
9 10
10 11
11 12
12 14
14 15
15 16
16 17
17 18
18 19
19 21
21 22
22 23
23 24
24 27
27 30
30 31
31 32
32 33
33 35
35 36
36 39
39 40
40 44
44 45
45 46
46 48
48 49
49 50
50 51
51 52
52 53
53 54
54 56
56 57
57 58
58 59
59 60
60 61
61 62
62 64
64 65
65 66
66 67
67 68
68 69
69 75...

output:

624913928

result:

ok single line: '624913928'

Test #23:

score: 0
Accepted
time: 3198ms
memory: 462908kb

input:

500000 499999
1 3
3 4
4 5
5 6
6 8
8 9
9 10
10 12
12 14
14 15
15 19
19 21
21 25
25 28
28 29
29 30
30 31
31 32
32 33
33 34
34 36
36 37
37 42
42 45
45 46
46 48
48 49
49 50
50 54
54 56
56 57
57 58
58 61
61 67
67 68
68 70
70 71
71 73
73 74
74 75
75 76
76 78
78 79
79 80
80 82
82 84
84 85
85 87
87 93
93 96...

output:

855869095

result:

ok single line: '855869095'

Test #24:

score: 0
Accepted
time: 104ms
memory: 45276kb

input:

20000 19999
1 2
2 4
4 5
5 7
7 9
9 13
13 14
14 15
15 16
16 17
17 20
20 21
21 22
22 25
25 27
27 28
28 29
29 33
33 34
34 39
39 40
40 42
42 44
44 46
46 47
47 48
48 49
49 50
50 51
51 52
52 55
55 60
60 62
62 68
68 69
69 70
70 71
71 72
72 74
74 75
75 77
77 83
83 87
87 88
88 90
90 91
91 96
96 98
98 100
100 ...

output:

898746113

result:

ok single line: '898746113'

Test #25:

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

input:

200 199
2 3
3 7
7 9
9 11
11 18
18 21
21 22
22 23
23 24
24 25
25 26
26 29
29 30
30 33
33 35
35 36
36 38
38 39
39 46
46 47
47 48
48 50
50 53
53 56
56 58
58 60
60 61
61 64
64 66
66 68
68 70
70 73
73 76
76 79
79 80
80 81
81 84
84 85
85 89
89 90
90 92
92 94
94 96
96 97
97 98
98 115
115 102
102 103
103 10...

output:

27130982

result:

ok single line: '27130982'

Test #26:

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

input:

10 9
6 3
3 10
10 7
7 2
2 5
5 8
8 1
1 4
4 9

output:

26

result:

ok single line: '26'

Test #27:

score: 0
Accepted
time: 2909ms
memory: 457748kb

input:

500000 499999
187564 40668
40668 349455
349455 236165
236165 234125
234125 19156
19156 200503
200503 27193
27193 229119
229119 106828
106828 441617
441617 199617
199617 267010
267010 351798
351798 4127
4127 462764
462764 499225
499225 40019
40019 40149
40149 492337
492337 129118
129118 403985
403985...

output:

26

result:

ok single line: '26'

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%