QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#642874 | #5165. 比赛 | KiharaTouma | 100 ✓ | 1894ms | 149620kb | C++14 | 4.2kb | 2024-10-15 16:47:15 | 2024-10-15 16:47:16 |
Judging History
answer
//qoj5165
#include <bits/stdc++.h>
using namespace std;
const int N = 2.5e5 + 10;
int T, n, Q, sa[N], sb[N];
typedef unsigned long long ll;
ll a[N], b[N], ans[N];
vector<pair<int, int> > q[N];
struct mat{
ll a[5][5];
mat operator * (const mat &b) const {
mat c;
for(int i = 0; i < 5; ++ i){
for(int j = 0; j < 5; ++ j){
c.a[i][j] = a[i][0] * b.a[0][j]
+ a[i][1] * b.a[1][j]
+ a[i][2] * b.a[2][j]
+ a[i][3] * b.a[3][j]
+ a[i][4] * b.a[4][j];
}
}
return c;
}
} ini;
mat ma(ll x){
mat k = ini;
k.a[1][2] = k.a[4][0] = x;
return k;
}
mat mb(ll x){
mat k = ini;
k.a[0][2] = k.a[4][1] = x;
return k;
}
mat lsh(){
mat k = ini;
k.a[2][3] = 1;
return k;
}
struct node{
ll x, y, xy, all, cnt;
bool flg;
mat tag;
void mdf(mat val){
ll tx = x, ty = y, txy = xy, tall = all;
x += cnt * val.a[4][0];
y += cnt * val.a[4][1];
xy = tx * val.a[0][2] + ty * val.a[1][2] + txy + cnt * val.a[4][2];
all = tx * val.a[0][3] + ty * val.a[1][3] + txy * val.a[2][3] + tall + cnt * val.a[4][3];
}
} t[N*4];
void psd(int p){
if(!t[p].flg){
return;
}
t[p].flg = 0;
t[p<<1].mdf(t[p].tag);
t[p<<1|1].mdf(t[p].tag);
t[p<<1].tag = t[p<<1].tag * t[p].tag;
t[p<<1|1].tag = t[p<<1|1].tag * t[p].tag;
t[p<<1].flg = t[p<<1|1].flg = 1;
for(int i = 0; i < 5; ++ i){
for(int j = 0; j < 5; ++ j){
t[p].tag.a[i][j] = (i == j);
}
}
}
void upd(int p){
t[p].x = t[p<<1].x + t[p<<1|1].x;
t[p].y = t[p<<1].y + t[p<<1|1].y;
t[p].xy = t[p<<1].xy + t[p<<1|1].xy;
t[p].all = t[p<<1].all + t[p<<1|1].all;
t[p].cnt = t[p<<1].cnt + t[p<<1|1].cnt;
}
void build(int p, int l, int r){
t[p].cnt = r - l + 1;
t[p].flg = 0;
for(int i = 0; i < 5; ++ i){
for(int j = 0; j < 5; ++ j){
t[p].tag.a[i][j] = (i == j);
}
}
if(l != r){
int mid = l + r >> 1;
build(p<<1, l, mid);
build(p<<1|1, mid+1, r);
upd(p);
}
}
void add(int p, int l, int r, int ql, int qr, mat val){
if(qr < l || r < ql){
return;
} else if(ql <= l && r <= qr){
t[p].mdf(val);
t[p].tag = t[p].tag * val;
t[p].flg = 1;
} else {
int mid = l + r >> 1;
psd(p);
add(p<<1, l, mid, ql, qr, val);
add(p<<1|1, mid+1, r, ql, qr, val);
upd(p);
}
}
ll ask(int p, int l, int r, int ql, int qr){
if(qr < l || r < ql){
return 0;
} else if(ql <= l && r <= qr){
return t[p].all;
} else {
int mid = l + r >> 1;
psd(p);
return ask(p<<1, l, mid, ql, qr) + ask(p<<1|1, mid+1, r, ql, qr);
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> T >> n;
for(int i = 0; i < 5; ++ i){
for(int j = 0; j < 5; ++ j){
ini.a[i][j] = (i == j);
}
}
for(int i = 1; i <= n; ++ i){
cin >> a[i];
}
for(int i = 1; i <= n; ++ i){
cin >> b[i];
}
cin >> Q;
for(int i = 1; i <= Q; ++ i){
int l, r;
cin >> l >> r;
q[r].emplace_back(l, i);
}
build(1, 1, n);
int ta = 0, tb = 0;
for(int i = 1; i <= n; ++ i){
int la = i, lb = i;
add(1, 1, n, i, i, ma(a[i]));
while(ta && a[sa[ta]] <= a[i]){
add(1, 1, n, sa[ta], la-1, ma(a[i]-a[sa[ta]]));
la = sa[ta];
-- ta;
}
a[la] = a[i];
sa[++ta] = la;
add(1, 1, n, i, i, mb(b[i]));
while(tb && b[sb[tb]] <= b[i]){
add(1, 1, n, sb[tb], lb-1, mb(b[i]-b[sb[tb]]));
lb = sb[tb];
-- tb;
}
b[lb] = b[i];
sb[++tb] = lb;
add(1, 1, n, 1, n, lsh());
for(auto j : q[i]){
ans[j.second] = ask(1, 1, n, j.first, i);
}
}
for(int i = 1; i <= Q; ++ i){
cout << ans[i] << '\n';
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Pretests
Final Tests
Test #1:
score: 4
Accepted
time: 0ms
memory: 17980kb
input:
1 30 12 28 21 20 26 9 6 10 27 1 16 19 30 5 2 25 4 3 29 17 7 14 8 22 24 13 23 11 18 15 12 29 4 25 24 18 2 1 26 22 10 14 13 9 21 8 16 11 7 23 27 17 20 5 30 15 6 19 3 28 30 1 30 2 24 1 24 1 23 4 28 6 30 2 23 4 29 5 28 4 29 3 28 4 28 5 26 4 30 1 25 21 26 27 30 8 15 2 23 1 30 17 27 4 20 3 23 18 23 3 4 7 ...
output:
336710 184007 203523 185997 225059 225153 167351 244869 206071 244869 244156 225059 169225 266125 224763 10602 3689 18312 167351 336710 39581 92768 148849 9978 1109 6894 106319 18113 50782 47053
result:
ok 30 lines
Test #2:
score: 4
Accepted
time: 2ms
memory: 17976kb
input:
2 30 10 17 6 8 11 25 3 12 18 27 19 24 4 2 22 15 26 21 13 29 1 28 5 9 7 20 23 30 16 14 2 22 19 20 5 14 1 25 30 24 27 18 21 4 23 15 8 12 13 29 9 28 6 10 3 16 17 11 26 7 30 1 30 3 24 2 28 2 27 4 25 5 27 4 28 4 30 7 28 7 28 1 30 8 30 8 29 1 27 1 25 9 28 4 27 13 25 7 30 1 4 1 6 2 23 15 28 6 13 5 26 4 22 ...
output:
342792 179327 273851 252521 180248 197746 235091 278681 180251 180251 342792 199838 181594 271572 231039 146648 215561 58601 218441 2698 6741 177789 68964 22922 180622 131720 318248 6692 57156 148723
result:
ok 30 lines
Test #3:
score: 4
Accepted
time: 12ms
memory: 21276kb
input:
3 3000 353 828 1669 1982 2914 2076 2567 1457 1544 2684 2740 1321 2633 2048 2031 56 1523 1005 2808 1297 1259 2494 2270 1413 611 2423 1172 2329 1423 160 2510 944 1952 2500 1032 1072 2149 2883 2301 298 1783 791 1842 2505 147 2430 1098 1361 2044 118 643 2481 631 483 2477 2467 2551 1582 2330 866 835 716 ...
output:
40184823834717 26955803491255 22228935847946 25888117162514 23161821278709 22629748084474 20966308289652 30355251231971 29221320168914 28419961509740 23713745743311 21575766706848 35122192290088 32225006837037 19822682748069 34002609535683 25497598744349 25327366506625 22936542274243 32198777758697 ...
result:
ok 3000 lines
Test #4:
score: 4
Accepted
time: 12ms
memory: 19912kb
input:
4 3000 2638 2598 731 140 1171 2511 1243 2680 1519 1460 2266 2053 2218 597 390 817 2038 1356 2174 2355 2783 42 262 2608 2157 19 703 631 1860 2840 573 1376 213 1058 1783 1188 1901 1785 1734 2141 2556 2376 906 1327 1464 2405 1339 2048 2005 110 1509 2551 431 2716 2652 722 502 1477 686 2319 891 80 1888 4...
output:
40206056459952 31102701371903 22040591903644 29242861635616 23150931329106 28470613252887 30683550840310 22462054969441 30942659939149 30565815940715 35688860808536 26119573396887 22224253959404 26093094410917 27127773484960 26463960447379 22310005535454 21359719514334 34109845370909 31436618773049 ...
result:
ok 3000 lines
Test #5:
score: 4
Accepted
time: 12ms
memory: 21456kb
input:
5 3000 2249 537 2892 2283 2306 2418 31 1660 766 2489 2604 705 274 2387 179 2884 2367 1218 194 2341 1800 2722 2055 1390 2383 691 2560 2590 1612 2061 1830 2375 554 1301 401 450 733 2116 1210 2649 84 1657 1302 2028 1200 1347 793 929 2834 1600 1512 1102 490 649 1329 2403 1246 2312 1363 1736 2045 299 249...
output:
40215407189923 28473212930514 30689293264758 22464103417527 30946745354068 30573551559436 35696532341486 26123406341435 22222979171353 26100348250511 27135756380679 26469471376536 22316238161527 21363388695037 34117103848766 31442873240128 26775958078231 20402778389177 20064003507977 23564507607300 ...
result:
ok 3000 lines
Test #6:
score: 4
Accepted
time: 363ms
memory: 79448kb
input:
6 100000 75396 38259 70632 44693 79241 97717 47646 85325 83810 92620 10842 2833 69920 53424 11573 42594 83445 5481 16123 10436 81601 67126 21529 83632 91675 53146 93935 75478 26177 10079 61996 62220 65571 17854 62571 44120 12071 28594 9282 43761 93433 50961 16593 95861 25192 62665 20974 92691 27730 ...
output:
13088889182779035269 6534221255345174303 1359726823929544631 2164887475632371239 318477223968383210
result:
ok 5 lines
Test #7:
score: 4
Accepted
time: 348ms
memory: 79568kb
input:
7 100000 63014 56265 32171 20204 73218 62 14769 68831 53214 29740 74162 95845 11373 74008 25172 29026 20301 54740 30487 83999 11075 78571 60955 20839 65241 12436 47345 41877 82265 71138 76247 70103 58369 34126 19769 85143 52047 81783 28431 69356 73486 7452 86080 81571 65219 5041 92975 32553 66188 85...
output:
13087680263309436773 12208176281181665354 5349200018910054316 8044281256248766983 20326974567770060
result:
ok 5 lines
Test #8:
score: 4
Accepted
time: 947ms
memory: 144948kb
input:
8 250000 102524 204126 191550 136652 234896 111850 90965 123593 106274 56675 82246 19895 57397 55004 46130 155550 39785 60103 122552 214968 216455 48719 166072 172777 104767 92024 32452 230050 103268 158821 178060 45135 204816 161747 91265 241770 97501 21273 203007 171576 242557 36395 161246 236301 ...
output:
15916192476525971552 2162818724032435710 6465963313729027597 17463824369159434524 10911204528903543039
result:
ok 5 lines
Test #9:
score: 4
Accepted
time: 940ms
memory: 142848kb
input:
9 250000 200098 97174 28170 173369 98549 34871 116482 220351 141539 159688 93550 139417 45870 191337 186976 147334 195549 152697 174924 168723 223082 182413 225141 21840 44011 60626 230775 79423 153938 5518 29510 41843 2318 10396 122588 34595 66572 245685 47998 67755 240326 101564 5965 202014 26201 ...
output:
15912983582252787007 10410234923824936691 13973178605249614163 2120633925405422633 13426410780788018570
result:
ok 5 lines
Test #10:
score: 4
Accepted
time: 386ms
memory: 82188kb
input:
10 100000 99999 99997 38376 6647 99995 45264 99994 60797 3686 19252 18126 99993 60719 5628 99992 32773 99990 99989 50339 47441 6259 99988 40227 39408 4332 54868 4905 99987 28891 99986 56608 3960 49232 52515 48642 99985 99983 38232 99982 42651 99981 15289 52368 47437 47335 14612 35407 7505 99980 1777...
output:
317658595255444763 18368397959953075616 280084360399151992 2583610329466235517 1533455168035
result:
ok 5 lines
Test #11:
score: 4
Accepted
time: 456ms
memory: 79972kb
input:
11 100000 100000 30591 99999 99998 99997 6657 99996 99994 99992 38864 99991 20670 99990 99988 99987 99985 39155 99983 99982 99978 99976 27117 99974 99973 99967 24075 37813 99961 39325 30605 99964 99963 99962 99965 30090 99955 5617 18135 35997 99957 99956 28441 21161 5823 99958 99951 31145 99949 9994...
output:
13780806793530050287 17797854238990890570 5199674444197409071 8457812700909895353 800980143824327
result:
ok 5 lines
Test #12:
score: 4
Accepted
time: 1060ms
memory: 144960kb
input:
12 250000 61524 87207 90471 27670 249999 16574 249998 146951 37265 36283 109285 23307 82928 249997 91608 78510 37152 149901 84119 96035 249994 249993 153324 36882 77439 113753 148205 249992 167295 124778 249990 169147 111261 126598 69467 249983 249989 30595 56533 58700 84977 249987 249984 32849 8844...
output:
13401429665741651757 5445801491807823146 65952966932255245 10273614241771999601 15233330626915511798
result:
ok 5 lines
Test #13:
score: 4
Accepted
time: 1199ms
memory: 143084kb
input:
13 250000 249999 249991 20376 249967 249987 249984 91555 249980 119971 249975 4184 82372 249974 249972 249968 121786 112458 62201 249988 249962 249961 113867 107713 120838 64384 22539 249959 114100 249957 55583 86376 120039 249955 249952 15133 249936 249934 249928 14071 86733 249926 31954 249917 965...
output:
13023542996513313546 5514856497234306324 6135776573383867168 15025991517681955636 11156803493337155655
result:
ok 5 lines
Test #14:
score: 4
Accepted
time: 583ms
memory: 83932kb
input:
14 100000 3597 5516 55551 37736 24211 37914 21390 22526 46215 55934 32264 65310 42575 65276 24672 44887 19860 76191 20150 16092 13668 67517 49084 56403 12945 40511 43649 54874 58111 16947 79097 87926 41053 81714 85374 26502 49945 78788 4803 80183 46427 2335 68454 58827 34567 84916 54004 32408 38036 ...
output:
13088540581574624766 629284173226669726 468997573440049364 15354396477365723427 11288498399364179889 17327189088647249103 12769418610977411556 4638657286546655948 12658845491222164310 17426075592880655679 8948083376677040380 9972228259175586377 10791888668281039517 13868367556255097777 1591944218451...
result:
ok 100000 lines
Test #15:
score: 4
Accepted
time: 584ms
memory: 84400kb
input:
15 100000 57947 32527 16708 9265 74780 96120 10235 79718 61290 9952 70460 34316 29410 32436 61691 94001 53555 61234 13140 32757 73723 32566 66354 71055 33746 66066 43476 59950 84762 44443 13470 79853 99700 10649 97877 73182 60586 86844 88176 7865 52949 56433 72723 58388 80743 52574 35199 95237 34911...
output:
13088703057356339375 9452829717979056783 10855633573936637367 15932473885595328514 15201582657253629696 13450475369980672385 8450776191038386557 8789636774986419618 8735359102250942459 10238677876572080533 10443715256660146761 16863804767088622984 15497692803706754695 8075678448199707171 15599621965...
result:
ok 100000 lines
Test #16:
score: 4
Accepted
time: 1614ms
memory: 149472kb
input:
16 250000 66306 188910 58319 44602 94461 248619 191701 9283 84850 155848 129558 21149 14162 191976 24385 92838 106196 74117 86536 186052 195455 9505 57069 111387 232179 68871 71099 83805 245081 49405 4968 22277 102051 219152 53152 71844 85630 75109 149087 85840 203663 157740 17189 224588 125747 1654...
output:
15901165996479164054 17645567968823706781 11383646607262754188 3843060804699240129 5339948415843585142 8732670064104377917 7206149073644327793 15141337111442713620 11273515289599901320 2966459017842939057 12433053853778078763 16913765521134962542 15403251547768100489 14982142361046750750 12556941713...
result:
ok 250000 lines
Test #17:
score: 4
Accepted
time: 1597ms
memory: 147400kb
input:
17 250000 214518 7109 165693 60996 99727 33543 225083 68598 41778 4151 81497 40289 177818 156013 224688 237064 79616 21242 230963 161523 96814 51020 61668 19841 180565 177619 169253 1584 71948 103452 146421 146694 19330 30181 232433 161668 135488 88316 191971 24533 230674 125996 58536 131117 222030 ...
output:
15903935775160413324 12994160406131293768 12165084526331385143 14915389009222117516 4802966625784111142 11663903321506010611 8036958267239845870 2811767071491552017 8767519343589391918 15636568170785007093 514355359526556023 6531764696108762682 16805251735351690210 5848766500400494625 46284739914423...
result:
ok 250000 lines
Test #18:
score: 4
Accepted
time: 621ms
memory: 85008kb
input:
18 100000 199 11245 59248 15250 95721 77198 12068 47226 70219 94612 40882 78125 56325 81706 99564 57757 40981 16735 6520 37254 22399 45242 56303 18639 90538 5749 67746 10561 83841 8002 97391 44193 82633 47690 22491 88835 47085 11531 52728 90114 66975 84612 90065 10969 4360 66237 89606 281 78020 6408...
output:
6815616820806551949 7205429439063432118 15642689870296207430 3245952823108576149 11065941631556876399 2607022425032372237 9730308011167063463 6298877467219356716 9683954174931502382 3759342463774861788 6523546419874379014 4389383856772441835 7668291728724766969 16584967084166502935 95695822556053940...
result:
ok 100000 lines
Test #19:
score: 4
Accepted
time: 659ms
memory: 81336kb
input:
19 100000 34498 55141 40963 75807 81840 89426 43863 32781 39782 31733 91313 97434 93531 80424 17034 16579 93540 26418 37633 70011 48786 19831 45883 38094 92295 72555 46747 21368 77539 18609 40907 88241 53467 7765 25009 41052 5111 20060 5059 51826 5359 71155 74408 47512 86754 66199 91733 11292 92220 ...
output:
2481761466351641555 986422971484149060 8658728699695364257 17851261996804073978 916152257861574538 15855025375517424187 10721715135603385812 3472831708317046634 14516646658494029447 13619176746086567018 3902068668827903455 5864881558079158416 14419266579987066772 16180430767487305565 226871722232768...
result:
ok 100000 lines
Test #20:
score: 4
Accepted
time: 1640ms
memory: 149384kb
input:
20 250000 142345 136958 147947 150195 175778 238652 55360 166158 240487 70312 222146 26065 190856 62531 107895 54077 134731 76929 247840 99416 42360 132793 110469 176374 237332 180573 34058 148110 112862 150992 68053 6351 21165 227763 100676 238525 249762 94625 9877 57640 210186 121501 233338 103138...
output:
3820862573978173915 4944664584049231566 1948923261612496834 12305998794212425421 10587441072080903488 14795184753215030538 14658239869983805154 9680187033405342348 17468915320758956101 1766055310103217277 7165546993139274351 14715678340396521834 15932377749871389945 5714735654891013046 1761587681949...
result:
ok 250000 lines
Test #21:
score: 4
Accepted
time: 1651ms
memory: 147524kb
input:
21 250000 159644 118111 87979 83677 241819 36594 90595 96968 114358 249598 220083 174210 179881 66939 78773 174346 232433 135387 133117 154375 202090 27468 211108 24017 129381 118539 138809 178525 234827 1082 189139 89875 205732 122496 60062 246324 87972 213698 81399 159352 109340 173047 119539 1451...
output:
17902996979340955854 1249335798204624021 7897571998295448347 17253834189159181673 5849414953601644821 14388170676943453701 5260200040902933447 15949149739430648537 12596139528068517872 17811305931019968485 1664299185963689712 8519162293166367046 8862258597358475018 17354376492033378310 1404822881830...
result:
ok 250000 lines
Test #22:
score: 4
Accepted
time: 668ms
memory: 84544kb
input:
22 100000 99987 99992 99993 99990 99988 99991 99986 99982 99980 22717 3929 16263 29103 99979 99978 99977 99976 10865 99974 16993 99961 32111 99960 99957 99956 99949 26884 99947 23452 99946 22242 99945 99944 24237 99943 99938 99937 9438 12536 99935 99934 99930 99926 99922 99924 33917 3063 99923 99925...
output:
12296334484533229217 13339030993315175869 13090479388088811926 10482345934402558251 14606812070592042149 1191169862805405355 247267660434405450 13064213015389476904 4417588199022775781 17508586375392596219 16108134279804317852 16572022413825000678 1183556796563209024 15852127071992314873 13167456753...
result:
ok 100000 lines
Test #23:
score: 4
Accepted
time: 651ms
memory: 84136kb
input:
23 100000 22584 33702 100000 37252 25122 17398 99998 99997 21290 99994 99990 99989 22335 22740 9312 99986 33821 99985 99984 99983 99979 99975 27331 99974 99973 13708 31617 99972 31130 13202 99971 99968 99967 3499 15101 99965 99964 99963 99962 36857 99960 37915 5196 10357 28557 14304 38089 27830 9995...
output:
15517502797221565608 12830304114960719956 4083489056006744671 6829605594922517664 15654051563504379394 4278503817148562008 7677371610297366733 14480009389326238220 5898746971631297662 4712939369321956375 16544777417349376055 17172668781345836613 16973850571062347363 2922394463132022392 1588208881951...
result:
ok 100000 lines
Test #24:
score: 4
Accepted
time: 1894ms
memory: 149620kb
input:
24 250000 25471 61705 74365 249999 38625 85441 106054 12840 24109 3680 126059 249997 249995 249990 249989 249985 126496 119298 249984 19970 249983 57482 249982 249979 249978 59295 115702 17 80704 26932 249977 127802 45793 249976 249975 59578 249974 29119 48458 249973 18429 126811 126616 41549 249972...
output:
12654552932509952002 4863971916966126082 502179853002254144 15643904512646255937 8607283891000218650 2448995531533441176 2928284788055212677 5030057499297770409 4514511350259380957 3892813970117946131 1185837678406931724 6381561426633300820 14616703955040717329 2707049799894478645 151636652432050106...
result:
ok 250000 lines
Test #25:
score: 4
Accepted
time: 1769ms
memory: 148112kb
input:
25 250000 250000 16831 249999 249998 23668 73080 81716 58206 249997 48474 249995 249993 36919 7843 249992 249989 249988 1992 50732 1225 51301 249987 249986 249983 249982 17515 249980 11033 28231 92583 249979 45096 59146 249978 249977 65779 249976 6789 249975 249974 249973 249972 19209 60855 47949 24...
output:
16413963986625749995 15458558464703591824 5971634645298588232 8050283248746177425 4492074800717107479 10987980096118508916 10070702564837035166 2865130248714107066 6403515205955362044 9170268418095653367 8803265996930822480 13257252194896333827 9645695517490179342 5031755409690677863 112907989796689...
result:
ok 250000 lines
Extra Test:
score: 0
Extra Test Passed