QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#182835 | #3503. Misspelling | ClHg2 | 57 | 3275ms | 62220kb | C++14 | 1.8kb | 2023-09-18 16:42:43 | 2023-09-18 16:42:43 |
Judging History
answer
#include <algorithm>
#include <cstdint>
#include <iostream>
#define EVAL(x) cout << #x " = " << x << "\n"
namespace {
using std::cin;
using std::cout;
using std::int64_t;
const int kP = 1.0e9 + 7;
namespace mod {
inline int Mod(int x) { return x >= kP ? x - kP : x; }
inline void Add(int &x, int y) { x = Mod(x + y); }
} // namespace mod
const int kMaxN = 5.0e5 + 5;
int n, m;
int lt_bound[kMaxN], gt_bound[kMaxN];
int f[kMaxN][26];
class Fenwick {
public:
void Modify(int x, int val);
int Max(int x);
private:
int max_[kMaxN];
};
void Fenwick::Modify(int x, int val) {
x = n - x;
while (x <= n) max_[x] = val, x += x & -x;
}
int Fenwick::Max(int x) {
x = n - x;
int ans = 0;
while (x) ans = std::max(ans, max_[x]), x &= x - 1;
return ans;
}
Fenwick lt_tree, gt_tree;
} // namespace
int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
cin >> n >> m;
while (m--) {
int a, b;
cin >> a >> b;
if (a < b) {
gt_bound[a] = std::max(gt_bound[a], b - 1);
} else {
lt_bound[b] = std::max(lt_bound[b], a - 1);
}
}
std::fill_n(f[0], 26, 1);
int ans = 26;
for (int i = 1; i <= n - 1; ++i) {
gt_tree.Modify(gt_bound[i], i);
int j = gt_tree.Max(i);
for (int k = j; k < i; ++k) {
for (int prev_c = 0; prev_c < 26; ++prev_c) {
for (int c = prev_c + 1; c < 26; ++c) mod::Add(f[i][c], f[k][prev_c]);
}
}
lt_tree.Modify(lt_bound[i], i);
j = lt_tree.Max(i);
for (int k = j; k < i; ++k) {
for (int prev_c = 0; prev_c < 26; ++prev_c) {
for (int c = 0; c < prev_c; ++c) mod::Add(f[i][c], f[k][prev_c]);
}
}
for (int c = 0; c < 26; ++c) mod::Add(ans, f[i][c]);
}
cout << ans << "\n";
return 0;
}
详细
Subtask #1:
score: 8
Accepted
Test #1:
score: 8
Accepted
time: 1ms
memory: 7752kb
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: 1ms
memory: 7728kb
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: 7720kb
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: 1ms
memory: 7664kb
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: 7716kb
input:
10 1 4 2
output:
960864167
result:
ok single line: '960864167'
Test #6:
score: 0
Accepted
time: 1ms
memory: 7748kb
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: 1ms
memory: 7732kb
input:
2 1 1 2
output:
351
result:
ok single line: '351'
Test #8:
score: 0
Accepted
time: 1ms
memory: 7712kb
input:
2 2 2 1 1 2
output:
26
result:
ok single line: '26'
Subtask #2:
score: 20
Accepted
Test #9:
score: 20
Accepted
time: 3ms
memory: 7656kb
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: 0
Accepted
time: 0ms
memory: 7684kb
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:
324576383
result:
ok single line: '324576383'
Test #11:
score: 0
Accepted
time: 1ms
memory: 7724kb
input:
200 200 1 4 2 98 5 145 6 89 10 40 12 154 14 142 15 115 17 153 18 199 19 23 20 137 21 152 23 155 25 145 27 56 28 48 29 86 30 66 31 127 32 184 35 137 36 177 40 115 45 192 46 196 47 71 49 174 50 195 52 185 53 57 54 123 56 161 61 130 62 79 63 103 65 171 67 120 68 186 74 84 75 118 77 157 78 197 80 139 83...
output:
169274437
result:
ok single line: '169274437'
Test #12:
score: 0
Accepted
time: 1ms
memory: 7660kb
input:
200 200 1 152 3 147 4 21 7 146 10 174 12 89 13 154 17 165 18 96 19 71 20 55 23 100 24 162 25 127 28 99 29 166 32 43 34 55 36 159 37 167 38 113 40 116 42 47 43 146 44 97 46 102 49 180 50 197 51 119 52 115 55 124 56 102 57 73 59 187 61 157 62 167 63 143 66 136 67 160 71 195 72 147 74 169 78 163 81 190...
output:
117351
result:
ok single line: '117351'
Test #13:
score: 0
Accepted
time: 2ms
memory: 7748kb
input:
200 199 5 6 6 10 10 11 11 12 12 13 13 16 16 19 19 23 23 24 24 28 28 30 30 32 32 35 35 38 38 41 41 47 47 51 51 54 54 55 55 59 59 60 60 61 61 62 62 64 64 65 65 66 66 67 67 68 68 75 75 77 77 79 79 80 80 82 82 86 86 87 87 89 89 90 90 91 91 92 92 93 93 95 95 97 97 100 100 102 102 103 103 108 108 109 109 ...
output:
585503549
result:
ok single line: '585503549'
Test #14:
score: 0
Accepted
time: 0ms
memory: 7808kb
input:
200 199 2 3 3 7 7 8 8 9 9 12 12 13 13 16 16 18 18 20 20 21 21 22 22 75 75 25 25 29 29 31 31 32 32 33 33 35 35 39 39 40 40 41 41 43 43 45 45 46 46 47 47 49 49 50 50 52 52 53 53 55 55 59 59 60 60 63 63 65 65 67 67 69 69 70 70 73 73 74 74 76 76 78 78 82 82 83 83 84 84 91 91 94 94 98 98 100 100 101 101 ...
output:
240485564
result:
ok single line: '240485564'
Test #15:
score: 0
Accepted
time: 1ms
memory: 7816kb
input:
200 200 141 177 64 183 31 25 196 113 105 6 163 71 38 149 198 64 140 55 113 55 103 60 50 123 145 88 123 54 95 1 65 102 187 74 56 46 169 119 11 40 192 44 42 129 80 8 145 161 182 179 162 62 183 172 63 134 43 3 121 53 71 148 154 153 122 48 77 21 195 54 46 78 111 17 166 200 186 73 66 110 46 57 174 142 47...
output:
351
result:
ok single line: '351'
Test #16:
score: 0
Accepted
time: 2ms
memory: 7756kb
input:
200 10000 70 186 2 197 148 118 47 79 29 27 65 83 96 143 57 173 55 193 123 62 157 57 17 137 4 110 143 124 84 111 83 97 91 110 147 25 44 72 9 47 28 136 116 107 109 195 2 49 167 129 169 125 153 59 68 91 5 43 167 59 193 199 38 75 109 21 173 93 43 108 52 108 140 118 5 123 150 41 48 145 161 41 69 177 53 1...
output:
26
result:
ok single line: '26'
Test #17:
score: 0
Accepted
time: 9ms
memory: 7804kb
input:
200 1 9 162
output:
424803593
result:
ok single line: '424803593'
Test #18:
score: 0
Accepted
time: 2ms
memory: 7812kb
input:
200 100 139 171 104 173 71 168 139 166 159 182 176 2 71 103 59 131 25 70 12 23 49 127 100 108 171 128 187 59 29 190 16 32 131 63 146 186 188 56 51 117 98 169 38 25 46 43 189 103 155 83 151 7 28 114 125 158 158 190 104 29 142 173 198 106 28 8 54 39 35 121 175 17 4 47 183 108 157 124 4 178 12 2 103 22...
output:
11515858
result:
ok single line: '11515858'
Subtask #3:
score: 29
Accepted
Test #19:
score: 29
Accepted
time: 375ms
memory: 62216kb
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: 783ms
memory: 62148kb
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: 557ms
memory: 62212kb
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: 453ms
memory: 62220kb
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: 759ms
memory: 62144kb
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: 12ms
memory: 9212kb
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: 7660kb
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: 7788kb
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: 3275ms
memory: 62092kb
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
Time Limit Exceeded
Test #28:
score: 0
Time Limit Exceeded
input:
20000 10000 1 12498 2 4890 6 9894 7 15113 8 12798 9 16884 10 6938 12 15913 16 4036 17 15990 21 17803 23 9296 26 15532 27 11655 28 4917 30 10019 34 8147 38 7054 39 6590 40 16560 42 1907 46 14882 49 5312 50 948 51 15792 54 10799 56 11267 57 3435 58 4153 60 12999 61 2732 63 9843 65 10202 66 3849 67 142...
output:
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #41:
score: 0
Time Limit Exceeded
input:
500000 250000 3 134857 5 472819 6 33637 7 264857 8 30671 13 470140 17 112998 19 196477 22 262970 23 72130 25 165886 26 398558 29 243310 30 489865 31 409197 38 338668 40 337398 41 693 43 126674 44 491366 45 351893 46 240057 51 33944 53 151936 54 312222 55 466767 56 342191 57 262777 58 126907 60 29419...