QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#701719 | #88. Lucky Numbers | TheZone | 100 ✓ | 64ms | 22396kb | C++20 | 6.1kb | 2024-11-02 14:36:48 | 2024-11-02 14:36:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#ifdef LOCAL
bool local = true;
#else
bool local = false;
#endif
mt19937 rnd(234);
const ll inf = 1e18;
const ll mod = 1e9 + 7;
struct SGT{
struct node{
int dp[3][2][2];
void build(int x){
for(int i = 0; i < 3; i += 1){
for(int j = 0; j < 2; j += 1){
for(int k = 0; k < 2; k += 1){
dp[i][j][k] = 0;
}
}
}
for(int c = 0; c < 10; c += 1){
int bg = 1;
int nd = 1;
if(c == 1){
nd = 0;
} else if(c == 3){
bg = 0;
}
if(c < x){
dp[0][bg][nd] += 1;
} else if(c == x){
dp[1][bg][nd] += 1;
} else {
dp[2][bg][nd] += 1;
}
}
}
};
void merge(const node &a, const node &b, node &c){
for(int i = 0; i < 3; i += 1) {
for(int j = 0; j < 2; j += 1) {
for(int k = 0; k < 2; k += 1) {
c.dp[i][j][k] = 0;
}
}
}
for(int sa = 0; sa < 3; sa += 1){
for(int bga = 0; bga < 2; bga += 1){
for(int nda = 0; nda < 2; nda += 1){
for(int sb = 0; sb < 3; sb += 1){
for(int bgb = 0; bgb < 2; bgb += 1){
for(int ndb = 0; ndb < 2; ndb += 1){
if(nda == 0 && bgb == 0){
continue;
}
int sc = sa;
if(sc == 1){
sc = sb;
}
c.dp[sc][bga][ndb] = (c.dp[sc][bga][ndb] + (ll)(a.dp[sa][bga][nda]) * b.dp[sb][bgb][ndb]) % mod;
}
}
}
}
}
}
}
int n;
vector<node> t;
void upd(int v){
merge(t[v + v], t[v + v + 1], t[v]);
}
void build(int v, int tl, int tr, vector<int> &a){
if(tl == tr){
t[v].build(a[tl]);
return;
}
int tm = (tl + tr) / 2;
build(v + v, tl, tm, a);
build(v + v + 1, tm + 1, tr, a);
upd(v);
}
void build(vector<int> &a){
n = (int)a.size();
t.resize(n * 4);
build(1, 0, n - 1, a);
}
void chng(int v, int tl, int tr, int i, int x){
if(tl == tr){
t[v].build(x);
return;
}
int tm = (tl + tr) / 2;
if(i <= tm){
chng(v + v, tl, tm, i, x);
} else{
chng(v + v + 1, tm + 1, tr, i, x);
}
upd(v);
}
void chng(int i, int x){
chng(1, 0, n - 1, i, x);
}
node get(int v, int tl, int tr, int l, int r){
if(l <= tl && tr <= r){
return t[v];
}
int tm = (tl + tr) / 2;
if(r <= tm){
return get(v + v, tl, tm, l, r);
}
if(tm + 1 <= l){
return get(v + v + 1, tm + 1, tr, l, r);
}
auto rsl = get(v + v, tl, tm, l, r);
auto rsr = get(v + v + 1, tm + 1, tr, l, r);
node rs;
merge(rsl, rsr, rs);
return rs;
}
ll get(int l, int r){
ll rs = 0;
auto x = get(1, 0, n - 1, l, r);
for(int s = 0; s < 2; s += 1){
for(int bg = 0; bg < 2; bg += 1){
for(int nd = 0; nd < 2; nd += 1){
rs = (rs + x.dp[s][bg][nd]) % mod;
}
}
}
return rs;
}
};
template<class T>
ostream& operator<<(ostream& out, vector<T> &a){
for(auto x: a){
out << x << " ";
}
return out;
}
SGT sgt;
int n, q;
vector<int> a;
int32_t main(){
if(true){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
cin >> n >> q;
a.resize(n);
for(int i = 0; i < n; i += 1){
char c;
cin >> c;
a[i] = c - '0';
}
sgt.build(a);
cout << sgt.get(0, n - 1) << "\n";
for(int itr = 0; itr < q; itr += 1){
int t;
cin >> t;
if(t == 1){
int l, r;
cin >> l >> r;
--l;
--r;
cout << sgt.get(l, r) << "\n";
} else if(t == 2){
int i, x;
cin >> i >> x;
--i;
sgt.chng(i, x);
}
}
return 0;
}
詳細信息
Subtask #1:
score: 14
Accepted
Test #1:
score: 14
Accepted
time: 0ms
memory: 3748kb
input:
4 0 1944
output:
1806
result:
ok single line: '1806'
Test #2:
score: 14
Accepted
time: 0ms
memory: 3696kb
input:
5 0 21660
output:
19947
result:
ok single line: '19947'
Test #3:
score: 14
Accepted
time: 0ms
memory: 3692kb
input:
6 0 252025
output:
231770
result:
ok single line: '231770'
Subtask #2:
score: 14
Accepted
Dependency #1:
100%
Accepted
Test #4:
score: 14
Accepted
time: 0ms
memory: 3680kb
input:
14 0 98387735275536
output:
945764145
result:
ok single line: '945764145'
Test #5:
score: 14
Accepted
time: 0ms
memory: 3696kb
input:
16 0 7968288208093277
output:
319854049
result:
ok single line: '319854049'
Test #6:
score: 14
Accepted
time: 0ms
memory: 3700kb
input:
18 0 009714495581676200
output:
129991858
result:
ok single line: '129991858'
Subtask #3:
score: 9
Accepted
Test #7:
score: 9
Accepted
time: 23ms
memory: 4704kb
input:
8000 8000 13170855683470101241434860327122855890718325609856902796503309750892031429230639788926172560588532170164256985156324809437756916754159112542449438487015430312577456934037646165804945588408165846665372851553376323395384804334277688371865438991453267472929111774071983567740759887753607132707...
output:
583307075 752108051 534138377 27235044 337520455 584659316 780416686 790077337 660834308 727322472 944048747 990120652 160575137 118825730 534780110 314195235 654312500 678921918 553457150 719307019 330934305 867776692 602189726 982548131 301436919 221932205 254541092 187946247 91909237 107541381 30...
result:
ok 8001 lines
Test #8:
score: 9
Accepted
time: 29ms
memory: 5316kb
input:
10000 10000 040974476534995350341398719846526498273289300798590022821431377188889643011452683373310706807006308041696027399510247245882534155873381626853517109928554860862623812318375550234494285850732459995141520420583461562621995442761565184120786306839458022455456185172269318398928092954398138479...
output:
347497400 821715995 14683912 92878654 276920989 557925032 763963361 426413170 647688238 451502410 400254888 469150771 946252030 990720268 406371445 281137538 658276916 733410189 764062510 959750792 313435882 909704720 319478642 986435286 120588401 624981028 388471386 664084953 566786813 770490459 78...
result:
ok 10001 lines
Subtask #4:
score: 27
Accepted
Dependency #3:
100%
Accepted
Test #9:
score: 27
Accepted
time: 52ms
memory: 18500kb
input:
80000 8000 0681264629460091197116820742373674574088350383499303115055094872647163704832904218066741697353996295204952715750393440625031762616836385783707476778156146042580804017361289570800314589876681294837751954887916508740049649661835220252905061752068305884987137954593157807385160203108532759007...
output:
6827078 923445373 686289426 119228127 219440220 284052379 914032079 61985692 419522229 42458320 263231504 425353761 243710363 324835563 673802548 959496578 556920581 713183772 873304203 622119487 643715463 619013571 938713385 243173296 350112849 835565022 595317903 121860470 994807711 440828478 2662...
result:
ok 8001 lines
Test #10:
score: 27
Accepted
time: 50ms
memory: 18500kb
input:
80000 8000 4905139061859483847170977571497690171937792072050781529721471308887269435464504759236622648285961050014900643363911561362958420476397802631967358599452317515185309731497961121254841475111352829948066358368261010116938883354970716757715697000688412157630140818065007497697145549315311479777...
output:
245989061 982757278 617268532 314305979 837260953 674234682 565098325 438735951 458312923 330786325 174739694 3690248 413944558 2583791 146928646 959037858 18093219 146117276 284523665 65053721 354065816 471818895 901477651 223513188 696403886 18457673 617690761 901642008 718425978 82022354 31453303...
result:
ok 8001 lines
Test #11:
score: 27
Accepted
time: 56ms
memory: 20264kb
input:
90000 9000 9941072729505386061428953110679907484756243227235130509127038580859624620649727286987939687639056147494195779382636131845102469961342922599742420197732423314516470252692165119423099478203910400281296678556270221624741343749365415573163595275278615289275952069328244183427661656063980205145...
output:
610003886 985384815 52448965 56646322 764678518 586427205 209506639 843862643 837131498 651162030 463746010 646262579 416243243 250182396 958610703 801695058 160160376 759977394 419222407 973273333 928825503 416273798 887102557 477632468 899202218 270743542 555148980 988744637 83768106 131352041 692...
result:
ok 9001 lines
Test #12:
score: 27
Accepted
time: 61ms
memory: 22356kb
input:
100000 10000 92872377384387479300723833607221198124648988960553275270434478042588326510609081767581953888954119311261279187673555097844589524516409277507091382833423432329596337811515117350325016406476106396270203978546434371907169386757496381109921121611682073275387287853492986069136102361695057971...
output:
609469908 457994938 462823395 337313914 730618640 650217355 714637784 863704983 504869808 769898525 164349610 619569408 705043780 616914350 833443551 770106979 65729220 103623948 310560702 762014998 207465614 375551026 696133192 472194783 91127917 50283463 790671384 717861010 932494351 812950012 789...
result:
ok 10001 lines
Test #13:
score: 27
Accepted
time: 60ms
memory: 22364kb
input:
100000 10000 24331678092862595276870292326266825079383367389312582508975128987130968248126915394446088457517720579532921422252311887146934517726997454141508026874248232695578915651410995371413823127136483241625788067510097702528219591486405483131046232338109122001149771715512552520256042102209001189...
output:
287097036 541536016 421884095 465709310 512897381 888342889 148355738 321801982 600608859 904606707 286900032 204509487 997932400 848807887 795998567 66861295 114387514 833872293 636060868 578361295 175311889 755416764 743235249 884316318 196120854 682293949 634942147 477459464 590135717 237362609 1...
result:
ok 10001 lines
Subtask #5:
score: 9
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #14:
score: 9
Accepted
time: 21ms
memory: 4752kb
input:
8000 8000 38793107152998495474971534878490565599501610995043493831309818438348936271715524992571281654755625631992972127593667954843270852152828342941298596484672763767837068924015351300032810756313426113632384879940031717867918226608737793231988023177329346844218382329901834967976684397674856665150...
output:
83632781 651660672 124772426 604264224 850363088 83728605 266452012 548375055 962035171 622809109 57734928 103567666 857612504 999335176 428955941 61840857 6608926 785724058 219791180 33952247 381637011 821992387 499562945 687367479 439539269 405892954 769977583 763563145 497550395 499873232 3655508...
result:
ok 3956 lines
Test #15:
score: 9
Accepted
time: 32ms
memory: 4924kb
input:
10000 10000 574941308909409685547833314067941904755732815941735066683546087045580299560971992239738003916336301557921603005408404175052044173075393368725547387233056737935911295209481781971167744589068048258376549272542457520814829995094184704180218954803759388200252122071790824594448798939165334914...
output:
220830615 93650473 242869258 121820546 359915425 819491158 996125868 792030458 463275101 149357361 415355943 813734449 780429723 860780836 436736171 158556847 953938224 691950128 720137503 475264861 872143296 626063249 176617225 689509005 390659043 537972726 129963878 917887602 248892469 2283392 907...
result:
ok 5081 lines
Subtask #6:
score: 27
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Test #16:
score: 27
Accepted
time: 50ms
memory: 18556kb
input:
80000 8000 9177811274051249568090869454388914416317104280488248404865830878344977478278656210841586841811316251309398452251136128869579231624799873802452183558604479277686828053003062759103122442703967273170347277792514360649143326411236571523358771504633886911175220073656987413849883505375326577273...
output:
896709687 858937597 169041875 2109562 258289173 202569461 141052213 845676153 800434686 624255959 27037576 254116643 34643531 491387619 20516353 803008702 171610417 490806260 463308242 623798039 639149232 595775802 460636524 798088934 212913849 904459458 465560197 176423289 523415828 597674165 15928...
result:
ok 4045 lines
Test #17:
score: 27
Accepted
time: 49ms
memory: 18528kb
input:
80000 8000 5611118267705042132727990053132102126456564670293828171950668718190896975341626118588314337773500360562805946461181882235534457065466921739354296444840693271445550832006322377906470381544855033300890000382256523360552020948612573663342413413194118919743945050677395580054408593563085079608...
output:
306608611 255364435 104076517 874765406 988673011 770078867 667205672 960412843 637866707 611622297 356479624 823392676 613607293 312850687 324074469 665137437 115923827 921796756 912585346 620493127 982765397 84344818 148536008 105441131 382329537 109020605 332542941 872611340 317616902 909784362 7...
result:
ok 3926 lines
Test #18:
score: 27
Accepted
time: 51ms
memory: 20520kb
input:
90000 9000 1449779929051975671970950264394815771341432708480648591126605471362196850533891185731642270463295676128609036064008608714876415398275814441537145642061101608237151623485143764249634224445002416871895754975284530672865148121542279747768421368748117278444357266923460370843920170261494277470...
output:
960427224 492356825 691857677 972890385 957945537 8717326 431866695 427049792 225302529 627751984 397354263 344540689 151050937 263409139 564585762 725205309 810141740 103468859 641407857 712702045 350651407 834397497 403235917 95948885 429934924 244074472 908066751 342565690 47811030 965324059 9217...
result:
ok 4548 lines
Test #19:
score: 27
Accepted
time: 64ms
memory: 22364kb
input:
100000 10000 63256108098936181615183976595131748596369194642517848849919177499916662635650314648295584285979245013479355143979076423073387418825405127586769779329318580110597105801789309259218710356420831254859275965186510060523134253691934353982335187714879448248160665527622216786568974630919023017...
output:
681271635 60078530 479371327 921387815 26520704 115756798 760107559 277051874 576250873 983411851 228268181 15014818 134507268 609820926 488183860 638900678 610102854 393444152 368710308 979312553 903085497 395701330 545883131 624333707 273820507 659083128 570517209 56683187 545222381 159829864 2456...
result:
ok 4943 lines
Test #20:
score: 27
Accepted
time: 63ms
memory: 22396kb
input:
100000 10000 30003805271851257196578792817149148500382661932652626285349886709440829665174984112257507402707462151487305816964234867282088884210147255573696594651679322654531454080980542512625018308184142987249757465428947183863434731700458572183043062449660449395012283273098238094043448639753423352...
output:
73406457 785801834 460282015 886793588 209473375 58213082 981800598 107359652 279438737 891729548 906902882 230216021 741230188 558713404 778173364 147093500 92899105 556746224 878839572 655304927 955468258 316212705 579452387 799112712 621886466 521592913 79266 633838238 734607512 778079244 2229244...
result:
ok 5038 lines