【二分查找 位运算】3145. 大数组元素的乘积

本文涉及知识点

二分查找算法合集
位运算、状态压缩、枚举子集汇总

LeetCode3145. 大数组元素的乘积

一个整数 x 的 强数组 指的是满足和为 x 的二的幂的最短有序数组。比方说,11 的强数组为 [1, 2, 8] 。
我们将每一个正整数 i (即1,2,3等等)的 强数组 连接得到数组 big_nums ,big_nums 开始部分为 [1, 2, 1, 2, 4, 1, 4, 2, 4, 1, 2, 4, 8, …] 。
给你一个二维整数数组 queries ,其中 queries[i] = [fromi, toi, modi] ,你需要计算 (big_nums[fromi] * big_nums[fromi + 1] * … * big_nums[toi]) % modi 。
请你返回一个整数数组 answer ,其中 answer[i] 是第 i 个查询的答案。

示例 1:

输入:queries = [[1,3,7]]

输出:[4]

解释:

只有一个查询。

big_nums[1…3] = [2,1,2] 。它们的乘积为 4 ,4 对 7 取余数得到 4 。

示例 2:

输入:queries = [[2,5,3],[7,7,4]]

输出:[2,2]

解释:

有两个查询。

第一个查询:big_nums[2…5] = [1,2,4,1] 。它们的乘积为 8 ,8 对 3 取余数得到 2 。

第二个查询:big_nums[7] = 2 ,2 对 4 取余数得到 2 。

提示:

1 <= queries.length <= 500
queries[i].length == 3
0 <= queries[i][0] <= queries[i][1] <= 1015
1 <= queries[i][2] <= 105

二分查找、位运算

令 m = max(queries[i][1])<= 1015
令f(x)是强数组,即f(1) = {1} f(2) = {2} f(3} = {1,2} 。特殊的情况f(0)为空。
fl(x)等于f(x)的长度,即数组元素的个数。
big_nums 显然就是f(1) 、f(2)、f(3) ⋯ \cdots f( ∞ \infty )的拼接。
big_nums[0…toi] 令f(1)到f(i2)的拼接,其中f(i2)可能部分元素在 big_nums[0…toi] 中,也可能全部在big_nums[0…toi] 中。
令big_nums[formi] 是f(i1)的元素。则:big_nums[formi…toi]则可以分成三部分:
一,f(i1)的后缀 二,f(i1+1) ⋯ \cdots f(i2-1) 三,f(i2)的前缀。
如果i1等于i2,直接枚举i1,就可以了。
g(x) = ∑ i : 0 x f l ( i ) \sum_{i:0}^{x}fl(i) i:0xfl(i)
has = g(i1-1)
从低位到高位枚举i1的二进制1
has ++ 如果 has > formi vCnt[bit]++
v= g2(i2-1) - g2(i1)
将v加到has中。
从低位到高位枚举i2的二进制1
has ++ 如果 has <= toi+1 vCnt[bit]++

Π i : 0 60 ( 1 < < i ) v C n t [ i ] \Pi_{i:0}^{60}(1 << i)^{vCnt[i]} Πi:060(1<<i)vCnt[i]
注意:要求mod。

x的n次方

如果 n是奇数 xn=x × \times × (x t i m e s times timesx) n/2
如果n是偶数 xn= (x t i m e s times timesx) n/2
无论那种情况 n都是/2,故复杂度是O(logn)

g2和g函数

0到x的第bit位有多少个1? 以 1 << bit 为半周期halfUnit,前半个周期是0,后半个周期是1 。最后一个周期可能不完整 max(0,(x+1)%(2*halfUnit) -haflUnit)
g函数就是g2 返回数组之和。

二分查找

auto ll1 = NBinarySearch::FindFrist(0LL, llMax, [&](long long mid) {return TotalBitCount(mid) > fromi; });auto ll2 = NBinarySearch::FindFrist(0LL, llMax, [&](long long mid) {return TotalBitCount(mid) >= toi + 1; });

二分查找+ 位运算 代码

核心代码

namespace NBinarySearch
{template<class INDEX_TYPE, class _Pr>INDEX_TYPE FindFrist(INDEX_TYPE left, INDEX_TYPE rightInclue, _Pr pr){while (rightInclue - left > 1){const auto mid = left + (rightInclue - left) / 2;if (pr(mid)){rightInclue = mid;}else{left = mid;}}return rightInclue;}template<class INDEX_TYPE, class _Pr>INDEX_TYPE FindEnd(INDEX_TYPE leftInclude, INDEX_TYPE right, _Pr pr){while (right - leftInclude > 1){const auto mid = leftInclude + (right - leftInclude) / 2;if (pr(mid)){leftInclude = mid;}else{right = mid;}}return leftInclude;}
}class C1ToXBitCount {
public:C1ToXBitCount(int iBitCount = 60):m_iBitCount(iBitCount){}long long TotalBitCount(long long x) {auto v = BitCount(x);return std::accumulate(v.begin(), v.end(), 0LL);}vector<long long> BitCount(long long x) {vector<long long> ret(m_iBitCount);auto cnt = x + 1;for (int bit = 0; bit < m_iBitCount; bit++) {long long halfUnit = (1LL << bit);const auto curBitCount = cnt / 2 / halfUnit * halfUnit + max(0LL, cnt % (2 * halfUnit) - halfUnit);ret[bit] = curBitCount;}return ret;}int  m_iBitCount = 0;
};
class Solution : public C1ToXBitCount {
public:vector<int> findProductsOfElements(vector<vector<long long>>& queries) {vector<int> vRet;for (const auto& v : queries) {vRet.emplace_back(Do(v[0], v[1], v[2]));}return vRet;}int Do(long long fromi, long long toi, int modi) {const long long llMax = 1e15;auto ll1 = NBinarySearch::FindFrist(0LL, llMax, [&](long long mid) {return TotalBitCount(mid) > fromi; });auto ll2 = NBinarySearch::FindFrist(0LL, llMax, [&](long long mid) {return TotalBitCount(mid) >= toi + 1; });long long has = TotalBitCount(ll1 - 1);vector<long long> vCnt(m_iBitCount);for (int i = 0; i < m_iBitCount; i++) {if ((1LL << i) & ll1) {has++;if ((has > fromi)&&(has <= toi + 1)) { vCnt[i]++; };}			}if (ll1+1 < ll2) {auto v1 = BitCount(ll1);auto v2 = BitCount(ll2 - 1);for (int i = 0; i < m_iBitCount; i++) {vCnt[i] += v2[i] - v1[i];has += v2[i] - v1[i];}}for (int i = 0; (i < m_iBitCount)&&(has < toi +1 ); i++) {if ((1LL << i) & ll2) {vCnt[i]++; has++;}}long long ret = 1;for (int i = 0; i < m_iBitCount; i++) {ret = ret * pow(1LL << i, vCnt[i], modi) % modi;}return ret;}int  pow(long long cur,long long n,int mod){cur %= mod;int ret = 1;while (n){if (n & 1){ret = (ret*cur)%mod;}cur = (cur * cur) % mod;n >>= 1;}return ret;}};

测试用例

template<class T>
void Assert( vector<T> v1,  vector<T> v2)
{if (v1.size() != v2.size()){assert(false);return;}for (int i = 0; i < v1.size(); i++){assert(v1[i] == v2[i]);}
}template<class T>
void Assert(const T& t1, const T& t2)
{assert(t1 == t2);
}int main()
{vector<vector<long long>> queries = { {1,3,7} };{Solution slu;queries = {{ 7,7,4}, { 2,5,3 } };auto res = slu.findProductsOfElements(queries);Assert({ 2,2 }, res);}{Solution slu;queries = { {1,3,7} };auto res = slu.findProductsOfElements(queries);Assert({ 4 }, res);}{Solution slu;queries = { {169879810433127,550761388797555,99654},{686430206490542,811526032631952,42165},{692660576128036,948612666549598,6133},{26737971469338,666047313558003,47418},{702069714047969,722859311394739,23778},{170454620243294,337251866693689,34867},{305734079281920,324817853585667,58089},{46541944951724,865072982439244,8679},{684974369233663,906035997959252,76558},{54080337594455,434490824054586,16831},{597229285596974,659743613415763,65326},{226262698769597,307549095866773,99069},{220710914421489,691249094235569,4606},{211841115117980,590627441797697,10759},{313803718067076,938374854970880,98435},{278632107783837,969472753253940,59589},{126240528937192,767131030750298,51230},{568136189941940,864908502392279,77320},{408030802722074,450791504535906,97230},{912658919991971,987571709654291,67639},{348587565236231,470157946939825,10536},{480847828216116,883348967709687,52714},{66654096941850,773046970395140,66182},{262409721196468,283114507800109,5651},{332217337159867,399174306599015,94366},{308810633057721,902765491828908,88988},{494113020581729,604103736565843,60562},{37643130072432,136766380923656,51253},{922833714934653,989827516323421,20554},{746310872599863,916979242488308,57917},{134187838000278,383291149065272,54910},{695088635463290,966311269169523,28303},{107637667344049,939739733559622,98864},{45615627893824,620590849240789,55210},{96470930774481,950591166253836,64171},{344201066550140,375653586124517,59199},{350705174349951,713889258226369,98726},{220939451500946,442203792978359,96500},{605641768732975,683789319835603,69850},{398641676093294,795286733748412,3160},{268091229082870,673372967979654,80017},{879092781541449,984050531820364,73782},{124244327576881,751693320748727,12774},{135501666962027,428380765238956,3264},{311963279697981,809487239213212,67778},{336663486456888,780142182833960,19800},{284803070755828,374071712600370,57870},{114021529057229,130368432740862,80944},{794750249210086,842646645705749,8516},{785133420600219,851060391170786,79794},{279286307655226,337935382214016,89399},{275519280685880,366909585151808,25943},{388743754001988,940073334938768,35820},{477172627053941,538325632274392,2197},{23890558331476,989101914029894,26111},{307559677935642,827178917523968,53898},{518385789289429,827319678217963,71852},{733902682019658,797312507565766,38117},{478104200404529,664563201558809,28550},{13546621908435,30315331134084,42015},{100534964679993,934285422318778,50725},{762659058527522,891018704291773,56383},{303217091936734,605733160837591,84726},{440341510928062,767591625009031,36592},{725497143437471,865480838070159,72993},{278380608782350,937778454702653,38077},{145593943033503,724957742382445,66580},{565413866948742,581900150951605,11100},{198670401062530,350346679664698,7048},{584228984882461,745952107636833,5404},{220164602842346,539867204903599,11155},{78037803442736,666003811820915,14619},{96218980717634,340309527372502,46053},{790243678108771,797984748258355,76048},{183777354154631,849179656012830,36328},{170563825236004,973908679478443,74487},{524612934832724,760670576423803,83249},{249650691200852,890515711573665,36671},{148241532241974,849065739496506,16214},{86743511521795,705590839745977,22943},{184765001629768,394083568444198,3069},{18608468813205,714901119217709,1312},{69847164357545,549986054668059,75446},{777026828727024,929870156103628,82450},{106530121582665,572669767049386,62029},{770439193417336,982913838454573,21767},{269286607731063,945170558465798,83513},{87212495848914,549885883444719,15218},{499046515618578,512049445965769,85429},{221988549169046,989748737625449,45916},{311132871687036,930417357267884,70669},{280109230465362,338748618671269,57829},{79680069477967,831708854208332,79575},{474006030850009,804939695838265,57659},{402759292307455,896183306762154,6744},{615548023201624,826782457183497,15991},{10045993020252,105528891424682,56933},{66012355823282,335481063198861,47760},{338574215791837,662982158628165,13150},{526116910465538,824468790859152,69990},{626973870310328,897965950356006,5606},{638304129981624,973659274380061,89108},{53925052375364,518673397700445,88042},{105433947614916,561317982757430,3882},{606154844241389,949595587309455,2066},{206055897763694,861386710948952,59614},{372205322894116,711319516754311,27670},{1350869976559,281481877177474,75679},{439667752821956,873040630260396,25077},{177607826775636,519757604019219,89366},{140989726865581,193423186784730,92786},{294664216215784,774667650553164,81087},{99058221211883,154275604832129,62089},{843266541340090,854817726005552,63737},{70656695563443,84316580143538,34158},{209030242644215,364748419410813,40354},{152671856303228,986786535142694,46822},{667596073471528,927271738323382,80033},{779993698702576,979789790375746,45008},{424666323121782,463145381122856,24429},{149698167966580,435590413708761,44462},{692075493320596,929319925137949,81946},{317867607584134,637826749304663,26068},{319006197361561,401246540391921,19167},{51651777707375,605846057551854,26337},{638991445062931,689718719458258,23564},{823586011186540,947256788278129,42352},{427765785917033,755431182044512,69004},{68157820875530,86122235661641,65460},{45150380376171,229797112625778,62175},{113575903816524,927565447906985,38156},{32666417273654,507848687902017,63119},{194460606840265,361707386085673,46879},{756326228312467,773865545508146,32957},{161265061497137,379704340563169,53998},{385529353477193,928881468297762,48491},{505644880476173,636403213827194,63003},{182913424900786,934787907512504,31323},{81297719800444,454701936724266,76871},{358439621843515,358908001944514,145},{299004604184363,544365302481344,66938},{382000926753887,575795570524572,24166},{697948092970866,897879178481972,90750},{496950578440098,590835906119535,15041},{14654415620022,183060139738772,53095},{626514345819902,799628494153827,7037},{169444849579571,985523404733288,98355},{73810569320998,284437669738099,54002},{433037103123273,864020069385119,63263},{777314770042566,825018625174414,73534},{590225690468350,968446371394337,4208},{540993580956872,920322432848060,83141},{148451142299215,447946215869282,8225},{12411950854222,202162213844830,46611},{311281990397318,623298865334273,53601},{195621687103996,436985351480676,45023},{338919585913808,794376847691200,93570},{400567522312370,501716346870319,89463},{185384813863165,432941813215534,4035},{546980178418435,749701211921384,63406},{105631342217088,323180242946265,11684},{232995683231486,961845249435830,77465},{594215554899896,966057748419453,31193},{249821814734628,726732791146041,58329},{141314334778648,239427002389772,1093},{152370097810979,821639191166531,47392},{32618411121216,707230515129832,82015},{192156220813870,631790652398535,77239},{7484737376901,69693793194551,12522},{62634049524058,370290322377400,91846},{220801287355973,657466281394741,52936},{56691873407604,724057986444041,67496},{478053228144307,755708540739650,23007},{10523037225021,339573687228888,52483},{77190995178283,373986628979691,39859},{555149755510336,567010244509406,95593},{280556834576141,713048041557728,22416},{184033412716887,508531929088144,62310},{60383028552629,575830137264173,39654},{242972972957629,325484627915151,93078},{298404842020694,330327027023552,41472},{777755079967664,781438980320194,71228},{61777510600635,677091374264686,58804},{342079555975149,383954996543859,19003},{139990760554065,902439418766639,89689},{154035757480931,741285805025997,14635},{574507447518172,860082343483385,40232},{46763819317110,613121805003433,24981},{133169794521957,626986766783240,29509},{153578580947152,876423013398679,47340},{118198890962138,990177483884735,68728},{454367615194851,671920319481192,86099},{344311894728280,807804643010575,18189},{143718292681025,700513898453493,30850},{276111708155921,565548925564050,71836},{941406998503339,998009526296985,54920},{647838278738544,714641022733781,55308},{799023184668010,917593796718606,93083},{193932701161617,450857178933091,24040},{378287075556724,725285523646341,24726},{105083862289805,501562986065548,6993},{197161404799746,604142137643008,11144},{83891984396472,468500105623774,90200},{554824353876895,681216071630503,44250},{399786499307747,876071161607114,62486},{114790331451705,287142819274461,16116},{613641435046418,697402547480892,91222},{308542138743989,713994734133365,76003},{365748962434917,539067486098593,67266},{56538169248700,174875245396919,7811},{274536463375690,968436777986722,95879},{434374365651533,528169998981158,58400},{450863594550544,553804849101630,32773},{286106250732793,708851037156156,25746},{904764510101117,982637352792061,94148},{756060606390732,851894133505126,95300},{94358969311629,700143010667454,24151},{447307499943756,597702174938719,90898},{250542572613311,395946018947565,95315},{427618818338246,859125987101407,5959},{217869320589660,446119241564076,5389},{419446046194289,951247525191738,60001},{841676879445924,926017977884738,74723},{712843501960875,958259865590179,34883},{253560332054221,467641475485976,57868},{117940177655703,870970302724208,99026},{40422212599842,944910815099215,29117},{79233831300266,662316030993942,26468},{641694961382412,878408506191573,50859},{17460846856586,98530119467692,67335},{29062942822929,365653130850825,84226},{552000015660943,809005156907540,20724},{47576665447314,115025508321507,25856},{350049463685461,405732915617710,27505},{424298519435636,519960374548473,24052},{463063636884819,918058763184258,81847},{366858486251221,904758048272205,82461},{433435813092195,575337570331189,52631},{261007137696826,838019854815805,32190},{8145477171909,500006600474914,58103},{579116135638767,766736200829758,42777},{5652767880015,498966978321589,21749},{49825117196488,255482230029687,12911},{529135630914970,877807807200674,77755},{397096372692211,435511061504674,13685},{354418031915540,580152501759665,77343},{331602561088385,761111849758458,55982},{343940281396817,995012325965831,93214},{262181669675546,371835060127146,93655},{794444122294249,872905634909238,63166},{600881666682873,638792967510592,59368},{469152713057150,641496978878833,57979},{437520639294805,499038333675139,31005},{224067676173318,707204810133966,25425},{173690781794467,858218076511495,17301},{706448989327164,986286473500448,78908},{187922589694309,469481268354684,62909},{528825964445125,650538219168478,67459},{629328305172996,865000196139573,47715},{965406224699396,965939157319812,18817},{362165764864127,727537405625576,24172},{160039113891932,415250422545393,6617},{408348424985699,724838037530226,8767},{64523958731778,723302988959061,82092},{529387417166051,744330348066857,83845},{416279187533020,517731130061643,65369},{382007110250479,667372176424456,7883},{158638287871492,962626124208888,20563},{898027573113675,918458257571029,90585},{670830522872050,714536639317598,34547},{425302888294623,762364859086081,86480},{20818606498087,52006361133292,77655},{4863569704140,479799758560187,56183},{93876483300606,202160175573732,1513},{363796704343420,894664112296523,62057},{202735345075243,920895762718787,67433},{26104426508547,572507930294270,53635},{254615315594291,359918660633938,29077},{155670053299376,836568636305658,40612},{163964407934620,408888097385989,92877},{247398682037266,307760618910972,6129},{12528869477550,386998381641651,71901},{283341957109536,547013571595345,53988},{28092044101882,385908712756865,84108},{251671159026235,843801734128550,75174},{198003909566196,224121412843821,69563},{288939823452796,807586705360871,41562},{287482264311805,675063639151542,59871},{560923898316053,772671859343610,22154},{260362960932859,701612172604521,17028},{104996086375848,389146576360973,35554},{120374639930658,862236961153140,85470},{258229026844484,332229658805595,19277},{800525319464348,892612757764989,37584},{219322574315701,302604148335193,72855},{460010109401041,700920658468959,51049},{249746031631698,324851472573807,94458},{92080978143861,892340892135079,10268},{544224452867292,613823531094040,11758},{314099379585167,759862449647118,97314},{837069650643034,956888187539312,19088},{323427747797352,757788244941949,58491},{227459012322321,570789079185202,26824},{490274713643306,558974287347997,38161},{199509287404141,363903357976880,54968},{165828819158570,491418274543435,59822},{236131335960027,405408826209396,42149},{382275788572734,690964882784139,6686},{336337190803379,586741426203297,17454},{841463471541323,865882846506739,48415},{322185614894543,855500396331698,21981},{449920006841490,475162747806109,61376},{393559556691978,765252453671919,34093},{123814122120984,724556193859212,50683},{384655392310770,734106362904586,32408},{638907895299762,963825365946571,86577},{18389984000193,507742090488065,58624},{153113693415846,738677609620053,55826},{353278461302091,796320324065161,49869},{120487455840624,893168310100090,8929},{31312696229851,667736453844515,62799},{309222752511994,704099686337610,84175},{69120439428320,439908126154933,43633},{140874489646564,855282240850736,56035},{290528454739140,948162992698092,94016},{133378073428493,679267660131561,3446},{80212409819238,215578786091039,29144},{709843638979503,939729539035745,35454},{502848846007895,785927477293483,92783},{299138131510932,777133454351735,48475},{653278549495306,803387321297509,51262},{464019928549523,594289428067737,13110},{624875908533228,778935820082016,43101},{551941267387125,903289392025286,41768},{453221434221062,508844976285909,63150},{783651921411286,868904427147931,1911},{149303733184950,973984631843116,23562},{677280175528973,726309133488917,7083},{367363188614225,653859776408737,65792},{486616560008153,496098300996082,69551},{55995171472520,650357705043030,16457},{82188142118838,840043153818782,32771},{125498337953065,660707543008776,65787},{276168856615147,319589581206043,23140},{390009827817415,585033955249421,71306},{803337346429908,871074298092014,49948},{82264923959670,786917584634739,77270},{217164757804268,928405625390588,27299},{21846969322090,97916013339438,96851},{391298004239373,779176831533257,70952},{282269426844047,404321070170314,37412},{930667351291298,955070427676583,7397},{337473499905468,989966807539288,59166},{409219854408910,717641380306745,87705},{717336304436159,734721015060704,96354},{905905478755048,993752177857454,58304},{103682645019956,933311970961158,596},{147721197219430,707184919669008,8086},{773323610928081,797359432737206,30733},{84691122683600,942502708765494,32942},{385565944192773,386444006530708,1048},{611351883351176,675690439233446,73351},{328690157770550,659984196899173,32396},{156784371526278,512360334514269,78961},{704808690008986,724205891138276,72594},{42900221633690,800737727017482,56169},{448333664609432,982885753088721,30830},{377951565018272,863339338907788,37323},{331632098740055,817767742562938,14656},{154235553556978,959667396921046,67526},{638368078488077,948717952116002,84439},{437786520233936,506355548963899,74891},{38560079567510,347117183078642,63575},{94568338892577,251442227492976,23868},{144786974621986,719350991451965,37416},{101431159053331,874647769393943,83270},{600009556026343,705684224861488,92444},{524592253723411,951714940764087,62672},{74292947502856,599358802790662,78753},{480513172891717,808277574951146,66117},{303117155843179,614242296995099,51052},{365051884763210,453048798586234,62504},{630953519060957,917505370242003,34429},{797548635343194,856624176029560,75979},{94784054379464,143669374731457,76638},{543586232403132,759654370431201,2671},{657567961807437,958541988488614,53625},{609619844720892,666358622548122,49718},{459946264350664,987811467912668,94164},{542575772896560,919269959703172,68034},{386918858418724,834635485450428,56515},{80786835435381,437919617407890,9792},{651210172661673,715916893976411,98700},{351555510575332,757287303391140,31066},{150572062172396,492469784419994,79785},{10704918311699,349542852617263,42050},{183726006598937,214788555380630,23286},{65951116632206,971163286441322,81161},{540925913530456,856331220874470,95622},{274401258121294,375755408330403,26581},{839832058239414,883762876130947,51115},{56998242520197,69460832171809,69387},{524891885217506,592716979960784,81555},{412904780446540,539156527028903,60367},{21993444711341,184818969250488,21907},{130448209601840,396268924428027,19967},{203947109340484,446064612681644,56523},{458089926614053,482263018180954,37466},{109393991754990,717891751616400,13606},{507558275977855,564112806006766,12892},{673398613710906,730951668002068,9644},{557869442141289,681236799178642,95796},{721572093101954,737253307592354,9105},{486867452890135,497757620831203,22526},{39673047899321,801140403105483,74839},{364530547383205,889520949393970,76523},{194032545303294,882682593266301,42399},{209120367324337,626864357790808,29302},{203626776482552,755657341307036,2023},{528622322405331,646502055035930,15150},{159684661106844,741648561481392,73408},{378823529523863,597605700254887,57237},{22483194265263,612920156660412,57719},{466504150621172,712495739150914,71692},{280601318966160,913558379589021,44319},{107990201273563,747589404313253,17590},{63290987416612,708277199631953,64014},{199433719848491,730151282211716,8157},{25809447611841,764527362332704,66421},{217718059442472,813212514007734,66917},{13576482667055,66609774895500,32282},{691036980800393,819407140944106,27329},{713316007405749,739823309898059,34505},{648527616200992,909827670073285,80962},{555743969535144,689532818459888,96771},{687827521286425,737900573108865,95406},{178897120131374,965167298060998,14168},{259313446214838,776792884054010,37309},{569742448856058,664499708489562,80012},{268907216877999,538401045183098,88952},{194882932485492,291408152741102,12191},{477417768932343,937892999640169,31064},{294230104737997,618232043399536,8532},{86816390208535,390026710643288,44104},{550470381758187,808179542691797,26264},{446502026901828,626742126434100,27692},{801612514973201,977553982823091,38050},{791370658131972,879045390384383,30010},{766381408250925,824022946469116,51498},{504619101118388,956690669236279,83672},{78555985803144,263128380009920,79349},{172857469481218,593411881621861,64263},{244740087615197,355943098455821,37836},{479632077019856,908285564570472,92202},{245670016470255,382317344991779,55155},{166522628903825,395107613380472,82888},{25250385334111,203099522165258,16900},{171171259971792,979308975471211,17909},{315016511118984,536847617726660,32936},{359670229568459,774458419505777,15816},{221061222692375,297006353623160,83212},{17028883585951,300157531654950,12846},{103968103778333,932766363235667,70916},{628742872329007,825147004099451,83098},{717595668193342,801731698484657,58541},{528266024915093,590630892540738,68790},{833914691940999,931943376339254,21249},{794762776057755,892650687353110,76212},{503822338755645,898226135524187,71148},{417574715337081,510885376490759,11623},{970321992518238,971508406793707,4416},{304696979055424,464225900657665,44391},{132769158732626,257099469248728,45321},{6633710275197,296196949075724,41715},{499257767376886,635549865466029,1035},{12096190249184,739848837945036,82823},{303495453249048,482382464154412,408},{526321769069239,537567191336014,37265},{365743573977832,927546771146016,37281},{508471828395642,744938935429716,90992},{306936793686991,581118149702391,83095},{735768529837802,973790659342717,17685},{435770744368689,874952829220258,88479},{36074284912657,465514384081053,27381},{530974108543117,884859880704508,11140},{238184086564662,666987848473833,73132},{534114615382323,678278505338341,7651},{22614436643938,903258058198293,73803},{221861668496934,493734729025702,34376},{318072159369916,391611729099878,74025},{668931677893655,787922776255606,30699},{561145176100540,797743046402906,14060},{106792192171657,491304978706028,8874},{94380245542434,483647941791816,16567},{89791033083028,604488855253373,36848},{143732528798576,355201648181005,83607},{258137058383524,481097528080069,92365},{560931211602313,682470721484083,64665},{360462787255856,827305826134824,55399},{0,1000000000000000,1301} };auto res = slu.findProductsOfElements(queries);Assert({ 69466,27076,2758,38294,19964,10490,8,4126,7564,13576,60878,84827,2928,793,81926,23438,9878,46888,77918,28378,3952,52396,17170,3847,15620,39396,29300,43833,6700,42449,47432,15005,52112,42486,4375,23326,63234,30104,30496,712,76070,65084,11444,2048,12672,128,55936,576,1808,2,31780,19469,20824,1695,11756,50956,55324,35126,25014,3218,43657,30968,42760,26992,9547,14741,29548,9848,4856,856,1728,8747,19342,55728,22576,5674,21225,29928,10518,17208,1087,320,18188,32988,20320,13387,73110,14170,28780,19684,67778,224,15278,14627,2608,10488,8900,19936,12796,45094,718,10692,4502,3698,578,54222,13502,21363,16459,63236,89932,50359,39668,62739,14372,8888,7016,38436,39968,13058,22964,67992,1164,9278,23948,21148,39472,56388,39376,12136,20644,9529,14828,12940,35128,13329,4112,22904,45815,68,13170,128,47858,14693,20094,4248,42109,37698,10375,26406,3040,927,1024,41644,26779,29556,72038,20477,2779,10760,5592,18349,350,55232,1024,44544,63239,42246,8564,7822,26464,24240,10199,25467,23185,27514,12224,56732,26500,39488,20992,49044,20372,7814,9862,6552,15432,24073,27649,31084,18256,17347,11674,29612,53544,328,5032,65478,512,15464,4796,4096,64,39646,20230,4552,69288,497,41932,3860,816,30496,26049,22334,71252,56904,1488,32,74174,2207,2610,11190,30807,15386,45460,19730,24590,18064,13529,47491,35962,19208,23296,15017,18748,16746,26269,7288,18302,24662,5482,7890,7070,19971,9563,11050,35988,68366,67343,30962,40096,14825,6362,212,256,26896,61147,32397,1114,18170,18776,5235,8057,36020,72852,37358,1097,13549,34007,1241,33312,59119,38617,757,31963,57384,38548,7456,32680,36964,380,55930,25112,60856,27094,21447,9800,35158,17672,11360,21908,6518,16914,5776,7906,43438,50164,9076,266,64514,4960,39374,20696,24010,21048,37608,33464,2740,15524,1664,3035,33856,33435,22006,16200,55418,44800,30052,42817,6290,44080,8192,17827,20833,72832,3396,24544,14120,84014,47951,18200,8108,39442,15872,41926,1843,19534,2308,63744,64969,2508,8762,11669,21872,51474,5900,16366,21271,77379,28568,32344,966,40484,79009,30700,47616,268,5988,15697,1220,880,46429,4096,20685,2048,40312,3846,2048,12928,39096,49593,67722,47062,15920,24088,21664,60020,21232,20429,56767,33684,4872,32255,56458,512,1936,5777,31154,16088,48808,22622,512,45152,2598,47792,1126,15560,6957,27778,13080,17049,57122,22118,18028,2707,16286,11528,11316,1356,9340,1460,92396,1,6722,68682,60859,8192,2580,988,2468,21952,31298,49783,21292,20353,6928,16358,2084,22483,40590,22032,23905,23033,56340,20054,39008,7800,407,512,1024,8914,29944,712,936,18776,9160,11842,22462,10012,78080,3709,31063,27932,40672,19366,6832,12748,11485,13136,14704,12900,8942,15868,42982,13085,20342,194,128,3532,8869,3712,44056,24220,28381,124,80202,8,27226,6901,62464,48803,13651,42473,6475,1152,31532,396,24970,32800,45109,1001,1024,8702,6278,18384,46787,32,17987,34108,313}, res);}
}

扩展阅读

视频课程

有效学习:明确的目标 及时的反馈 拉伸区(难度合适),可以先学简单的课程,请移步CSDN学院,听白银讲师(也就是鄙人)的讲解。
https://edu.csdn.net/course/detail/38771

如何你想快速形成战斗了,为老板分忧,请学习C#入职培训、C++入职培训等课程
https://edu.csdn.net/lecturer/6176

相关下载

想高屋建瓴的学习算法,请下载《喜缺全书算法册》doc版
https://download.csdn.net/download/he_zhidan/88348653

我想对大家说的话
《喜缺全书算法册》以原理、正确性证明、总结为主。
闻缺陷则喜是一个美好的愿望,早发现问题,早修改问题,给老板节约钱。
子墨子言之:事无终始,无务多业。也就是我们常说的专业的人做专业的事。
如果程序是一条龙,那算法就是他的是睛

测试环境

操作系统:win7 开发环境: VS2019 C++17
或者 操作系统:win10 开发环境: VS2022 C++17
如无特殊说明,本算法用**C++**实现。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/16784.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Lookin高效调试iOS App的UI

Lookin是一款iOS开发时常用的调试软件&#xff0c;由腾讯微信读书团队QMUI开发。 它可以查看和修改iOS App里的UI对象的软件&#xff0c;展示App UI图层&#xff0c;类似于Xcode自带的UI Inspector工具&#xff0c;或另一款叫做Reveal的软件。 此外&#xff0c;虽然Lookin主体…

内存泄漏案例分享4-异步任务流内存泄漏

案例4——异步任务内存泄漏 异步任务&#xff0c;代指起子线程异步完成一些数据操作、网络接口请求等&#xff0c;通常会使用以下API&#xff1a; Runnbale&#xff0c;Thread,线程池RxJavaHandlerThread 而这些异步任务很有可能操作内存泄漏&#xff0c;下面我们以Rxjava为…

【实战JVM】-基础篇-02-类的声明周期-加载器

【实战JVM】-基础篇-02-类的声明周期-加载器 3 类的生命周期3.1 生命周期的概述3.2 加载阶段3.2.1 查看内存中的对象 3.3 连接阶段3.3.1 验证阶段3.3.1.1 验证是否符合jvm规范3.3.1.2 元信息验证3.3.1.3 验证语义3.3.1.4 符号引用验证 3.3.2 准备阶段3.3.3 解析阶段 3.4 初始化…

使用OpenCV计算滑块缺口(2)

上一篇 openCV 计算滑块缺口&#xff0c;执行可能出现问题&#xff0c;这一篇文章&#xff0c;是上一版本的补充&#xff08;https://blog.csdn.net/weixin_42883164/article/details/137604965&#xff09; 实现计算滑块缺口的步骤&#xff1a; 接口部分参照上述文章&#xf…

创新营销之路:探索订单排队模式的无限可能

随着市场竞争的日益激烈&#xff0c;企业家们都在寻找新的营销策略来脱颖而出。在这里&#xff0c;我想向大家介绍一种充满活力和创新性的营销新模式——订单排队模式。它不仅能够有效提升用户黏性&#xff0c;还能为企业带来持续的增长动力。 一、订单排队模式的魅力 订单排队…

为什么建议大家加快拥抱Kotlin,说点不一样的

本文首发于公众号“AntDream”&#xff0c;欢迎微信搜索“AntDream”或扫描文章底部二维码关注&#xff0c;和我一起每天进步一点点 Kotlin自2017年起被Google正式宣布为Android的编程语言之一&#xff0c;随后在2019年进一步宣布Kotlin为Android的首选语言&#xff0c;普及速度…

上下文视觉提示实现zero-shot分割检测及多visual-prompt改造

文章目录 一、Closed-Set VS Open-set二、DINOv2.1 论文和代码2.2 内容2.3 安装部署2.4 使用效果 三、多visual prompt 改造3.1 获取示例图mask3.2 修改函数参数3.3 推理代码3.4 效果的提升&#xff01; 四、总结 本文主要介绍visual prompt模型DINOv&#xff0c;该模型可输入八…

深度解析:医院管理全面数字化转型的技术实现与优势

随着科技的飞速发展&#xff0c;信息技术的应用已经渗透到社会的各个角落&#xff0c;医疗行业作为关乎人民群众生命健康的重要领域&#xff0c;更是急需借助科技的力量实现转型升级。在这样的时代背景下&#xff0c;全面数字化转型成为了医院管理创新的必由之路。 北京XXX医院…

linux下宝塔负载100%解决方法

今天发现服务器宝塔面板负载居然是100% 但是cpu 和内存其实并不高 通过命令查看主机 uptime 中load average 居然高达18.23 看来负载是真的高了 通过vmstat 看看具体问题 procs&#xff1a; ​ r 表示运行和等待CPU时间片的进程数&#xff0c;这个值如果长期大于系统CPU个数…

Pytorch深度学习实践笔记9(b站刘二大人)

&#x1f3ac;个人简介&#xff1a;一个全栈工程师的升级之路&#xff01; &#x1f4cb;个人专栏&#xff1a;pytorch深度学习 &#x1f380;CSDN主页 发狂的小花 &#x1f304;人生秘诀&#xff1a;学习的本质就是极致重复! 《PyTorch深度学习实践》完结合集_哔哩哔哩_bilibi…

【一竞技CS2】YaLLa 2024邀请TheMongolz和BB

1、近日YaLLa Compass 2024主办方已宣布了最后两支受邀参赛的队伍是TheMongolz和BB两支战队,赛事将于6月5日至9日间在阿联酋阿布扎比的Space 42 Arena举行,总奖金为40万美元。 值得一说的是本次赛事的12支参赛队伍中,Cloud9和FURIA尚未确定参赛阵容。在arT离队后,FURIA让青训队…

LaTex安装及配置(Windows)

LaTex安装及配置&#xff08;Windows&#xff09; 安装环境安装texlive下载texlive安装 编辑器安装texstudio下载texstudio安装 环境配置 使用第一个LaTex文档新建文件编程查看results 安装 环境安装 texlive下载 镜像清华源下载地址&#xff1a;https://mirrors.tuna.tsing…

Java通过Html(ftl模板)生成PDF实战, 可支持商用

Java通过Html(freemarker模板)生成PDF实战, 可支持商用 技术架构 springboot freemarker [pdfbox] flying-saucer-pdf 生成流程&#xff1a; freemarker: 根据数据填充ftl模板文件&#xff0c;得到包含有效数据的html文件&#xff08;包含页眉页脚页码的处理&#xff0c…

InteractiveGraph图谱中vue项目中如何使用

InteractiveGraph图谱中vue项目中如何使用 一、下载js和css和字体二、vue2.0项目中引用三、grap组件 一、下载js和css和字体 //在这里面找 https://github.com/grapheco/InteractiveGraph/blob/master/dist/examples/example1.html二、vue2.0项目中引用 //main.js中全局引入$ …

导入 FDTD 仿真的 S 参数到 INTERCONNECT 的器件中

导入 FDTD 仿真的 S 参数到 INTERCONNECT 的器件中 正文正文 很多时候,仿真链路比较大时,我们可以将仿真的每个部分分隔开来,用 FDTD 计算出每一部分的 S 参数,然后将这些 S 参数导入 INTERCONNECT 中得到最终的仿真结果。这里我们来介绍一下这种方法。 首先,我们从右侧…

Linux系统安装AMH服务器管理面板并实现远程访问管理维护

目录 前言 1. Linux 安装AMH 面板 2. 本地访问AMH 面板 3. Linux安装Cpolar 4. 配置AMH面板公网地址 5. 远程访问AMH面板 6. 固定AMH面板公网地址 1. 部署Docker Registry 2. 本地测试推送镜像 3. Linux 安装cpolar 4. 配置Docker Registry公网访问地址 5. 公网远程…

【链表】Leetcode 92. 反转链表 II【中等】

反转链表 II 给你单链表的头指针 head 和两个整数 left 和 right &#xff0c;其中 left < right 请你反转从位置 left 到位置 right 的链表节点&#xff0c;返回 反转后的链表 。 示例 1&#xff1a; 输入&#xff1a;head [1,2,3,4,5], left 2, right 4 输出&#x…

Solidity 教程01 Remix IDE 初次见面

访问链接地址&#xff1a; https://remix.ethereum.org/ 文件管理器 文件资源管理器用于管理工作区和文件。此插件还包含许多快捷方式和命令。要快速浏览&#xff0c;请右键单击文件以获取弹出菜单&#xff0c;并检查插件右上角的汉堡菜单。 要找到文件资源管理器模块 - 单…

rust语言初识

程序设计实践课上水一篇ing 来源&#xff1a;rust基础入门-1.初识rust-酷程网 (kucoding.com) rust作为一名新兴语言&#xff0c;与go又有些许不同&#xff0c;因为它的目标是对标系统级开发&#xff0c;也就是C、C这两位在编程界的位置。比如我们最常用的windows系统&#x…

001.数据分析_NumPy

我 的 个 人 主 页&#xff1a;&#x1f449;&#x1f449; 失心疯的个人主页 &#x1f448;&#x1f448; 入 门 教 程 推 荐 &#xff1a;&#x1f449;&#x1f449; Python零基础入门教程合集 &#x1f448;&#x1f448; 虚 拟 环 境 搭 建 &#xff1a;&#x1f449;&…