QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#354809 | #5110. Splitstream | nvmdava | WA | 28ms | 4860kb | C++23 | 2.9kb | 2024-03-16 02:28:18 | 2024-03-16 02:28:18 |
Judging History
answer
#if not LOCAL
#define NDEBUG 1
#endif
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(auto i = a; i < (b); ++i)
#define down(x, a) for (auto x = a; x--;)
#define all(x) begin(x), end(x)
#define sz(x) int(size(x))
#define let auto const
using ll = long long;
using lint = ll;
using pii = pair<int, int>;
using vi = vector<int>;
struct Node {
Node *inp1 = nullptr, *inp2 = nullptr;
int siz;
bool isLe = false;
Node(int siz, bool isLe = false) : siz(siz), isLe(isLe){}
};
const int N = 100005;
Node* arr[N];
char cc[N];
int xx[N], yy[N], zz[N];
int help[N];
int indeg[N];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int m, n, q;
cin>>m>>n>>q;
arr[0] = new Node(m);
queue<int> que;
rep(i, 0, N) help[i] = -1;
rep(i, 0, n) {
cin>>cc[i]>>xx[i]>>yy[i]>>zz[i];
--xx[i]; --yy[i]; --zz[i];
if(xx[i] == 0) que.push(i);
if(cc[i] == 'M') {
indeg[i] = 2;
help[xx[i]] = i;
help[yy[i]] = i;
} else {
indeg[i] = 1;
help[xx[i]] = i;
}
}
while(!que.empty()) {
int x = xx[que.front()], y = yy[que.front()], z = zz[que.front()];
char c = cc[que.front()];
que.pop();
if(c == 'S') {
assert(arr[x] != nullptr);
assert(arr[y] == nullptr && arr[z] == nullptr);
arr[y] = new Node( (arr[x] -> siz + 1 ) / 2, true);
arr[z] = new Node( (arr[x] -> siz) / 2);
arr[y] -> inp1 = arr[x];
arr[z] -> inp1 = arr[x];
if(help[z] != -1 && --indeg[help[y]] == 0) que.push(help[y]);
if(help[z] != -1 && --indeg[help[z]] == 0) que.push(help[z]);
} else {
assert(arr[x] != nullptr && arr[y] != nullptr);
assert(arr[z] == nullptr);
arr[z] = new Node( arr[x] -> siz + arr[y] -> siz);
arr[z] -> inp1 = arr[x];
arr[z] -> inp2 = arr[y];
if(help[z] != -1 && --indeg[help[z]] == 0) que.push(help[z]);
}
}
while(q--) {
int x, k;
cin>>x>>k;
--x;
if(arr[x] == nullptr) {
cout<<"none\n";
continue;
}
Node *cur = arr[x];
while(cur != arr[0]) {
// cout<<(cur -> siz)<<' '<<cur -> inp1 -> siz<<' '<<cur -> inp2 -> siz<<'\n';
if(cur -> inp2 == nullptr) {
k = k * 2 - (cur -> isLe == true);
cur = cur -> inp1;
} else {
if(k <= 2 * min(cur -> inp1 -> siz, cur -> inp2 -> siz)) {
if(k % 2 == 1) {
cur = cur -> inp1;
k = (k + 1) / 2;
} else {
cur = cur -> inp2;
k = k / 2;
}
} else {
k -= min(cur -> inp1 -> siz, cur -> inp2 -> siz);
if(cur -> inp1 -> siz > cur -> inp2 -> siz) {
cur = cur -> inp1;
} else {
cur = cur -> inp2;
}
}
}
}
if(k > m) cout<<"none\n";
else cout<<k<<'\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4044kb
input:
5 8 26 M 8 9 13 S 2 4 5 S 1 2 3 M 6 5 8 S 4 9 10 S 10 14 15 S 3 6 7 S 7 11 12 2 3 2 4 3 2 3 3 4 2 4 3 5 1 5 2 6 1 6 2 7 1 7 2 8 2 8 3 9 1 9 2 10 1 10 2 11 1 11 2 12 1 13 3 13 4 14 1 14 2 15 1
output:
5 none 4 none 5 none 3 none 2 none 4 none 3 none 1 none 5 none 4 none none 3 none 5 none none
result:
ok 26 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 4792kb
input:
1000000000 8191 1000 S 1 2 3 S 2 4 5 S 3 6 7 S 4 8 9 S 5 10 11 S 6 12 13 S 7 14 15 S 8 16 17 S 9 18 19 S 10 20 21 S 11 22 23 S 12 24 25 S 13 26 27 S 14 28 29 S 15 30 31 S 16 32 33 S 17 34 35 S 18 36 37 S 19 38 39 S 20 40 41 S 21 42 43 S 22 44 45 S 23 46 47 S 24 48 49 S 25 50 51 S 26 52 53 S 27 54 55...
output:
1 3 999999999 499999999 333333331 999999997 499999997 333333329 2 4 1000000000 500000000 333333332 999999998 499999998 333333330 1 5 999999997 499999997 333333329 999999993 499999993 333333325 3 7 999999999 499999999 333333331 999999995 499999995 333333327 2 6 999999998 499999998 333333330 999999994...
result:
ok 1000 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 4860kb
input:
1000000000 8190 1000 S 1 2 3 M 8193 8194 8192 S 2 4 5 M 8195 8196 8193 S 3 6 7 M 8197 8198 8194 S 4 8 9 M 8199 8200 8195 S 5 10 11 M 8201 8202 8196 S 6 12 13 M 8203 8204 8197 S 7 14 15 M 8205 8206 8198 S 8 16 17 M 8207 8208 8199 S 9 18 19 M 8209 8210 8200 S 10 20 21 M 8211 8212 8201 S 11 22 23 M 821...
output:
1 2 1000000000 500000000 333333333 999999999 499999999 333333332 1 1 3 3 999999999 999999999 499999999 499999999 333333331 333333331 999999997 999999997 499999997 499999997 333333329 333333329 2 2 4 4 1000000000 1000000000 500000000 500000000 333333332 333333332 999999998 999999998 499999998 4999999...
result:
ok 1000 lines
Test #4:
score: 0
Accepted
time: 3ms
memory: 4716kb
input:
1000000000 10000 1000 S 1 2 3 S 2 4 5 S 4 6 7 S 6 8 9 S 8 10 11 S 10 12 13 S 12 14 15 S 14 16 17 S 16 18 19 S 18 20 21 S 20 22 23 S 22 24 25 S 24 26 27 S 26 28 29 S 28 30 31 S 30 32 33 S 32 34 35 S 34 36 37 S 36 38 39 S 38 40 41 S 40 42 43 S 42 44 45 S 44 46 47 S 46 48 49 S 48 50 51 S 50 52 53 S 52 ...
output:
1 1 536870913 1000000000 2 999999998 3 999999999 4 999999996 5 999999995 6 999999994 7 999999997 8 999999992 9 999999991 10 999999990 11 999999989 12 999999988 13 999999987 14 999999986 15 999999993 16 999999984 17 999999983 18 999999982 19 999999981 20 999999980 21 999999979 22 999999978 23 9999999...
result:
ok 1000 lines
Test #5:
score: 0
Accepted
time: 28ms
memory: 4712kb
input:
1000000000 10000 1000 S 1 2 3 S 2 4 5 M 5 3 6 S 4 7 8 M 8 6 9 S 7 10 11 M 11 9 12 S 10 13 14 M 14 12 15 S 13 16 17 M 17 15 18 S 16 19 20 M 20 18 21 S 19 22 23 M 23 21 24 S 22 25 26 M 26 24 27 S 25 28 29 M 29 27 30 S 28 31 32 M 32 30 33 S 31 34 35 M 35 33 36 S 34 37 38 M 38 36 39 S 37 40 41 M 41 39 4...
output:
1 999999998 536870913 999999996 268435457 999999994 134217729 999999992 805306369 999999990 67108865 999999988 402653185 999999986 33554433 999999984 671088641 999999982 201326593 999999980 939524097 999999978 16777217 999999976 335544321 999999974 100663297 999999972 469762049 999999970 8388609 999...
result:
ok 1000 lines
Test #6:
score: 0
Accepted
time: 6ms
memory: 4700kb
input:
1000000000 10000 120 S 1 2 3 M 3 2 4 S 4 5 6 M 6 5 7 S 7 8 9 M 9 8 10 S 10 11 12 M 12 11 13 S 13 14 15 M 15 14 16 S 16 17 18 M 18 17 19 S 19 20 21 M 21 20 22 S 22 23 24 M 24 23 25 S 25 26 27 M 27 26 28 S 28 29 30 M 30 29 31 S 31 32 33 M 33 32 34 S 34 35 36 M 36 35 37 S 37 38 39 M 39 38 40 S 40 41 42...
output:
1 999999999 3 999999997 5 999999995 7 999999993 9 999999991 11 999999989 13 999999987 15 999999985 17 999999983 19 999999981 2 1000000000 4 999999998 6 999999996 8 999999994 10 999999992 12 999999990 14 999999988 16 999999986 18 999999984 20 999999982 2 999999999 1 1000000000 4 999999997 3 999999998...
result:
ok 120 lines
Test #7:
score: 0
Accepted
time: 8ms
memory: 4700kb
input:
1000000000 9998 260 S 1 2 3 S 2 4 5 S 3 6 7 M 4 6 8 M 5 7 9 S 8 10 11 S 9 12 13 M 10 12 14 M 11 13 15 S 14 16 17 S 15 18 19 M 16 18 20 M 17 19 21 S 20 22 23 S 21 24 25 M 22 24 26 M 23 25 27 S 26 28 29 S 27 30 31 M 28 30 32 M 29 31 33 S 32 34 35 S 33 36 37 M 34 36 38 M 35 37 39 S 38 40 41 S 39 42 43 ...
output:
1 999999997 5 999999993 9 999999989 13 999999985 17 999999981 21 999999977 25 999999973 29 999999969 33 999999965 37 999999961 2 999999998 6 999999994 10 999999990 14 999999986 18 999999982 22 999999978 26 999999974 30 999999970 34 999999966 38 999999962 3 999999999 7 999999995 11 999999991 15 99999...
result:
ok 260 lines
Test #8:
score: 0
Accepted
time: 4ms
memory: 4700kb
input:
1000000000 10000 1000 S 2816 2882 2883 S 625 669 670 S 6854 7128 7129 M 5200 5017 5204 M 14100 14126 14151 M 13883 13804 13914 M 6816 6875 6901 M 11434 11803 11832 S 1681 1710 1711 S 1271 1312 1313 S 12100 12196 12197 M 347 378 456 M 4096 4064 4190 S 9177 9253 9254 M 554 225 746 M 10210 10256 10345 ...
output:
410542848 488844679 937935067 819832776 719109937 692579778 736124132 68676658 543140981 273960384 244177174 146341334 492672362 52284117 658245275 542648314 373316895 325695562 344652426 896047680 626880168 425102056 481091069 406672794 530596564 889101874 842378664 486416028 643174340 754279819 33...
result:
ok 1000 lines
Test #9:
score: 0
Accepted
time: 0ms
memory: 4704kb
input:
1000000000 10000 1000 M 5215 5209 5225 S 6624 6750 6751 S 12896 12936 12937 S 5790 5819 5820 S 1101 1160 1161 S 11444 11500 11501 S 11803 11909 11910 S 11713 11771 11772 S 4227 4295 4296 S 8171 8267 8268 S 6511 6659 6660 M 13671 13774 13823 M 183 306 392 S 11310 11868 11869 M 4599 4401 4623 M 13434 ...
output:
158545516 276771801 872580399 227403884 326752219 708606434 866158890 578794373 549989532 721061337 843206532 99079001 475183478 883716291 579165343 555386147 336634476 739477362 485935976 265683774 771204600 107456831 845075569 414509171 349595259 357305487 616396118 205650066 298870564 465702962 4...
result:
ok 1000 lines
Test #10:
score: 0
Accepted
time: 4ms
memory: 4772kb
input:
1000000000 10000 1000 M 9932 9892 9977 M 8446 8364 8573 M 12477 12381 12493 S 7746 7826 7827 M 2698 2653 2735 M 9532 9541 9581 S 2334 2443 2444 S 8507 8726 8727 S 8512 8611 8612 M 1964 1959 2054 M 1218 1209 1256 M 8633 8583 8707 M 11304 11219 11348 M 5544 5501 5724 M 13579 13789 13793 S 6811 6948 69...
output:
358216369 765714662 720619982 383094630 583222016 403904399 540799071 732725672 529435876 467351271 344056601 570019702 221689159 201296808 982834620 39561719 777523667 846368600 271296 384939959 513016697 736586673 272490880 913146907 78750430 191506974 99535212 616919370 317530836 761192053 650871...
result:
ok 1000 lines
Test #11:
score: 0
Accepted
time: 4ms
memory: 4712kb
input:
1000000000 10000 1000 S 13981 14119 14120 M 4081 4061 4355 M 5542 5302 5711 S 7989 8330 8331 S 3733 3767 3768 S 14329 14364 14365 S 8472 8501 8502 M 13897 13909 13957 S 5940 5971 5972 S 2642 2843 2844 S 5699 5702 5703 M 464 392 502 S 717 980 981 M 13890 13671 13902 S 6210 6224 6225 S 10149 11187 111...
output:
946583475 39950867 12114520 344042237 925236152 196637666 522940481 585398886 153165178 111583555 605886099 982385470 322756559 612482216 897028405 972371026 571912484 93984365 630146423 284805281 584957467 351316787 631855216 707739262 808047962 89733919 834604257 813408335 454854794 759626715 5796...
result:
ok 1000 lines
Test #12:
score: 0
Accepted
time: 4ms
memory: 4740kb
input:
1000000000 10000 1000 S 14044 14074 14075 S 10989 11010 11011 S 3009 3171 3172 M 1137 1186 1222 S 13599 13802 13803 S 345 506 507 S 10014 10147 10148 M 11082 11316 11319 S 13661 13776 13777 S 18 20 21 S 14734 14780 14781 M 4887 4827 4888 S 5241 5279 5280 M 9803 9583 9806 S 13548 13589 13590 S 2439 2...
output:
373564651 135588323 235943754 310533534 357785906 269064756 846167599 701246756 372231499 246040914 128072793 305568608 131705549 141589287 379549707 264932775 106219309 675198886 11065755 143823582 201985355 560673344 890446547 435573742 295516854 942017776 426261404 471127122 628046718 577131205 9...
result:
ok 1000 lines
Test #13:
score: 0
Accepted
time: 1ms
memory: 4068kb
input:
6807 1363 1000 S 166 284 285 M 1818 1848 1870 M 477 486 492 M 1836 1827 1838 M 1958 1964 1965 M 875 840 930 S 1379 1427 1428 M 1634 1639 1653 S 245 251 252 M 1536 1700 1733 S 1780 1794 1795 S 426 515 516 M 1708 1703 1740 S 1734 1785 1786 M 427 409 466 M 449 423 457 S 1212 1236 1237 S 1122 1130 1131 ...
output:
3857 6410 388 610 4546 6570 3907 5794 2201 3916 3863 5557 2009 1782 942 879 1395 4980 1955 784 5424 4493 1186 6665 6744 4501 5774 4549 4496 1240 1433 2386 667 3323 2230 6234 163 3108 4022 4343 1503 5806 1295 4783 3085 1090 4278 4496 2424 2581 584 6049 1950 25 6646 1124 449 5248 5442 5799 5594 5991 6...
result:
ok 1000 lines
Test #14:
score: 0
Accepted
time: 2ms
memory: 4612kb
input:
1900 5736 1000 S 3071 3162 3163 S 2435 2454 2455 S 180 209 210 M 4303 4279 4313 M 93 124 126 S 85 91 92 S 4359 4420 4421 M 7328 7378 7384 S 3804 3807 3808 M 5154 5155 5178 S 8230 8287 8288 M 2981 2886 3040 S 3029 3077 3078 S 6331 6342 6343 M 3706 3663 3710 M 7325 7276 7330 S 305 524 525 S 7469 7573 ...
output:
1215 72 554 995 937 1349 1878 198 558 570 1137 493 1217 1057 1322 292 250 177 1032 316 793 1151 714 77 123 1223 1836 1262 842 1531 235 1443 1732 41 176 1151 837 307 340 662 445 1472 38 1808 1043 1067 1780 869 1369 271 1172 871 1813 227 1484 1349 667 31 295 77 377 1643 934 638 1027 811 934 165 781 45...
result:
ok 1000 lines
Test #15:
score: 0
Accepted
time: 3ms
memory: 4564kb
input:
7794 7236 1000 M 1425 1036 1429 M 469 338 472 M 4284 4411 4414 S 1013 1356 1357 S 6979 6994 6995 S 1653 1876 1877 S 62 81 82 M 5145 5090 5260 S 2017 2060 2061 M 7588 7612 7700 S 172 383 384 S 4025 4065 4066 M 1037 1044 1054 S 6407 6603 6604 S 8354 8419 8420 S 8966 9192 9193 S 330 361 362 M 3417 3409...
output:
1250 6640 4138 126 4249 5828 2883 3362 7205 3447 1312 3239 6717 6217 3684 1247 651 3141 5848 1885 2387 4964 6382 3516 385 7682 4488 2631 2114 6338 3870 3125 1550 4200 5004 1543 7517 483 5121 5272 3485 3231 1 3065 7361 6621 291 2521 3216 178 6073 4148 6403 7496 365 1383 1753 7213 171 7300 5170 1063 6...
result:
ok 1000 lines
Test #16:
score: 0
Accepted
time: 2ms
memory: 4304kb
input:
5563 4583 1000 S 2441 2706 2707 M 2339 2227 2392 S 4216 4251 4252 S 6010 6168 6169 M 1769 1779 1792 M 1809 1755 1815 S 6395 6451 6452 M 1352 1500 1517 S 286 399 400 M 5355 5161 5401 M 3163 3122 3180 M 1766 1859 1860 S 119 124 125 M 3266 3517 3537 S 5165 5196 5197 S 6290 6336 6337 M 6714 6672 6723 M ...
output:
1073 3728 3078 1217 2337 3532 5106 2251 635 2081 5230 2656 3248 3396 1626 3119 1970 4947 3995 852 2857 3301 2884 518 4776 1705 2775 1415 2488 4981 422 330 1518 2331 539 4140 1160 2453 3912 2802 5381 2173 3704 5044 1121 509 4696 2735 1193 5415 1121 1239 1310 1485 4799 4793 1846 4157 3878 4544 3503 39...
result:
ok 1000 lines
Test #17:
score: 0
Accepted
time: 0ms
memory: 4152kb
input:
190 2488 1000 M 3666 3728 3729 M 3670 3595 3705 M 67 72 112 S 2413 2451 2452 S 2608 2689 2690 S 1851 1997 1998 S 3078 3091 3092 S 3243 3291 3292 S 1164 1202 1203 S 2338 2343 2344 S 600 739 740 S 1982 2035 2036 S 1595 1768 1769 S 301 316 317 M 2354 2292 2422 S 1223 1227 1228 S 40 58 59 S 1343 1432 14...
output:
182 140 166 178 38 166 186 170 63 133 66 100 157 123 48 138 126 46 31 56 154 70 133 180 83 56 66 120 53 182 171 184 3 23 167 190 11 53 119 143 111 156 163 13 126 63 138 174 70 160 80 78 12 162 156 96 70 187 165 145 91 69 154 93 155 21 115 178 39 140 33 146 189 80 156 154 128 185 91 56 188 107 64 48 ...
result:
ok 1000 lines
Test #18:
score: 0
Accepted
time: 1ms
memory: 3972kb
input:
889966903 51 1000 M 31 34 40 M 27 33 35 M 23 10 29 S 20 24 25 S 71 73 74 M 13 11 14 S 57 63 64 M 14 28 30 S 30 36 37 S 29 38 39 M 61 76 77 S 5 15 16 M 54 37 60 S 40 41 42 M 12 9 13 M 67 73 76 S 51 56 57 S 66 68 69 M 65 63 67 M 77 75 78 M 7 8 10 S 2 8 9 S 50 51 52 M 60 55 66 M 59 49 65 M 42 47 50 M 4...
output:
187821228 366651030 52852727 308067944 354657940 232789970 421616206 283181248 792111684 852513733 324668148 429039954 767584290 796252534 699591398 425184006 302588861 59135876 110071181 844739244 864085254 363892328 273236460 439943138 177830156 711773080 883025868 295196499 273307628 879769376 49...
result:
ok 1000 lines
Test #19:
score: -100
Wrong Answer
time: 0ms
memory: 3996kb
input:
77957119 65 1000 S 1 2 3 S 55 65 66 M 58 36 67 M 60 62 69 S 71 82 83 M 14 9 15 M 90 84 96 M 51 44 57 S 47 48 49 M 69 70 79 M 76 66 85 M 52 73 78 M 97 87 98 S 29 42 43 M 95 98 99 M 19 11 23 S 49 70 71 S 17 29 30 M 46 54 60 M 96 88 97 S 45 52 53 M 79 89 92 S 32 34 35 S 8 13 14 S 43 46 47 S 50 58 59 S ...
output:
7244754 75815519 63867856 19261728 27671677 29262969 none 67136232 45909545 77466057 47958265 75764413 70563711 58188431 40107756 64606749 7396261 30335055 3067797 69529315 10413795 55662713 43804189 31621753 59669028 43367108 49932119 66653748 73768429 61628007 4796742 1499769 38379529 14814508 378...
result:
wrong answer 7th lines differ - expected: '51363826', found: 'none'