QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#383196 | #7771. 不是这一道据数构结题 | valeriu | 0 | 645ms | 65868kb | C++20 | 3.3kb | 2024-04-09 03:36:22 | 2024-04-09 03:36:24 |
Judging History
answer
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using ld = long double;
//#define int ll
#define sz(x) ((int)(x).size())
using pii = pair<int,int>;
using tii = tuple<int,int,int>;
const int nmax = 1e6 + 5;
#define lsb(x) (x & -x)
struct AIB {
vector<int> tree;
void init(int n) {
tree.assign(n + 2, 0);
}
void upd(int p, int x) {
p++;
while(p < sz(tree)) tree[p] += x, p += lsb(p);
}
int query(int p) {
p++;
int sum = 0;
while(p > 0) sum += tree[p], p -= lsb(p);
return sum;
}
} aib;
int sum[nmax];
void add(int p, int x) {
aib.upd(p, x);
}
int query(int l, int r) {
int total = r - l + 1;
return total + aib.query(r) - aib.query(l - 1);
}
template<typename Node>
struct AINT {
vector<Node> aint;
int n;
void init(int n_, Node TMP = Node()) {
n = n_;
aint.assign(2 * n + 10, TMP);
}
template<class CB> void walk(CB&& cb) { walk(cb, 0, n - 1); }
template<class CB> void walk(CB&& cb, int l, int r) { walk(cb, l, r, 1, 0, n - 1); }
template<class CB> void walk(CB&& cb, int l, int r, int node, int cl, int cr) {
if(cr < l || r < cl) return;
if(l <= cl && cr <= r && !cb(aint[node], cl, cr)) return;
int mid = (cl + cr) >> 1, L = node + 1, R = node + (mid - cl + 1) * 2;
walk(cb, l, r, L, cl, mid);
walk(cb, l, r, L, mid + 1, cr);
aint[node].pull(aint[L], aint[R]);
}
};
struct Node {
int mx;
void pull(Node& L, Node& R) {
*this = Node(max(L.mx, R.mx));
}
};
vector<pii> qs[nmax];
int rez[nmax];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int n, q;
cin >> n >> q;
aib.init(n + 1);
vector<int> v(n);
for(auto &x : v) cin >> x;
AINT<Node> aint;
aint.init(n);
aint.walk([&](Node& val, int cl, int cr) {
if(cl != cr) return 1;
val.mx = v[cl];
return 0;
});
auto nxt_gval = [&](int p, int target) {
if(p >= n) return n;
p++;
int rez = p;
aint.walk([&](Node& val, int cl, int cr) {
if(cl != rez) return 0;
if(val.mx <= target) { rez = cr + 1; return 0;}
if(cl == cr) {
rez = cl;
return 0;
}
return 1;
}, p, n - 1);
//cerr << rez << '\n';
return rez;
};
for(int tc = 0, l, r; tc < q; tc++) {
cin >> l >> r;
--l;
--r;
qs[l].emplace_back(r, tc);
}
struct st_elem {
int val;
int poz;
int borderpoz;
};
vector<st_elem> st;
for(int i = n - 1; i >= 0; i--) {
while(!st.empty() && st.back().val > v[i]) {
add(st.back().poz, 1);
add(st.back().borderpoz, -1);
st.pop_back();
}
add(i, -1);
if(st.empty())
st.emplace_back(v[i], i, n);
else
st.emplace_back(v[i], i, nxt_gval(st.back().val == v[i]? st.back().borderpoz : st.back().poz, v[i]));
add(st.back().borderpoz, 1);
for(auto [r, ptr] : qs[i])
rez[ptr] = query(i, r);
}
for(int i = 0; i < q; i++) cout << rez[i] << '\n';
}
/**
Anul asta nu se da centroid
-- Rugaciunile mele
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3640kb
input:
100 100 57 39 73 88 98 3 54 10 63 31 96 22 94 53 99 66 7 90 29 27 91 37 74 4 64 43 86 100 12 58 78 97 75 87 36 51 40 20 48 92 26 72 89 85 46 13 55 80 6 47 41 17 30 25 60 35 93 28 69 16 83 23 1 34 56 45 18 21 38 11 68 71 8 2 84 76 15 33 44 81 77 82 70 24 67 95 61 9 32 49 50 65 19 59 5 42 14 62 52 79 ...
output:
64 91 15 7 10 1 56 20 0 11 48 7 3 13 5 36 11 85 2 52 36 0 45 65 43 21 3 30 41 22 50 53 31 17 34 37 36 8 55 38 15 2 10 3 40 86 46 8 1 34 16 78 13 57 18 56 45 8 67 39 14 78 46 54 12 29 79 7 4 64 37 18 4 34 30 38 42 3 7 17 14 16 37 58 63 47 31 10 8 16 22 64 50 0 39 45 1 23 6 0
result:
wrong answer 1st numbers differ - expected: '65', found: '64'
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 3684kb
input:
100 100 2 3 1 3 3 8 1 1 1 3 2 3 2 75 1 44 78 3 3 65 2 1 3 3 90 2 1 1 1 2 2 2 1 2 9 3 24 1 2 1 89 2 2 42 2 66 1 1 19 25 3 2 3 2 3 51 1 1 3 1 3 29 21 2 2 2 1 2 1 3 3 2 84 2 1 11 2 2 3 2 9 1 1 1 1 99 48 1 77 3 9 78 69 1 2 1 1 2 1 2 21 68 41 76 9 76 7 43 30 81 45 84 81 83 23 45 57 91 17 65 72 81 39 91 3...
output:
34 24 51 26 38 28 0 14 24 33 7 38 34 6 47 24 48 26 33 52 10 2 31 11 52 21 47 57 10 58 48 24 5 26 23 2 24 47 13 13 55 27 21 49 49 4 4 50 8 25 9 10 26 23 26 15 26 50 26 17 4 43 40 1 43 31 56 51 25 22 44 12 19 27 16 4 8 1 2 35 1 13 65 41 21 7 13 14 58 6 11 25 45 41 31 44 47 24 6 53
result:
wrong answer 1st numbers differ - expected: '35', found: '34'
Test #3:
score: 0
Wrong Answer
time: 2ms
memory: 3872kb
input:
3000 3000 82 1139 2770 344 363 880 427 2001 207 2969 1309 2063 2349 1817 1869 2724 2380 1887 1377 1422 1732 449 2105 1706 1155 2417 963 308 1996 2788 737 1963 1973 1163 2899 2438 760 1995 1435 1750 1947 2863 1606 1078 493 2922 1478 607 1871 2191 2978 2587 1699 332 1581 2048 68 350 2220 1306 1633 187...
output:
1464 908 1099 255 2577 10 1176 329 1715 2227 627 47 1353 1452 638 2746 1024 833 637 605 989 1107 1132 1186 152 2260 978 992 640 1104 685 2319 1892 162 1156 1113 1682 783 731 2043 477 334 983 889 2090 5 1260 983 615 1049 1375 1505 1820 1158 1168 599 657 295 23 169 2604 1663 1979 1664 1040 1133 156 48...
result:
wrong answer 39th numbers differ - expected: '732', found: '731'
Test #4:
score: 0
Wrong Answer
time: 2ms
memory: 3712kb
input:
3000 3000 2120 271 658 684 1092 795 2522 2924 2204 382 709 1351 2977 1639 1190 2472 458 1337 1034 566 2644 664 1224 1410 1820 625 2203 2045 1979 2297 2926 1238 2014 1492 1372 2594 1324 1854 1968 1074 919 2345 1544 1880 626 2505 1742 1427 2892 99 447 1732 2273 2490 1166 2419 2717 1248 2493 1048 2291 ...
output:
1077 883 1831 56 330 100 2421 578 1207 1586 477 1117 2741 1546 1245 55 1398 1044 826 267 456 861 248 1299 1819 278 221 1047 2444 1174 2459 421 801 75 367 845 872 1005 417 988 721 449 341 2529 379 1159 2688 255 23 210 1699 802 42 1077 335 2 3 113 1648 1871 687 737 70 402 2426 780 466 1289 2056 754 10...
result:
wrong answer 1st numbers differ - expected: '1079', found: '1077'
Test #5:
score: 0
Wrong Answer
time: 0ms
memory: 3776kb
input:
3000 3000 2637 1681 2145 1131 33 618 2714 914 2587 2182 1823 1044 1320 2020 568 2 411 902 523 2075 910 459 124 669 1546 2593 1314 312 2736 1408 1578 28 291 1017 421 798 2202 978 597 2246 1349 1486 2756 2464 1912 636 1130 201 648 882 2737 2066 2007 1758 91 2923 49 1288 2254 776 2814 1315 1665 2306 25...
output:
705 474 1002 1840 193 1483 1273 2298 83 1736 2235 297 257 853 1431 2481 1693 866 1635 330 1067 725 371 25 858 1509 1475 232 366 1478 88 776 172 163 951 1528 806 1214 134 1467 572 547 439 102 24 2107 1457 1251 1263 260 9 223 582 1437 1794 1896 171 954 1412 1297 572 502 1606 976 436 1564 650 2448 113 ...
result:
wrong answer 1st numbers differ - expected: '708', found: '705'
Test #6:
score: 0
Wrong Answer
time: 0ms
memory: 3836kb
input:
3000 3000 15 64 32 83 23 22 48 7 68 36 43 75 29 17 37 97 92 42 50 87 73 43 12 48 83 44 1 13 23 96 48 60 99 26 2 104 73 73 64 61 64 49 67 94 89 9 96 102 66 19 95 2 29 78 102 61 77 84 34 92 36 31 44 25 68 47 137 131 75 37 21 173 62 44 36 53 19 165 98 100 95 57 85 32 87 69 118 85 24 35 36 98 47 44 92 2...
output:
467 721 428 448 1172 1803 585 771 624 668 1077 879 2819 521 1182 294 2019 380 1919 1472 510 2130 467 1299 408 1177 355 493 410 923 1255 22 36 1687 293 1729 839 562 2528 218 858 986 706 715 5 2275 264 59 167 662 885 28 1049 2199 658 1215 431 1838 567 2189 892 1423 122 1901 1696 537 13 2142 2549 1381 ...
result:
wrong answer 45th numbers differ - expected: '4', found: '5'
Test #7:
score: 0
Wrong Answer
time: 2ms
memory: 4036kb
input:
3000 3000 96 48 34 1 27 93 76 3 38 26 79 74 25 95 34 37 5 26 54 37 62 22 17 3 53 34 10 132 64 91 53 34 74 92 64 3 103 38 74 40 31 38 63 12 84 84 80 5 88 22 51 66 28 158 16 31 26 53 47 22 66 89 7 65 91 49 62 73 26 54 13 33 28 45 48 90 91 46 37 34 53 69 70 52 62 71 56 190 154 72 25 6 17 196 66 39 80 5...
output:
1485 786 356 123 300 1005 779 339 654 371 1865 531 305 1481 2300 209 1098 1062 1365 893 1232 1829 1689 63 631 182 915 1715 741 726 297 345 1631 47 63 102 1681 1263 1955 905 1339 355 178 158 120 1853 1780 1224 132 365 764 1497 1631 334 218 53 1123 1637 849 1331 464 266 923 252 916 2227 1765 223 100 1...
result:
wrong answer 1st numbers differ - expected: '1486', found: '1485'
Test #8:
score: 0
Wrong Answer
time: 2ms
memory: 4060kb
input:
3000 3000 24 75 55 19 9 74 4 22 81 77 75 46 60 50 19 50 1 41 8 63 4 47 93 24 105 16 28 76 18 96 1 68 46 80 41 83 78 36 88 45 83 54 67 46 94 99 44 61 14 50 143 97 95 78 8 92 36 59 95 26 67 23 26 95 77 92 98 13 63 149 129 61 74 39 38 55 15 90 48 3 37 39 100 77 18 10 19 10 20 77 71 46 65 84 46 7 175 81...
output:
1582 102 35 1424 1137 1138 5 162 187 1875 489 1145 1417 1522 1 1447 291 626 742 658 2321 529 506 54 339 15 974 277 1046 13 49 1097 630 339 533 2097 631 236 105 82 724 724 1226 495 1631 1416 1784 590 210 158 110 2016 679 2387 1471 1976 725 548 1512 263 63 828 749 2594 829 1255 339 1949 2114 313 2145 ...
result:
wrong answer 1st numbers differ - expected: '1585', found: '1582'
Test #9:
score: 0
Wrong Answer
time: 5ms
memory: 4208kb
input:
10000 10000 1225 3839 1022 812 2195 8154 9848 3399 6401 5375 4192 5933 7758 9460 5569 6817 1504 104 7537 509 3830 3790 686 416 5452 4214 2651 2825 5881 4373 2118 8244 8803 5866 1737 5206 3037 4862 5976 2871 9541 6867 2024 8451 7815 1083 5523 8874 1745 828 8022 5706 3404 651 4212 8126 2555 6660 5481 ...
output:
2317 3599 3097 8537 195 960 799 3058 2037 2027 1541 2196 2833 771 5561 4431 1301 2065 256 3479 6754 2225 3446 82 8993 3657 6010 6246 598 6585 3467 5990 789 2675 4614 3816 6506 5410 5631 3388 8482 3403 4104 760 3379 2558 1639 451 3111 2318 6118 1229 6212 120 325 1895 2079 761 1645 961 6467 4077 543 2...
result:
wrong answer 7th numbers differ - expected: '801', found: '799'
Test #10:
score: 0
Wrong Answer
time: 5ms
memory: 4496kb
input:
10000 10000 4293 5943 4058 5440 7413 5250 1171 9947 4399 9939 5300 6419 5446 2275 8834 6841 1566 3814 2298 5294 8131 603 2736 4135 946 7071 3233 6196 6458 5162 8229 3087 227 828 7544 3423 7594 4496 8790 4052 8704 3088 7330 7269 5010 9400 9399 3819 302 4258 2985 3323 6455 5755 7489 321 501 3299 2026 ...
output:
2271 2651 444 7139 3433 87 4845 1491 1887 8436 6860 8573 4645 792 3690 252 3903 1325 239 5380 5856 7998 869 934 3331 9302 3509 5279 2656 4558 249 3229 181 7170 7702 2816 2145 342 6986 2395 4375 5391 3237 3596 5483 4816 1364 1057 2125 2863 1455 1488 1426 2608 1074 5963 2397 3960 3396 39 208 865 2765 ...
result:
wrong answer 2nd numbers differ - expected: '2653', found: '2651'
Test #11:
score: 0
Wrong Answer
time: 5ms
memory: 4264kb
input:
10000 10000 7 178 96 109 117 3 170 302 209 84 248 310 97 70 222 255 276 127 233 219 109 282 8 182 20 128 75 158 39 214 102 260 13 80 276 221 271 319 129 110 72 89 254 45 34 322 310 299 305 32 93 224 5 261 126 140 311 81 100 72 328 312 42 16 231 146 72 238 178 178 179 226 314 152 167 202 295 258 15 2...
output:
3540 3492 6381 272 975 2120 806 3968 2807 8 253 1431 9064 2839 5790 4725 5139 4190 1822 2034 404 5450 6140 2816 4761 3126 23 2010 97 831 4165 4454 312 3874 8999 7828 2109 1768 7990 654 3282 1357 8573 1740 4749 5966 137 5245 3420 864 6263 843 1850 8029 1743 1703 1449 3922 4334 976 1342 3143 4967 4553...
result:
wrong answer 2521st numbers differ - expected: '35', found: '36'
Test #12:
score: 0
Wrong Answer
time: 5ms
memory: 4200kb
input:
10000 10000 3 31 195 326 322 174 300 177 87 56 74 14 39 240 134 249 176 187 87 118 177 304 269 44 128 328 112 121 96 93 140 163 209 271 29 296 232 309 228 183 238 100 66 118 204 90 156 45 204 126 232 68 318 327 5 3 153 331 180 62 308 172 175 142 88 318 236 75 276 251 67 218 28 118 141 257 65 151 183...
output:
1097 1587 3515 1031 6208 8323 2862 5735 1103 2344 644 2487 470 1126 3820 6090 622 2978 3756 391 3684 3749 4705 6416 4527 8133 6120 421 1500 1256 1165 5093 397 4420 1598 6343 4459 3981 4623 5327 3845 1100 184 4345 9155 1902 9176 209 514 2410 2286 9315 2468 3202 1898 2259 5595 1251 1524 556 7397 2502 ...
result:
wrong answer 2nd numbers differ - expected: '1588', found: '1587'
Test #13:
score: 0
Wrong Answer
time: 97ms
memory: 15716kb
input:
200000 200000 120536 165588 195015 67563 60504 93355 188680 98879 30412 35909 162690 193085 79065 58869 51576 146413 166618 182838 56146 110147 142857 111033 186246 180779 63081 24777 52683 191278 98735 11504 115999 116939 157422 109468 175004 10755 112531 71163 35398 71262 141229 231 123311 168965 ...
output:
75089 92570 57628 28640 48922 56558 82968 66695 28322 166430 482 38952 118470 122071 50229 3057 79231 79201 13575 72987 45707 144206 30494 58345 162783 75575 74032 10826 4344 9720 140844 20904 52952 88400 63115 19344 118669 165375 112253 89817 57444 88386 122826 55230 102432 128215 134656 2813 13353...
result:
wrong answer 4th numbers differ - expected: '28642', found: '28640'
Test #14:
score: 0
Wrong Answer
time: 95ms
memory: 15792kb
input:
200000 200000 5203 2776 2051 83 5255 4479 6328 3395 5764 3079 4020 4235 31 62 2282 1983 4052 5141 6514 108 45 84 2874 2225 5833 2277 5069 777 3458 4312 6577 1083 18 6003 4773 1935 2908 91 843 5317 6643 103 5581 113 6234 3738 144 3953 1234 396 4543 3518 5508 1833 1674 1446 1134 6455 4343 558 658 3664...
output:
68599 42023 31649 94132 14382 59438 125005 172541 42659 96595 17561 140904 1162 174118 6118 9900 118431 85273 52893 20162 20154 9455 113418 187700 23798 82046 38165 84958 116343 22779 56590 55144 59223 34396 101151 44233 49106 34700 18446 3679 47377 13861 126002 60031 56194 7170 117299 132375 53669 ...
result:
wrong answer 7029th numbers differ - expected: '8', found: '9'
Test #15:
score: 0
Wrong Answer
time: 104ms
memory: 15852kb
input:
200000 200000 5102 3159 748 5427 621 5896 499 5528 1847 6008 961 3084 1541 3370 3477 6551 3122 34 60 5045 1000 2091 119 35 345 92 47 6200 2305 611 27 20 4462 37 1192 108 5020 6490 5834 2997 6615 4662 102 4466 3073 634 2393 278 6122 6451 4679 4161 2316 2074 4859 782 3340 3997 6350 6659 4747 2199 5225...
output:
40298 785 17317 4347 89982 20182 75792 134659 58692 21702 83921 48401 54815 119876 40560 150258 124750 14795 160809 97958 47897 107999 71587 16826 48008 10218 57944 179400 11860 2878 44399 49565 62159 25921 101990 535 23716 7907 13857 66715 69134 130911 4084 25238 7969 57623 145624 93857 82020 24653...
result:
wrong answer 461st numbers differ - expected: '12', found: '13'
Test #16:
score: 0
Wrong Answer
time: 86ms
memory: 15784kb
input:
200000 200000 5620 4596 1787 1569 11 3679 57 5561 1635 5384 5280 71 127 4084 4074 4 3533 4939 5115 96 336 75 3997 951 133 6410 4574 3466 3102 534 6321 107 2300 2531 5426 73 20 12 101 607 10 4424 5847 134 6212 862 855 5070 77 91 2010 4014 4678 4050 3695 3451 2790 4235 2235 5998 6354 5149 4794 4789 40...
output:
10109 12790 38728 16167 198015 30967 25813 58758 27224 68596 7175 19905 76354 116026 80143 179181 101778 7812 7871 5176 87627 100474 59650 68160 157974 33925 27889 170213 35514 27224 51567 72318 61590 23413 94032 95342 53043 39928 164681 5884 52204 90662 125169 1895 74144 9313 139074 32562 51266 830...
result:
wrong answer 1st numbers differ - expected: '10114', found: '10109'
Test #17:
score: 0
Wrong Answer
time: 645ms
memory: 65868kb
input:
1000000 1000000 87382 651796 951220 648926 497665 375383 228684 303780 166986 89826 91242 258504 374341 653338 160191 648153 603954 860894 376629 474180 967487 270337 3022 832849 628198 269953 992793 314447 701562 440916 559722 134912 67124 636002 748016 771119 200861 655997 618755 558 882633 709234...
output:
401389 115091 693946 405927 741547 92627 200487 82753 151394 228002 301571 510453 34245 128598 315021 504014 716098 46104 145061 544861 118917 145562 413047 596757 100850 50894 883811 180199 311843 417215 651492 188592 70439 122245 276160 104247 150070 733185 335337 609198 51882 907242 408519 507205...
result:
wrong answer 1st numbers differ - expected: '401390', found: '401389'
Test #18:
score: 0
Wrong Answer
time: 639ms
memory: 65788kb
input:
1000000 1000000 3228 19 1838 21 15231 54 27226 18805 16744 57 25133 23568 27304 24323 9187 89 14287 13412 20542 21860 23602 65 1 32705 27 20439 19966 70 7865 13967 127 30379 34 95 12820 8224 14188 32692 93 29481 28113 14591 119 7443 2802 6678 51 6838 88 74 7855 95 775 11917 104 18776 34 22985 32134 ...
output:
601769 87975 543626 148208 122254 85818 8159 181383 13904 194236 213328 139430 173150 498620 268387 595806 407081 147639 107030 14140 345529 160967 75778 611045 108846 263607 11065 517134 545505 707798 287954 26599 639829 4459 247016 426985 139157 21858 357759 297213 695761 93733 571707 513904 14232...
result:
wrong answer 2nd numbers differ - expected: '87976', found: '87975'
Test #19:
score: 0
Wrong Answer
time: 639ms
memory: 65868kb
input:
1000000 1000000 13910 7760 24228 1793 79 14626 44 10663 25005 56 4240 15833 3609 19816 13269 28175 8807 67 1480 27123 69 12868 11829 3 18390 5510 58 28157 26708 17269 10176 14025 41 7746 12814 9220 24534 115 12446 51 6256 21293 28779 6845 31048 19928 19877 13972 13317 7203 9974 13131 133 13 5348 166...
output:
149908 626053 592279 104658 180043 665728 132510 790579 318332 111443 27228 177444 318900 202114 522918 250078 266059 306169 869695 340287 43427 690066 490517 148540 558731 328410 440519 667778 674162 327415 120946 251396 476741 316593 798068 255036 307454 809193 159186 146509 692633 450103 677092 2...
result:
wrong answer 1st numbers differ - expected: '149909', found: '149908'
Test #20:
score: 0
Wrong Answer
time: 589ms
memory: 65840kb
input:
1000000 1000000 15899 2139 32955 19636 21943 29782 28207 9095 20266 68 15471 14533 17782 21804 31540 21751 19168 15466 19302 34 24617 3544 66 31466 31516 3341 30147 6947 26716 135 11544 50 30167 5 11 7820 149 5146 32617 20175 23019 23260 8830 16538 88 2357 22200 21845 2144 12436 104 31 24930 10455 1...
output:
127366 622409 88970 350108 62061 220820 468815 369350 696629 227040 194499 770550 698557 327855 58033 172055 19266 81501 11204 448625 621732 574033 298976 855979 21123 532370 932561 240266 256807 655255 96670 280067 640370 191913 328371 350249 422639 246030 781629 152850 111850 532533 705773 191469 ...
result:
wrong answer 1st numbers differ - expected: '127368', found: '127366'