QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#119882 | #1994. Help Yourself | bashkort# | 0 | 0ms | 0kb | C++20 | 3.4kb | 2023-07-05 23:41:15 | 2023-07-05 23:41:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int MOD = 1e9 + 7, N = 2e5 + 7, maxK = 11;
int dp[N], suf[N], pw2[N], F[maxK];
void rec(int n, int k, int s, int d) {
if (n == k) {
F[s] = (F[s] + d) % MOD;
} else {
rec(n + 1, k, s + 1, d * 1LL * (s + 1) % MOD);
if (s) {
for (int i = 0; i < s; ++i) {
rec(n + 1, k, s, d);
}
}
}
}
namespace SegmentTree {
vector<int> t, tag;
int sz = 1;
void pull(int x) {
t[x] = t[x << 1] + t[x << 1 | 1];
if (t[x] >= MOD) {
t[x] -= MOD;
}
}
void apply(int x, int tg) {
t[x] = 1LL * t[x] * tg % MOD;
tag[x] = 1LL * tag[x] * tg % MOD;
}
void push(int x) {
if (tag[x] != 1) {
apply(x << 1, tag[x]);
apply(x << 1 | 1, tag[x]);
tag[x] = 1;
}
}
void init(int n) {
sz = 1 << __lg(n) + !!(n & (n - 1));
t.assign(sz << 1, 0), tag.assign(sz << 1, 1);
for (int i = 0; i < n; ++i) {
t[i + sz] = dp[i];
}
for (int i = sz - 1; i > 0; --i) {
pull(i);
}
}
int rangeSum(int l, int r, int x = 1, int lx = 0, int rx = sz) {
if (l >= rx || lx >= r) {
return 0;
}
if (l <= lx && rx <= r) {
return t[x];
}
push(x);
int mid = lx + rx >> 1;
int ans = rangeSum(l, r, x << 1, lx, mid) + rangeSum(l, r, x << 1 | 1, mid, rx);
return ans < MOD ? ans : ans - MOD;
}
void rangeApply(int l, int r, int tg, int x = 1, int lx = 0, int rx = sz) {
if (l >= rx || lx >= r) {
return;
}
if (l <= lx && rx <= r) {
return apply(x, tg);
}
int mid = lx + rx >> 1;
push(x);
rangeApply(l, r, tg, x << 1, lx, mid), rangeApply(l, r, tg, x << 1 | 1, mid, rx);
pull(x);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
freopen("help.in", "r", stdin);
freopen("help.out", "w", stdout);
int n, k;
cin >> n >> k;
vector<pair<int, int>> seg(n);
vector<int> s, h(n);
for (auto &[l, r] : seg) {
cin >> l >> r;
l -= 1, r -= 1;
suf[l] += 1;
s.push_back(r);
}
sort(s.begin(), s.end());
sort(seg.begin(), seg.end(), [&](auto &x, auto &y) { return x.second < y.second; });
for (int i = 0; i < n; ++i) {
h[i] = lower_bound(s.begin(), s.end(), seg[i].first) - s.begin();
}
for (int i = 2 * n - 1; i >= 0; --i) {
suf[i] += suf[i + 1];
}
pw2[0] = 1;
for (int i = 1; i <= n; ++i) {
pw2[i] = pw2[i - 1] * 2;
if (pw2[i] >= MOD) {
pw2[i] -= MOD;
}
}
rec(0, k, 0, 1);
int ans = 0;
for (int cnt = 1; cnt <= k; ++cnt) {
if (cnt > 1) {
SegmentTree::init(n);
}
for (int i = 0; i < n; ++i) {
auto [l, r] = seg[i];
dp[i] = cnt == 1 ? pw2[i] : SegmentTree::rangeSum(0, h[i]);
ans = (ans + 1LL * dp[i] * F[cnt] % MOD * pw2[suf[r]]) % MOD;
if (cnt > 1) {
SegmentTree::rangeApply(0, h[i], 2);
}
}
}
cout << ans << '\n';
return 0;
}
详细
Test #1:
score: 0
Dangerous Syscalls
input:
3 2 1 6 2 3 4 5
output:
result:
Test #2:
score: 0
Dangerous Syscalls
input:
16 10 1 27 17 18 10 31 2 26 11 12 23 24 13 14 8 28 9 19 5 6 4 22 15 16 29 30 3 32 20 21 7 25
output:
result:
Test #3:
score: 0
Dangerous Syscalls
input:
1000 2 257 1057 425 426 820 1932 38 39 149 150 466 965 1974 1975 777 1227 631 632 647 1363 1621 1626 250 255 786 1698 453 801 522 1090 263 1040 1850 1851 920 1953 93 467 1034 1035 1062 1458 854 1711 472 473 500 501 679 776 477 653 1278 1279 1140 1141 921 1824 244 912 434 787 603 604 1763 1764 1326 1...
output:
result:
Test #4:
score: 0
Dangerous Syscalls
input:
1000 2 50 937 4 1229 470 1986 1979 1980 1422 1425 245 246 1797 1798 996 1777 585 1880 1762 1763 713 1465 402 1637 1572 1697 604 1878 1193 1194 897 900 1420 1421 1081 1756 708 749 319 320 1268 1746 278 1170 1223 1975 1993 1994 12 13 947 950 766 767 773 1233 1339 1693 241 1935 333 334 568 569 55 56 42...
output:
result:
Test #5:
score: 0
Dangerous Syscalls
input:
1000 2 1176 1179 1085 1412 1364 1365 688 1974 76 77 1194 1195 429 430 1958 1959 1021 1022 723 1180 27 1954 7 1735 366 373 1756 1757 1711 1714 1473 1474 1233 1234 227 237 500 1137 46 434 482 483 625 1124 1348 1349 570 862 1272 1273 1300 1560 854 855 913 914 1326 1327 1655 1656 177 178 1957 1960 369 3...
output:
result:
Test #6:
score: 0
Dangerous Syscalls
input:
1000 4 1626 1627 1096 1097 318 1513 14 17 261 262 724 896 1259 1260 1754 1757 443 1105 1715 1732 1112 1113 641 1527 1134 1135 698 699 1278 1279 1482 1483 437 1001 1870 1871 1288 1512 1306 1307 324 1933 822 1354 1369 1370 1911 1912 509 510 75 1132 1172 1834 1609 1610 1350 1351 163 164 742 1690 875 14...
output:
result:
Test #7:
score: 0
Dangerous Syscalls
input:
1000 7 327 895 1624 1625 405 1088 302 898 1482 1483 1972 1973 890 1071 870 871 1239 1240 1266 1267 507 508 661 1399 100 1976 388 1825 947 1027 270 354 679 1984 1313 1314 733 1318 742 1567 766 767 1941 1942 793 1893 150 823 1785 1981 1145 1146 1393 1394 235 236 99 228 221 222 1079 1080 522 523 1498 1...
output:
result:
Test #8:
score: 0
Dangerous Syscalls
input:
1000 10 802 1951 1340 1891 1168 1169 241 1072 83 551 1353 1354 1208 1209 235 1266 542 543 852 1644 1979 1980 400 401 1487 1895 259 260 632 1701 1575 1576 145 166 1059 1060 454 1789 570 571 1226 1227 1785 1786 690 1303 607 711 771 1591 930 931 616 617 783 1512 533 534 17 1019 356 1963 1011 1012 224 6...
output:
result:
Test #9:
score: 0
Dangerous Syscalls
input:
100000 3 5897 129730 49170 49173 41237 195778 83686 83687 70752 169816 17614 155410 71945 71946 86519 86520 90441 188046 21675 86380 59295 175039 51025 51032 178949 178952 37108 167629 785 92071 65649 65650 123391 154617 21550 85959 12167 83461 43696 43697 176913 176914 29066 172054 118261 123679 14...
output:
result:
Test #10:
score: 0
Dangerous Syscalls
input:
100000 4 123504 184162 20162 89295 68630 178121 66955 66956 70359 97517 61324 61325 8946 24830 26607 26618 11625 84350 22486 177973 20921 95731 99675 101231 87061 87062 13510 165260 184835 184836 83349 118398 150270 150271 171421 171422 102061 102062 166865 169287 83147 158219 6883 123997 8129 19366...
output:
result:
Test #11:
score: 0
Dangerous Syscalls
input:
100000 5 103555 103556 197996 197997 7531 7534 16803 16804 43303 192313 98700 98703 3828 44087 34944 121506 88926 161497 10230 187676 92128 92129 50714 154647 18309 47556 189146 189149 110028 110029 34142 34143 15635 78638 70191 70192 168616 174129 85083 85084 24028 198335 87670 87671 85241 183910 1...
output:
result:
Test #12:
score: 0
Dangerous Syscalls
input:
100000 6 39844 39845 132423 132424 156679 168289 138276 190905 77382 77385 146359 146360 29459 78378 132558 132563 136176 139868 112048 132732 565 146568 192272 192273 123835 123836 197052 197053 32916 179043 113290 113291 75390 75391 94543 94544 13614 13615 155796 155797 24149 24150 193714 193715 1...
output:
result:
Test #13:
score: 0
Dangerous Syscalls
input:
100000 7 87512 165950 84143 123927 165636 179507 36811 36812 18329 18330 114502 148151 139071 185081 91730 91731 49313 49314 183018 191733 171425 188707 94550 94557 36327 36328 43223 70541 23550 133579 20097 159492 155228 183836 49824 49827 65432 65433 132062 160411 884 1265 68662 165949 3 40610 317...
output:
result:
Test #14:
score: 0
Dangerous Syscalls
input:
100000 8 139479 139484 99908 99909 135422 135423 67569 69636 802 151050 59603 88814 42977 42980 48428 181292 9580 9581 61911 134518 139946 194227 129660 129661 107449 107450 19003 93339 8687 143543 173212 173213 159562 159563 86083 86084 21380 90431 41773 139333 134520 183413 32986 164876 16973 1697...
output:
result:
Test #15:
score: 0
Dangerous Syscalls
input:
100000 9 164083 164084 86222 86223 103475 103476 117198 117982 57195 196206 8879 150459 7019 7020 50629 74897 179088 194710 79291 79292 24223 113740 64371 64372 178499 178500 61016 123565 12463 181442 151509 151514 17374 92041 88281 123328 8433 63088 84772 84773 179332 179333 15778 15779 29225 15850...
output:
result:
Test #16:
score: 0
Dangerous Syscalls
input:
100000 10 4554 53630 20155 75946 27190 27191 42002 42003 14806 144285 82294 182737 153131 161387 143573 143574 109935 174947 105934 105935 3173 168965 117399 117400 174029 174030 187839 187840 11893 38358 119473 138362 75229 75230 8795 194263 50063 159286 81580 81581 12311 120375 195657 195658 97402...