QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#278518 | #7771. 不是这一道据数构结题 | zhouhuanyi | 40 | 394ms | 121140kb | C++20 | 2.0kb | 2023-12-07 16:52:07 | 2023-12-07 16:52:07 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#define N 1000000
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
struct reads
{
int num,data;
};
struct rds
{
int l,r;
};
vector<reads>p[N+1];
vector<int>v[N+1];
vector<rds>st[N+1];
int n,q,c[N+1],c2[N+1],a[N+1],nt[N+1],dque[N+1],top,ans[N+1];
long long c3[N+1];
int lowbit(int x)
{
return x&(-x);
}
void add(int x,int d)
{
for (;x<=n;x+=lowbit(x)) c[x]+=d;
return;
}
int query(int x)
{
int res=0;
for (;x>=1;x-=lowbit(x)) res+=c[x];
return res;
}
void add2(int x,int d)
{
int d2=x*d;
for (;x<=n;x+=lowbit(x)) c2[x]+=d,c3[x]+=d2;
return;
}
long long query2(int x)
{
int d=x+1;
long long res=0;
for (;x>=1;x-=lowbit(x)) res+=1ll*c2[x]*d-c3[x];
return res;
}
void adder(int l,int r,int d)
{
add2(l,d),add2(r+1,-d);
return;
}
int get(int x,int d)
{
if (x==n+1) return n+1;
for (int i=x+1;i<=n;++i)
if (a[i]>d)
return i;
return n+1;
}
int main()
{
int l,r,d;
n=read(),q=read();
for (int i=1;i<=n;++i) a[i]=read();
for (int i=1;i<=q;++i) l=read(),r=read(),p[l].push_back((reads){i,r});
dque[top=0]=n+1;
for (int i=n;i>=1;--i)
{
while (top&&a[dque[top]]>a[i])
{
for (int j=0;j<v[top].size();++j) add(v[top][j],-1);
for (int j=0;j<st[top].size();++j) adder(st[top][j].l,st[top][j].r,-1);
top--;
}
if (top&&a[dque[top]]==a[i])
{
d=dque[top],dque[top]=i,v[top].push_back(get(v[top].back(),a[i])),add(v[top].back(),1);
if (i+1<=d-1) adder(i+1,d-1,1),st[top].push_back((rds){i+1,dque[top-1]-1});
}
else
{
dque[++top]=i,v[top]={get(dque[top-1]-1,a[i])},add(v[top].back(),1),st[top].clear();
if (i+1<=dque[top-1]-1) adder(i+1,dque[top-1]-1,1),st[top].push_back((rds){i+1,dque[top-1]-1});
}
for (int j=0;j<p[i].size();++j) ans[p[i][j].num]=query(p[i][j].data)+query2(p[i][j].data);
}
for (int i=1;i<=q;++i) printf("%d\n",ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 4ms
memory: 86308kb
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:
65 91 17 7 11 1 56 21 0 11 48 8 3 13 6 37 11 86 2 53 36 0 45 66 44 21 3 30 41 23 51 53 32 17 34 38 36 8 55 39 15 2 10 3 41 86 46 8 1 35 17 78 14 58 19 57 45 9 67 40 16 78 47 55 12 30 80 7 4 65 37 19 4 35 30 39 42 2 7 18 14 17 39 58 63 49 33 10 8 16 23 66 50 0 41 46 1 23 6 0
result:
ok 100 numbers
Test #2:
score: 0
Wrong Answer
time: 12ms
memory: 85380kb
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:
30 23 43 24 33 23 0 16 21 32 7 31 26 6 39 24 41 25 25 45 10 2 29 11 44 18 43 47 7 51 42 24 5 24 21 3 25 42 13 17 49 26 22 43 41 5 5 44 5 27 10 11 21 24 25 12 26 45 23 13 6 36 34 2 36 26 50 43 25 17 41 16 14 22 14 4 11 1 2 30 2 13 55 34 17 8 11 12 52 10 15 25 38 33 27 37 40 19 9 47
result:
wrong answer 1st numbers differ - expected: '35', found: '30'
Test #3:
score: 5
Accepted
time: 4ms
memory: 84796kb
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 732 2043 477 334 983 889 2090 5 1260 983 615 1049 1375 1505 1820 1158 1168 599 657 295 23 170 2604 1663 1979 1664 1040 1133 156 48...
result:
ok 3000 numbers
Test #4:
score: 5
Accepted
time: 7ms
memory: 85432kb
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:
1079 884 1832 57 331 105 2422 580 1210 1590 478 1119 2742 1547 1248 58 1400 1046 827 270 459 866 250 1301 1822 280 223 1048 2447 1175 2463 422 803 78 367 846 874 1006 422 991 723 449 343 2532 382 1163 2692 256 25 213 1699 805 43 1079 336 2 3 117 1651 1874 690 741 71 407 2427 784 469 1290 2059 754 10...
result:
ok 3000 numbers
Test #5:
score: 5
Accepted
time: 7ms
memory: 85456kb
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:
708 479 1013 1843 195 1485 1284 2305 87 1741 2238 306 258 854 1435 2489 1697 871 1639 336 1071 734 374 27 859 1513 1477 236 372 1481 92 779 176 168 959 1533 814 1219 139 1470 574 551 448 109 27 2111 1461 1259 1270 263 10 225 584 1440 1797 1898 177 958 1421 1301 573 507 1610 985 439 1571 651 2452 117...
result:
ok 3000 numbers
Test #6:
score: 0
Wrong Answer
time: 9ms
memory: 86424kb
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:
187 355 44 140 610 -500 145 405 298 224 527 179 -100 324 182 234 -684 286 -407 -224 200 -323 163 168 220 118 204 217 338 -521 124 22 36 216 188 -554 -522 -89 -262 212 80 346 24 -135 4 -469 9 59 146 218 310 10 106 -380 151 -424 245 344 155 -549 325 228 110 -440 -643 -111 13 -405 -362 213 31 -11 -705 ...
result:
wrong answer 1st numbers differ - expected: '467', found: '187'
Test #7:
score: 0
Wrong Answer
time: 11ms
memory: 86528kb
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:
320 505 283 105 74 678 -7 242 -692 288 27 -804 264 518 -708 159 87 720 277 604 -816 312 -226 62 473 135 623 -587 546 327 213 101 -663 48 58 104 299 352 -932 94 -517 287 177 74 -6 273 -518 295 111 300 -1063 70 -624 259 109 58 229 -643 563 -809 380 203 -299 161 -1142 -394 -9 15 102 115 67 297 -1014 10...
result:
wrong answer 1st numbers differ - expected: '1486', found: '320'
Test #8:
score: 0
Wrong Answer
time: 8ms
memory: 85404kb
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:
289 99 35 605 543 577 7 149 141 395 49 235 248 424 1 307 185 399 -17 176 446 145 369 54 232 18 555 165 212 13 48 286 365 195 109 564 254 116 72 53 -33 237 305 95 710 267 430 345 95 92 69 323 261 772 183 472 510 113 190 164 66 23 100 610 71 539 218 244 336 239 513 227 85 271 728 565 103 376 31 572 11...
result:
wrong answer 1st numbers differ - expected: '1585', found: '289'
Test #9:
score: 5
Accepted
time: 7ms
memory: 85384kb
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 801 3058 2037 2027 1541 2197 2833 771 5561 4431 1301 2065 256 3479 6754 2226 3446 82 8993 3657 6011 6246 598 6585 3467 5990 790 2676 4614 3817 6507 5410 5632 3388 8482 3403 4104 760 3379 2558 1639 451 3111 2318 6118 1229 6212 120 325 1895 2079 761 1645 961 6468 4078 543 2...
result:
ok 10000 numbers
Test #10:
score: 5
Accepted
time: 8ms
memory: 86172kb
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 2653 444 7140 3433 89 4845 1492 1887 8437 6861 8573 4645 793 3692 252 3903 1326 240 5380 5856 7998 869 935 3332 9302 3509 5279 2656 4559 249 3229 182 7170 7702 2816 2146 343 6988 2396 4375 5391 3239 3598 5485 4816 1364 1058 2125 2865 1456 1488 1427 2608 1075 5964 2398 3960 3400 39 210 866 2766 ...
result:
ok 10000 numbers
Test #11:
score: 0
Wrong Answer
time: 8ms
memory: 86432kb
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:
838 835 -995 154 610 1054 476 761 -676 8 251 604 -38 434 -622 -1080 1111 -1949 578 794 360 187 -164 -1517 -1709 790 23 -1193 97 626 -225 792 306 979 199 1 -331 1255 -39 434 -27 497 291 798 -1733 -1162 135 1127 -2202 391 -945 694 -329 -536 1069 631 838 -2055 26 451 -685 -1147 -694 572 662 -345 -1187 ...
result:
wrong answer 1st numbers differ - expected: '3540', found: '838'
Test #12:
score: 0
Wrong Answer
time: 20ms
memory: 85012kb
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:
879 979 -3179 632 -4080 -3980 738 -4441 802 1352 587 -968 315 766 -5834 -4304 458 -2496 1349 389 -5814 315 -5092 -964 -4995 -4044 -4445 389 294 894 740 1908 370 -5124 276 -4353 -5087 451 -2379 -5716 -2091 809 157 -5393 -4466 -191 -4332 209 514 -2836 -2913 -4276 628 2065 797 1340 -4527 688 -1878 449 ...
result:
wrong answer 1st numbers differ - expected: '1097', found: '879'
Test #13:
score: 5
Accepted
time: 76ms
memory: 94872kb
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 28642 48923 56560 82969 66696 28323 166431 482 38952 118470 122072 50229 3057 79231 79203 13575 72987 45708 144206 30494 58345 162785 75575 74034 10826 4345 9720 140844 20906 52954 88401 63116 19344 118670 165376 112254 89817 57446 88388 122827 55232 102433 128215 134657 2814 13354...
result:
ok 200000 numbers
Test #14:
score: 0
Wrong Answer
time: 71ms
memory: 96352kb
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:
-34115 21660 22923 9544 8810 -18629 -24839 -10890 26835 -37841 6587 -28608 1143 -10482 5867 8737 -30184 27245 29829 12530 14036 7250 -30220 -10383 17023 29916 1667 11135 -42683 10330 -39451 32534 -4180 8747 -31106 18912 16672 15950 6490 2082 -5855 10456 -10111 34574 21858 7165 -41003 -21524 30605 42...
result:
wrong answer 1st numbers differ - expected: '68599', found: '-34115'
Test #15:
score: 0
Wrong Answer
time: 72ms
memory: 92948kb
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:
22536 785 16012 4218 8107 10076 -1905 18378 6381 17581 40218 19686 -10455 19834 -15633 37559 23168 11853 -7983 -3073 22475 12250 -1591 12853 22278 10073 -10359 5750 3123 2866 21927 13877 28645 14365 -29278 535 15709 6209 6497 32776 33204 -14540 4083 22526 7026 31366 -6848 16517 5037 23851 9392 17917...
result:
wrong answer 1st numbers differ - expected: '40298', found: '22536'
Test #16:
score: 0
Wrong Answer
time: 79ms
memory: 94736kb
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:
8453 12283 34491 14965 87899 11896 20902 33536 25261 26558 4175 10043 32460 69532 59024 84849 61268 5486 7866 1702 57414 57309 51454 26018 87557 4942 22955 79808 17860 22012 44633 53114 18241 7653 70279 43206 43643 17832 93683 3450 34399 42707 72803 1474 27742 6732 78504 29568 35973 44724 4 24350 87...
result:
wrong answer 1st numbers differ - expected: '10114', found: '8453'
Test #17:
score: 5
Accepted
time: 381ms
memory: 121068kb
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:
401390 115094 693946 405930 741547 92628 200488 82755 151394 228002 301572 510455 34245 128599 315022 504014 716098 46104 145061 544861 118917 145564 413047 596758 100851 50894 883811 180199 311843 417215 651492 188593 70440 122245 276161 104247 150070 733186 335338 609200 51884 907243 408520 507205...
result:
ok 1000000 numbers
Test #18:
score: 0
Wrong Answer
time: 394ms
memory: 121140kb
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:
-57978 49000 -29105 41117 95754 75582 7506 113245 13877 -6983 11839 63848 128502 -72792 -8061 -220372 -10210 100294 99158 12469 -8174 65323 55421 -54716 80636 152287 9449 1119 -31188 -145936 -57103 21085 12148 3413 174509 -130403 53584 20980 -25835 -59906 -150860 20272 65710 -139313 105297 -150419 -...
result:
wrong answer 1st numbers differ - expected: '601769', found: '-57978'
Test #19:
score: 0
Wrong Answer
time: 390ms
memory: 119000kb
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:
35199 50020 -73377 59206 25027 -29522 76083 25750 -49627 -53110 23297 115827 97511 148158 -50979 99037 59697 -110660 88308 87135 39786 -58871 177200 6173 -68977 90456 176548 312599 -20686 -125658 -2233 109044 -49368 127013 23205 178160 74921 100302 108835 82657 314355 177061 -55510 46965 228104 3345...
result:
wrong answer 1st numbers differ - expected: '149909', found: '35199'
Test #20:
score: 0
Wrong Answer
time: 376ms
memory: 119152kb
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:
86285 283671 76076 192406 26523 161088 202667 185131 299633 92094 107400 385445 337994 137699 42927 87302 19060 70019 10720 188792 267624 234825 100229 338283 21102 213980 387485 145508 83589 264722 56510 165473 292673 152981 106892 138267 103673 149692 261121 91694 41167 220829 349825 132296 90822 ...
result:
wrong answer 1st numbers differ - expected: '127368', found: '86285'