版本比较
粉丝の紫
正文
增加 849 行删除 203 行
2 行未改动34567789101112131415161718192078 行未改动9910010110210010310410210510610410710810911011114 行未改动1261271281291271301311321331341321351361371381395 行未改动1451461471481461491501511521532 行未改动15615715815915716016116216316416516616716816916717017117217317117217317417517617717517817918018118218318418518618418718818919019118919219319419519619719519819920020120238 行未改动2412422432442422452462472482492502512522502532542552562542572582592602612622632642622652662672682692702682712722702732742752762742772782792802812822832812842852862872884 行未改动29329429529629429729829929730030130230030330430530330630730830931030831131231331431231531631731831919 行未改动33934034134234034334434534634734834935034835135235335135435535635735821 行未改动3803813823833813843853863873883 行未改动39239339439539339639739839939740040140240340440240540640740840640941041141241041341441541641741841941742042142242342467 行未改动4924934944954934964974984995004 行未改动5055065075085065095105115125105135145155165175155185195205215195225235245255235265275285295305285315325335345355365375355385395405415425435445425455465475485497 行未改动5575585595605585615625635645655665645675685695675705715725735745 行未改动5805815825835815845855865875883 行未改动5925935945955935965975985996006016026036046026056066076086096106116126106136146156136166176186196206216226206236246256266276286266276296306316326336346326356366376386395 行未改动6456466476486466496506516526533 行未改动65765865966065866166266366466566666766866966767067167267367467567667767567867968067868168268368468568668768568868969069169269369169469569669769869969770070170270370470570670470770870970771071170971271371471571610 行未改动7277287297307287317327337317347357367377382 行未改动7417427437447427457467477487498 行未改动7587597607617597627637647657667677687697677707717727737747757737767777787797807817827837847857837867877887897907917897927937947957965 行未改动8028038048058038068078088098105 行未改动8168178188198178208218228208238248258268279 行未改动8378388398408388418428438448458468478458488498508518528538518548558568578584 行未改动86386486586686486786886686987086887187287387487587687787887687988088188288388488288588688788888928 行未改动9189199209219199229239249259263 行未改动9309319329339319349359369379382 行未改动94194294394494294594694794894913 行未改动9639649659669649679689699679709719729739749729759769779789799779809819829839846 行未改动99199299399499299599699799899699910001001100210031001100410051006100710085 行未改动101410151016101710151018101910201018102110221023102410221025102610271025102810291030103110321030103310341035103610341037103810391040104110421040104310441045104610471045104810491050105110521053105110541055105610571055105810591060106110623 行未改动10661067106810691067107010711072107010731074107510761077107810761079108010811082108310841082108510861087108810891090108810911092109310941095109610941097109810991100110111021100110311041105110611074 行未改动111211131114111511131116111711181119112011211119112211231124112511261127112511281129113011311132113311341135113611371135113811391140114111421143114411451146114711451148114911501151115211531154115511561157115511581159116011611159116211631164116511669 行未改动117611771178117911771180118111821183118411851183118611871188118911901191119211931194119511931196119711981199119712001201120212031204120512061207120812091207121012111212121312149 行未改动12241225122612271225122812291230123112291232123312341235123612371238123612391240124112421243124412421245124612471248124612491250125112491252125312541255125612571255125812591260126112591262126312641265126612671268126912701271126912721273127412751276127712781276127912801281128212801283128412851286128712881289129012881291129212931294129535 行未改动1331133213331334133213331335133613371335133813391340134113421343134413421345134613471348134913 行未改动136313641365136613641367136813661369137013711372137013731374137513761374137713781379138013811379138213831384138513863 行未改动13901391139213931391139413951396139713986 行未改动140514061407140814061409141014111412141323 行未改动14371438143914401438144114421443144414451446144714481449145014481451145214531454145514531456145714581459146014611462146314611464146514661464146714681469146714701471147214731474147514761477147514781479148014811479148214831484148514861487148814891487149014911492149314941495149614971498149914971500150115021503150415021505150615071508150921 行未改动153115321533153415321535153615371538153915401538154115421543154415421545154615471548154915471550155115521553155415551556155415571558155915571560156115621560156315641565156615671568156915701568157115721573157115741575157615771578157915801581158215831581158415851586158715881586158915901591158915921593159415951596159715981596159916001601160216031601160416051606160416071608160916101608161116121613161416151613161616171618161916201618162116221623162416257 行未改动16331634163516361634163716381639164016411642164316441645164616441647164816491650164816511652165316541655165616541657165816591660165816611662166316641665166616671668166616691670166816691671167216731674167516731676167716781679168016781681168216831681168416851686168716886 行未改动16951696169716981696169917001701170217031701170417051706170717081709170717101711171217131711171417151716171717181719172017211722172017231724172217251726172717281729173017311732173317341732173517361737173817393 行未改动17431744174517461744174717481749175017516 行未改动17581759176017611759176217631764176217651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132 行未改动写完之后会让 AI 改代码,防抄袭。(我也不知道对不对)
提示词:
``````text下面是一段C++代码,随便改,尽量复杂一些。(代码)(题目)```
改出来的不是人看的。
字数统计:62030 字符
### 44粉:[Brute_Force](https://www.luogu.com.cn/user/995899)
[【模板】三维偏序 / 陌上花开](https://www.luogu.com.cn/problem/P3810)
78 行未改动private: int num_threads; vector<thread> workers; vector<int>& data;
public: ParallelCalculator(vector<int>& d, int threads = thread::hardware_concurrency()) ParallelCalculator(vector<int>& d, int threads = thread::hardware_concurrency()) : data(d), num_threads(threads) {}
template<typename Func> void parallel_for(int start, int end, Func&& func) { int chunk = (end - start) / num_threads; for(int i = 0; i < num_threads; ++i) {14 行未改动template<typename... Args>class MultiDimensionalArray {private: tuple<vector<Args>...> data;
template<size_t... Is> void print_impl(index_sequence<Is...>) { (cout << ... << get<Is>(data).size()) << endl; }
public: void print_sizes() { print_impl(index_sequence_for<Args...>{}); }5 行未改动private: static constexpr size_t POOL_SIZE = 1000000; T pool[POOL_SIZE]; bool used[POOL_SIZE];
public: T* allocate() { for(size_t i = 0; i < POOL_SIZE; ++i) { if(!used[i]) {2 行未改动 } } return nullptr; }
void deallocate(T* ptr) { size_t index = ptr - pool; used[index] = false; }};
// 优化后的节点结构,使用移动语义和noexceptstruct Node { int a, b, c;
Node() noexcept = default; Node(int a_, int b_, int c_) noexcept : a(a_), b(b_), c(c_) {} Node(const Node&) = default; Node(Node&& other) noexcept : a(exchange(other.a, 0)), b(exchange(other.b, 0)), Node(Node&& other) noexcept : a(exchange(other.a, 0)), b(exchange(other.b, 0)), c(exchange(other.c, 0)) {}
Node& operator=(Node&& other) noexcept { if(this != &other) { a = exchange(other.a, 0); b = exchange(other.b, 0); c = exchange(other.c, 0); } return *this; }
bool operator<(const Node& r) const { static constexpr auto comparator = [](int x, int y, bool odd) -> bool { return odd ? x < y : x > y; };
if(bel[a] != bel[r.a]) { return bel[a] < bel[r.a]; } return comparator(b, r.b, bel[a] & 1); }
static inline vector<int> bel; // C++17 inline静态成员};
// 常量表达式优化38 行未改动}
// 查询函数 - 使用标准算法int query(int x, const vector<int>& val, const vector<int>& sum, const vector<int>& bel) { return accumulate(begin(val), begin(val) + x, 0) + return accumulate(begin(val), begin(val) + x, 0) + accumulate(next(begin(sum)), next(begin(sum), bel[x]), 0);}
signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
// 初始化 cin >> n >> k; vector<future<void>> futures;
// 异步读取输入 for(int i = 1; i <= n; ++i) { futures.push_back(async(launch::async, [i, &a, &b, &c]() { cin >> a[i] >> b[i] >> c[i]; })); } for(auto& f : futures) f.get();
// 使用并行算法 parallel_for(1, n + 1, [&](int i) { ++ra[a[i]]; ++rb[b[i]]; });
// 变换操作 transform(ra.begin() + 1, ra.begin() + k + 1, ra.begin(), transform(ra.begin() + 1, ra.begin() + k + 1, ra.begin(), [](int x) { return x; }); transform(rb.begin() + 1, rb.begin() + k + 1, rb.begin(), [](int x) { return x; });
for(int i = 1; i <= k; ++i) { la[i] = ra[i - 1] + 1; ra[i] += ra[i - 1]; lb[i] = rb[i - 1] + 1; rb[i] += rb[i - 1]; }
// 使用optional处理可能的空值 optional<int> temp; for(int i = 1; i <= n; ++i) { int x = la[a[i]]++;4 行未改动 ac[x] = c[i]; bc[y] = c[i]; temp = x; // 使用optional }
// 初始化bel数组 iota(bel.begin(), bel.end(), 0); transform(bel.begin(), bel.end(), bel.begin(), transform(bel.begin(), bel.end(), bel.begin(), [](int i) { return i / B1; }); Node::bel = bel;
// 排序 - 使用并行排序 sort(execution::par, q.begin() + 1, q.begin() + n + 1);
// 重新初始化bel数组 iota(bel.begin(), bel.end(), 0); transform(bel.begin(), bel.end(), bel.begin(), [](int i) { return (i - 1) / B2 + 1; });
int na = 0, nb = 0; auto adder = create_adder(); auto remover = create_remover();
// 主循环 - 添加异常处理 try { for(int i = 1; i <= n; ++i) { while(na < q[i].a) {19 行未改动 remover(bc[nb], val, sum, bel); } nb--; }
int result = query(q[i].c, val, sum, bel); ans[result - 1]++; } } catch(const exception& e) { cerr << "Error during processing: " << e.what() << endl; return 1; }
// 输出结果 copy_n(ans.begin(), n, ostream_iterator<int>(cout, "\n"));
return 0;}``````
21 行未改动 int val, key, siz; int sum, mx, lx, rx; int tag; bool rev, same;
// 新增的统计信息 int mn; // 最小值 int gcd_val; // 最大公约数 int xor_sum; // 异或和3 行未改动 int second_max; // 第二大值 int second_min; // 第二小值 int lazy_add; // 区间加法的懒标记 bool has_add; // 是否有加法标记
// 哈希相关(用于序列比对) uint64_t hash_val; // 哈希值 uint64_t hash_rev; // 反转哈希值
// 统计信息 int sum_square; // 平方和 int sum_cube; // 立方和 int sum_abs; // 绝对值和
// 区间最值位置 int max_pos; // 最大值位置 int min_pos; // 最小值位置
// 优先级队列(用于维护区间最值) priority_queue<int> max_heap; priority_queue<int, vector<int>, greater<int>> min_heap;
// 区间合并信息 int inc_len; // 最长连续递增长度 int dec_len; // 最长连续递减长度 int l_val, r_val; // 区间最左和最右的值 bool is_sorted_inc; // 是否升序 bool is_sorted_dec; // 是否降序
Node() { l = r = 0; val = key = siz = 0; sum = mx = lx = rx = 0;67 行未改动 tr[p].l = tr[p].r = 0; tr[p].val = x; tr[p].key = rand(); tr[p].siz = 1;
// 基础信息 tr[p].sum = x; tr[p].mx = x; tr[p].mn = x;4 行未改动 tr[p].cnt_negative = (x < 0) ? 1 : 0; tr[p].max_abs = abs(x); tr[p].second_max = -INF; tr[p].second_min = INF;
// 哈希信息 tr[p].hash_val = get_hash(x, 0); tr[p].hash_rev = get_hash(x, 0);
// 平方和立方 tr[p].sum_square = x * x; tr[p].sum_cube = x * x * x; tr[p].sum_abs = abs(x);
// 位置信息 tr[p].max_pos = p; tr[p].min_pos = p;
// 更新堆 tr[p].max_heap.push(x); tr[p].min_heap.push(x);
// 区间属性 tr[p].l_val = tr[p].r_val = x; tr[p].inc_len = tr[p].dec_len = 1; tr[p].is_sorted_inc = tr[p].is_sorted_dec = true;
// 懒标记 tr[p].same = false; tr[p].rev = false; tr[p].has_add = false; tr[p].lazy_add = 0; tr[p].tag = 0;
return p;}
// 增强版的pushupvoid pushup(int p) { if(!p) return;
tr[p].siz = 1; tr[p].sum = tr[p].val; tr[p].sum_square = tr[p].val * tr[p].val; tr[p].sum_cube = tr[p].val * tr[p].val * tr[p].val;7 行未改动 tr[p].max_abs = abs(tr[p].val); tr[p].l_val = tr[p].r_val = tr[p].val; tr[p].inc_len = tr[p].dec_len = 1; tr[p].is_sorted_inc = tr[p].is_sorted_dec = true;
// 清空堆并重新加入 while(!tr[p].max_heap.empty()) tr[p].max_heap.pop(); while(!tr[p].min_heap.empty()) tr[p].min_heap.pop(); tr[p].max_heap.push(tr[p].val); tr[p].min_heap.push(tr[p].val);
tr[p].second_max = -INF; tr[p].second_min = INF;
// 合并左子树 if(tr[p].l) { int lc = tr[p].l; tr[p].siz += tr[lc].siz;5 行未改动 tr[p].gcd_val = gcd(tr[p].gcd_val, tr[lc].gcd_val); tr[p].cnt_positive += tr[lc].cnt_positive; tr[p].cnt_negative += tr[lc].cnt_negative; tr[p].max_abs = max(tr[p].max_abs, tr[lc].max_abs);
// 合并堆 priority_queue<int> temp_max = tr[lc].max_heap; while(!temp_max.empty()) { tr[p].max_heap.push(temp_max.top());3 行未改动 while(!temp_min.empty()) { tr[p].min_heap.push(temp_min.top()); temp_min.pop(); }
// 更新最值 if(tr[lc].mx > tr[p].mx) { tr[p].second_max = tr[p].mx; tr[p].mx = tr[lc].mx; tr[p].max_pos = tr[lc].max_pos; } else if(tr[lc].mx < tr[p].mx) { update_second_values(p, tr[lc].mx); }
if(tr[lc].mn < tr[p].mn) { tr[p].second_min = tr[p].mn; tr[p].mn = tr[lc].mn; tr[p].min_pos = tr[lc].min_pos; } else if(tr[lc].mn > tr[p].mn) { update_second_values(p, tr[lc].mn); }
// 更新左右边界值 tr[p].l_val = tr[lc].l_val;
// 更新区间属性 if(tr[lc].is_sorted_inc && tr[lc].r_val <= tr[p].val) { tr[p].is_sorted_inc = tr[lc].is_sorted_inc; } else { tr[p].is_sorted_inc = false; }
if(tr[lc].is_sorted_dec && tr[lc].r_val >= tr[p].val) { tr[p].is_sorted_dec = tr[lc].is_sorted_dec; } else { tr[p].is_sorted_dec = false; } tr[p].inc_len = max(tr[lc].inc_len,
tr[p].inc_len = max(tr[lc].inc_len, (tr[lc].r_val <= tr[p].val ? tr[lc].inc_len + 1 : 1LL)); tr[p].dec_len = max(tr[lc].dec_len, (tr[lc].r_val >= tr[p].val ? tr[lc].dec_len + 1 : 1LL)); }
// 合并右子树 if(tr[p].r) { int rc = tr[p].r; tr[p].siz += tr[rc].siz;5 行未改动 tr[p].gcd_val = gcd(tr[p].gcd_val, tr[rc].gcd_val); tr[p].cnt_positive += tr[rc].cnt_positive; tr[p].cnt_negative += tr[rc].cnt_negative; tr[p].max_abs = max(tr[p].max_abs, tr[rc].max_abs);
// 合并堆 priority_queue<int> temp_max = tr[rc].max_heap; while(!temp_max.empty()) { tr[p].max_heap.push(temp_max.top());3 行未改动 while(!temp_min.empty()) { tr[p].min_heap.push(temp_min.top()); temp_min.pop(); }
// 更新最值 if(tr[rc].mx > tr[p].mx) { tr[p].second_max = tr[p].mx; tr[p].mx = tr[rc].mx; tr[p].max_pos = tr[rc].max_pos; } else if(tr[rc].mx < tr[p].mx) { update_second_values(p, tr[rc].mx); }
if(tr[rc].mn < tr[p].mn) { tr[p].second_min = tr[p].mn; tr[p].mn = tr[rc].mn; tr[p].min_pos = tr[rc].min_pos; } else if(tr[rc].mn > tr[p].mn) { update_second_values(p, tr[rc].mn); }
// 更新右边界值 tr[p].r_val = tr[rc].r_val;
// 更新区间属性 if(tr[p].is_sorted_inc && tr[p].val <= tr[rc].l_val && tr[rc].is_sorted_inc) { tr[p].is_sorted_inc = true; } else { tr[p].is_sorted_inc = false; }
if(tr[p].is_sorted_dec && tr[p].val >= tr[rc].l_val && tr[rc].is_sorted_dec) { tr[p].is_sorted_dec = true; } else { tr[p].is_sorted_dec = false; }
int left_inc = tr[p].inc_len; int right_inc = tr[rc].inc_len; if(tr[p].val <= tr[rc].l_val) { tr[p].inc_len = max(tr[p].inc_len, left_inc + (right_inc > 0 ? 1 : 0)); }
int left_dec = tr[p].dec_len; int right_dec = tr[rc].dec_len; if(tr[p].val >= tr[rc].l_val) { tr[p].dec_len = max(tr[p].dec_len, left_dec + (right_dec > 0 ? 1 : 0)); } }
// 计算 lx, rx, mx(原有逻辑,但增强) if(tr[p].l && tr[p].r) { tr[p].lx = max(tr[tr[p].l].lx, tr[p].lx = max(tr[tr[p].l].lx, tr[tr[p].l].sum + tr[p].val + max(0LL, tr[tr[p].r].lx)); tr[p].rx = max(tr[tr[p].r].rx, tr[p].rx = max(tr[tr[p].r].rx, tr[tr[p].r].sum + tr[p].val + max(0LL, tr[tr[p].l].rx)); tr[p].mx = max(max(tr[tr[p].l].mx, tr[tr[p].r].mx), max(tr[tr[p].l].rx, 0LL) + tr[p].val + max(tr[tr[p].r].lx, 0LL)); }10 行未改动 else { tr[p].lx = tr[p].rx = max(0LL, tr[p].val); tr[p].mx = tr[p].val; }
// 更新哈希值 int left_size = tr[tr[p].l].siz; tr[p].hash_val = tr[tr[p].l].hash_val + tr[p].hash_val = tr[tr[p].l].hash_val + get_hash(tr[p].val, left_size) * pow_base[left_size] + tr[tr[p].r].hash_val * pow_base[left_size + 1]; tr[p].hash_rev = tr[tr[p].r].hash_rev * pow_base[left_size + 1] + get_hash(tr[p].val, tr[tr[p].r].siz) * pow_base[tr[tr[p].r].siz] +2 行未改动
// 增强版的区间赋值void pushsame(int p, int c) { if(!p) return;
tr[p].val = c; tr[p].sum = c * tr[p].siz; tr[p].sum_square = c * c * tr[p].siz; tr[p].sum_cube = c * c * c * tr[p].siz;8 行未改动 tr[p].mx = max(c, tr[p].sum); tr[p].l_val = tr[p].r_val = c; tr[p].inc_len = tr[p].dec_len = tr[p].siz; tr[p].is_sorted_inc = tr[p].is_sorted_dec = true;
// 更新堆 while(!tr[p].max_heap.empty()) tr[p].max_heap.pop(); while(!tr[p].min_heap.empty()) tr[p].min_heap.pop(); tr[p].max_heap.push(c); tr[p].min_heap.push(c); tr[p].second_max = -INF; tr[p].second_min = INF;
// 更新哈希 for(int i = 0; i < tr[p].siz; i++) { tr[p].hash_val += get_hash(c, i); tr[p].hash_rev += get_hash(c, tr[p].siz - 1 - i); }
tr[p].same = true; tr[p].tag = c; tr[p].has_add = false; // 区间赋值会覆盖加法标记 tr[p].lazy_add = 0;}
// 新增:区间加法void pushadd(int p, int c) { if(!p) return;
if(tr[p].same) { // 如果已经有区间赋值标记,直接修改赋值标记 pushsame(p, tr[p].tag + c); return; }
tr[p].val += c; tr[p].sum += c * tr[p].siz; tr[p].sum_square += 2 * c * (tr[p].sum - c * tr[p].siz) + c * c * tr[p].siz; tr[p].sum_cube += 3 * c * tr[p].sum_square + 3 * c * c * (tr[p].sum - c * tr[p].siz) + c * c * c * tr[p].siz;5 行未改动 tr[p].rx = max(0LL, tr[p].rx + c); tr[p].mx += c; tr[p].l_val += c; tr[p].r_val += c;
// 更新堆 priority_queue<int> new_max; priority_queue<int, vector<int>, greater<int>> new_min; while(!tr[p].max_heap.empty()) {5 行未改动 tr[p].min_heap.pop(); } tr[p].max_heap = new_max; tr[p].min_heap = new_min;
if(tr[p].second_max != -INF) tr[p].second_max += c; if(tr[p].second_min != INF) tr[p].second_min += c;
tr[p].has_add = true; tr[p].lazy_add += c;}
9 行未改动
// 增强版的pushdownvoid pushdown(int p) { if(!p) return;
if(tr[p].has_add) { if(tr[p].l) pushadd(tr[p].l, tr[p].lazy_add); if(tr[p].r) pushadd(tr[p].r, tr[p].lazy_add); tr[p].has_add = false; tr[p].lazy_add = 0; }
if(tr[p].same) { if(tr[p].l) pushsame(tr[p].l, tr[p].tag); if(tr[p].r) pushsame(tr[p].r, tr[p].tag); tr[p].same = false; }
if(tr[p].rev) { if(tr[p].l) pushrev(tr[p].l); if(tr[p].r) pushrev(tr[p].r); tr[p].rev = false;4 行未改动 if(!p) { x = y = 0; return; }
pushdown(p);
int leftsize = tr[tr[p].l].siz;
if(leftsize >= k) { y = p; split(tr[p].l, k, x, tr[y].l); } else { x = p; split(tr[p].r, k - leftsize - 1, tr[x].r, y); }
pushup(p);}
int merge(int x, int y) { if(!x || !y) return x + y;
if(tr[x].key > tr[y].key) { pushdown(x); tr[x].r = merge(tr[x].r, y); pushup(x);28 行未改动 if(l > r) return; int len = r - l + 1; k = ((k % len) + len) % len; if(k == 0) return;
int x, y, z, w; split(root, l - 1, x, y); split(y, len, y, z); split(y, len - k, y, w);3 行未改动// 新增功能2:获取区间中位数int get_median(int p) { if(!p) return 0; pushdown(p);
// 使用对顶堆思想,这里简化处理:排序后取中间 vector<int> vals; function<void(int)> dfs = [&](int u) { if(!u) return;2 行未改动 vals.push_back(tr[u].val); dfs(tr[u].r); }; dfs(p);
sort(vals.begin(), vals.end()); return vals[vals.size() / 2];}
13 行未改动
// 新增功能4:判断两个区间是否相等(通过哈希)bool interval_equal(int root, int l1, int r1, int l2, int r2) { if(r1 - l1 != r2 - l2) return false;
int len = r1 - l1 + 1; int a, b, c, d, e, f;
split(root, l1 - 1, a, b); split(b, len, b, c); uint64_t hash1 = tr[b].hash_val; root = merge(merge(a, b), c);
split(root, l2 - 1, d, e); split(e, len, e, f); uint64_t hash2 = tr[e].hash_val; root = merge(merge(d, e), f);
return hash1 == hash2;}
// 新增功能5:区间离散化6 行未改动 vals.push_back(tr[u].val); dfs(tr[u].r); }; dfs(p);
vector<int> sorted = vals; sort(sorted.begin(), sorted.end()); sorted.erase(unique(sorted.begin(), sorted.end()), sorted.end());
map<int, int> mp; for(int i = 0; i < sorted.size(); i++) { mp[sorted[i]] = i + 1; }
vector<int> res; for(int v : vals) { res.push_back(mp[v]); }5 行未改动 cin.tie(0); cout.tie(0); srand(time(0)); init_pow();
int n, m; cin >> n >> m;
for(int i = 1; i <= n; i++) { cin >> a[i]; }
root = build(1, n); string op;
while(m--) { cin >> op; operation_count++; history.push_back(operation_count);
if(op == "INSERT") { int pos, tot; cin >> pos >> tot;
for(int i = 1; i <= tot; i++) { cin >> a[i]; value_set.insert(a[i]); freq_map[a[i]]++; }
int x, y; split(root, pos, x, y); int z = build(1, tot); root = merge(merge(x, z), y);
cout << "Inserted " << tot << " elements at position " << pos << endl; } else if(op == "DELETE") { int pos, tot; cin >> pos >> tot;
int x, y, z; split(root, pos - 1, x, y); split(y, tot, y, z);
// 更新频率统计 function<void(int)> update_freq = [&](int u) { if(!u) return; update_freq(tr[u].l);3 行未改动 } update_freq(tr[u].r); }; update_freq(y);
del(y); root = merge(x, z);
cout << "Deleted " << tot << " elements from position " << pos << endl; } else if(op == "MAKE-SAME") { int pos, tot, c; cin >> pos >> tot >> c;
int x, y, z; split(root, pos - 1, x, y); split(y, tot, y, z); pushsame(y, c); root = merge(merge(x, y), z);
cout << "Set " << tot << " elements to " << c << endl; } else if(op == "REVERSE") { int pos, tot; cin >> pos >> tot;
int x, y, z; split(root, pos - 1, x, y); split(y, tot, y, z); pushrev(y); root = merge(merge(x, y), z);
cout << "Reversed " << tot << " elements from position " << pos << endl; } else if(op == "GET-SUM") { int pos, tot; cin >> pos >> tot;
int x, y, z; split(root, pos - 1, x, y); split(y, tot, y, z); cout << "Sum: " << tr[y].sum << endl;4 行未改动 } else if(op == "ADD") { // 新增:区间加法 int pos, tot, c; cin >> pos >> tot >> c;
int x, y, z; split(root, pos - 1, x, y); split(y, tot, y, z); pushadd(y, c); root = merge(merge(x, y), z);
cout << "Added " << c << " to " << tot << " elements" << endl; } else if(op == "MIN") { // 新增:查询最小值 int pos, tot; cin >> pos >> tot;
int x, y, z; split(root, pos - 1, x, y); split(y, tot, y, z); cout << "Minimum: " << tr[y].mn << endl; root = merge(merge(x, y), z); } else if(op == "GCD") { // 新增:查询最大公约数 int pos, tot; cin >> pos >> tot;
int x, y, z; split(root, pos - 1, x, y); split(y, tot, y, z); cout << "GCD: " << tr[y].gcd_val << endl; root = merge(merge(x, y), z); } else if(op == "XOR") { // 新增:查询异或和 int pos, tot; cin >> pos >> tot;
int x, y, z; split(root, pos - 1, x, y); split(y, tot, y, z); cout << "XOR: " << tr[y].xor_sum << endl; root = merge(merge(x, y), z); } else if(op == "STATS") { // 新增:统计信息 int pos, tot; cin >> pos >> tot;
int x, y, z; split(root, pos - 1, x, y); split(y, tot, y, z);
cout << "=== Statistics ===" << endl; cout << "Size: " << tr[y].siz << endl; cout << "Sum: " << tr[y].sum << endl; cout << "Sum of squares: " << tr[y].sum_square << endl;9 行未改动 cout << "Longest increasing sequence: " << tr[y].inc_len << endl; cout << "Longest decreasing sequence: " << tr[y].dec_len << endl; cout << "Is sorted ascending: " << (tr[y].is_sorted_inc ? "Yes" : "No") << endl; cout << "Is sorted descending: " << (tr[y].is_sorted_dec ? "Yes" : "No") << endl;
root = merge(merge(x, y), z); } else if(op == "MEDIAN") { // 新增:查询中位数 int pos, tot; cin >> pos >> tot;
int x, y, z; split(root, pos - 1, x, y); split(y, tot, y, z); cout << "Median: " << get_median(y) << endl; root = merge(merge(x, y), z); } else if(op == "MODE") { // 新增:查询众数 int pos, tot; cin >> pos >> tot;
int x, y, z; split(root, pos - 1, x, y); split(y, tot, y, z);
auto freq = get_mode(y); int mode_val = 0, max_freq = 0; for(auto &[val, cnt] : freq) { if(cnt > max_freq) { max_freq = cnt; mode_val = val; } } cout << "Mode: " << mode_val << " (appears " << max_freq << " times)" << endl;
root = merge(merge(x, y), z); } else if(op == "ROTATE") { // 新增:区间旋转 int pos, tot, k;9 行未改动 } else if(op == "DISCRETE") { // 新增:区间离散化 int pos, tot; cin >> pos >> tot;
int x, y, z; split(root, pos - 1, x, y); split(y, tot, y, z);
auto discrete = interval_discrete(y); cout << "Discretized values: "; for(int v : discrete) { cout << v << " "; } cout << endl;
root = merge(merge(x, y), z); } else if(op == "UNIQUE") { // 新增:统计不同元素个数 int pos, tot; cin >> pos >> tot;
int x, y, z; split(root, pos - 1, x, y); split(y, tot, y, z);
auto freq = get_mode(y); cout << "Number of distinct elements: " << freq.size() << endl;
root = merge(merge(x, y), z); } else if(op == "TOP-K") { // 新增:查询前k大元素 int pos, tot, k; cin >> pos >> tot >> k;
int x, y, z; split(root, pos - 1, x, y); split(y, tot, y, z);
vector<int> vals; function<void(int)> dfs = [&](int u) { if(!u) return; pushdown(u); dfs(tr[u].l); vals.push_back(tr[u].val); dfs(tr[u].r); }; dfs(y);
sort(vals.rbegin(), vals.rend()); cout << "Top " << k << " elements: "; for(int i = 0; i < min(k, (int)vals.size()); i++) { cout << vals[i] << " "; } cout << endl;
root = merge(merge(x, y), z); } }
// 输出操作统计 cout << "\n=== Operation Statistics ===" << endl; cout << "Total operations: " << operation_count << endl; cout << "Current tree size: " << tr[root].siz << endl; cout << "Nodes in use: " << cnt << endl; cout << "Nodes in pool: " << top << endl; cout << "Distinct values: " << value_set.size() << endl;
return 0;}```
35 行未改动 int id; int timestamp; int priority; mutable int version; node(int v = 0, int i = 0, int t = 0, int p = 0, int ver = 0)
node(int v = 0, int i = 0, int t = 0, int p = 0, int ver = 0) : val(v), id(i), timestamp(t), priority(p), version(ver) {}
bool operator<(const node &other) const { if (val != other.val) return val < other.val; if (priority != other.priority) return priority < other.priority; if (timestamp != other.timestamp) return timestamp < other.timestamp; return id > other.id; }
bool operator==(const node &other) const { return id == other.id && version == other.version; }};13 行未改动 heap_base backup_heap; unordered_map<int, int> metadata; int heap_id; mutable int modification_count;
extended_heap(int id = 0) : heap_id(id), modification_count(0) {}
bool empty() const { return main_heap.empty() && backup_heap.empty(); }
size_t size() const { return main_heap.size() + backup_heap.size(); }
void push(const node& n) { main_heap.push(n); modification_count++; }
node top() const { if (!main_heap.empty()) { node top_main = main_heap.top(); if (!backup_heap.empty()) {3 行未改动 return top_main; } return backup_heap.top(); }
void pop() { if (!main_heap.empty() && !backup_heap.empty()) { if (main_heap.top() < backup_heap.top()) { backup_heap.pop();6 行未改动 backup_heap.pop(); } modification_count++; }
void merge(extended_heap& other) { main_heap.join(other.main_heap); backup_heap.join(other.backup_heap); modification_count += other.modification_count;23 行未改动 vector<heap_base::point_iterator> pos; vector<extended_heap> heaps; vector<operation_log> op_log; int current_time;
// Advanced find with path compression and union by size int find(int x) { if (fa[x] != x) { int root = find(fa[x]); // Path halving optimization fa[x] = root; } return fa[x]; }
// Generate random priority for nodes int random_priority() { return uniform_int_distribution<int>(0, MOD)(rng); }
// Validate operation before execution bool validate_operation(int op, int A, int B = -1) { if (A < 1 || A > n) return false; if (op == 4 && (B < 1 || B > n)) return false; if (op == 2 && del[A]) return false; return true; }
public: GensokyoSolver() : current_time(0) {}
void solve() { cin >> T >> W >> K;
while (T--) { initialize_test_case(); process_operations(); output_results(); cleanup(); } }
private: void initialize_test_case() { cin >> n >> m;
a.resize(n + 1); fa.resize(n + 1); del.resize(n + 1); pos.resize(n + 1); heaps.clear(); heaps.reserve(n + 1); op_log.clear();
for (int i = 1; i <= n; i++) { cin >> a[i]; fa[i] = i; del[i] = false; heaps.emplace_back(i); int priority = random_priority(); pos[i] = heaps[i-1].main_heap.push({a[i], i, current_time++, priority, 0}); } }
void process_operations() { for (int i = 1; i <= m; i++) { int op; cin >> op;
if (op == 1) { handle_undo(); } else if (op == 2) { int A;21 行未改动 handle_statistics(); } } }
void handle_delete(int A) { operation_log log; log.type = 2; log.arg1 = A; log.timestamp = current_time++;
if (!del[A]) { del[A] = true; int pa = find(A);
if (!heaps[pa-1].main_heap.empty()) { node current = *pos[A]; log.old_state = current; log.new_state = node(0, A, current_time, 0, current.version + 1);
heaps[pa-1].main_heap.erase(pos[A]); heaps[pa-1].backup_heap.push(log.new_state); op_log.push_back(log); } } }
void handle_modify(int A, int B) { int pa = find(A);
if (!heaps[pa-1].empty()) { node tp = heaps[pa-1].top();
if (!del[tp.id]) { operation_log log; log.type = 3; log.arg1 = tp.id; log.arg2 = B; log.timestamp = current_time++; log.old_state = tp;
int nv = tp.val - B; if (nv < 0) nv = 0;
if (nv == 0) { del[tp.id] = true; heaps[pa-1].main_heap.erase(pos[tp.id]); log.new_state = node(0, tp.id, current_time, 0, tp.version + 1); } else { node new_node = {nv, tp.id, current_time, tp.priority, tp.version + 1}; heaps[pa-1].main_heap.modify(pos[tp.id], new_node); log.new_state = new_node; }
op_log.push_back(log); } } }
void handle_merge(int A, int B) { int pa = find(A), pb = find(B);
if (pa != pb) { operation_log log; log.type = 4; log.arg1 = pa; log.arg2 = pb; log.timestamp = current_time++;
// Union by size with heap size consideration if (heaps[pa-1].size() < heaps[pb-1].size()) { swap(pa, pb); }
heaps[pa-1].merge(heaps[pb-1]); fa[pb] = pa;
op_log.push_back(log); } }
void handle_undo() { if (!op_log.empty()) { operation_log last_op = op_log.back(); op_log.pop_back();
// Revert the last operation if (last_op.type == 2 || last_op.type == 3) { int id = (last_op.type == 2) ? last_op.arg1 : last_op.arg2; int pa = find(id);
// Restore old state if (last_op.old_state.val > 0) { del[id] = false; node restored = last_op.old_state;7 行未改动 cout << "Undo of merge operation logged\n"; } } }
void handle_query(int A) { int pa = find(A); if (!heaps[pa-1].empty()) { node top_node = heaps[pa-1].top(); cout << "Query result: " << top_node.val << " (from node " << top_node.id << ")\n"; } else { cout << "Query result: Heap is empty\n"; } }
void handle_statistics() { unordered_map<int, int> heap_sizes; unordered_map<int, int> heap_modifications;
for (int i = 1; i <= n; i++) { int root = find(i); heap_sizes[root]++; heap_modifications[root] += heaps[root-1].modification_count; }
cout << "Statistics:\n"; cout << "Total heaps: " << heap_sizes.size() << endl; cout << "Total operations: " << op_log.size() << endl;
int max_heap = 0, max_heap_id = 0; for (const auto& [id, size] : heap_sizes) { if (size > max_heap) { max_heap = size; max_heap_id = id; } }
if (max_heap_id > 0) { cout << "Largest heap ID: " << max_heap_id << " (size: " << max_heap cout << "Largest heap ID: " << max_heap_id << " (size: " << max_heap << ", modifications: " << heap_modifications[max_heap_id] << ")\n"; } }
void output_results() { int tot = 0; vector<int> mx; vector<bool> vis(n + 1, false);
// Calculate results with advanced statistics vector<pair<int, int>> heap_maxima;
for (int i = 1; i <= n; i++) { int rt = find(i); if (!vis[rt]) { vis[rt] = true;6 行未改动 } } } }
// Apply W-based modifications with additional checks if (W == 2 && !mx.empty()) { int me = *max_element(mx.begin(), mx.end()); tot -= me;
// Log the adjustment cout << "W=2 adjustment: removed max value " << me << endl; } else if (W == 3 && !mx.empty()) { int me = *max_element(mx.begin(), mx.end()); tot += me;
// Log the adjustment cout << "W=3 adjustment: added max value " << me << endl; }
// Output final result with classification if (tot == 0) { cout << "Gensokyo "; } else if (tot > K) { cout << "Hell "; } else { cout << "Heaven "; }
cout << tot << "\n";
// Additional debug information if needed if (W > 1) { cout << "Heap maxima: "; for (const auto& [id, val] : heap_maxima) { cout << "(" << id << ":" << val << ") "; } cout << endl; } }
void cleanup() { for (int i = 1; i <= n; i++) { if (fa[i] == i) { while (!heaps[i-1].main_heap.empty()) {3 行未改动 heaps[i-1].backup_heap.pop(); } } }
// Clear all containers a.clear(); fa.clear(); del.clear();6 行未改动signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
GensokyoSolver solver; solver.solve();
return 0;}```
::::
### 47粉:[yjh20130105](https://www.luogu.com.cn/user/2020339)
[[JLOI2015] 城池攻占](https://www.luogu.com.cn/problem/P3261)
::::info[]```cpp#include <bits/stdc++.h>using namespace std;
// 超级复杂化版本 - 左偏树骑士远征问题// 增加了大量无关但有趣的特性
// 使用宏定义实现各种奇技淫巧#define int long long#define _CRT_SECURE_NO_WARNINGS#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)#define ROF(i, a, b) for(int i = (a); i >= (b); --i)#define ALL(x) (x).begin(), (x).end()#define SZ(x) ((int)(x).size())#define VI vector<int>#define VPII vector<pair<int, int>>#define PB push_back#define MP make_pair#define F first#define S second#define endl '\n'#define __builtin_popcountll __popcnt64
// 命名空间嵌套namespace Global { namespace Constants { const int N = 300005; const int INF = 1e18; const int MOD = 1e9 + 7; const double PI = acos(-1.0);
template<typename T> T max3(T a, T b, T c) { return max({a, b, c}); }
template<typename T> T min3(T a, T b, T c) { return min({a, b, c}); } }}
using namespace Global::Constants;
// 复杂化的节点结构struct node{ // 基础属性 int id, val, dis; int ls, rs; int add, mul;
// 扩展属性 int height; // 树高 int size; // 子树大小 int sum; // 子树和 int max_val, min_val; // 最大值最小值 int lazy_xor; // 异或懒标记 bool rev; // 翻转标记
// 构造函数 node() : id(0), val(0), dis(0), ls(0), rs(0), add(0), mul(1), height(0), size(0), sum(0), max_val(0), min_val(0), lazy_xor(0), rev(false) {}
// 带参构造函数 node(int _id, int _val) : id(_id), val(_val), dis(1), ls(0), rs(0), add(0), mul(1), height(1), size(1), sum(_val), max_val(_val), min_val(_val), lazy_xor(0), rev(false) {}};
// 全局变量,使用命名空间封装namespace Data { node tr[N * 2]; // 扩大数组 int n, m; int h[N], fa[N], a[N], v[N], s[N], c[N]; int dead[N], dep[N], diedep[N]; int root[N]; vector<int> e[N];
// 额外数据结构 set<int> alive_knights[N]; // 每个城池存活的骑士 map<int, int> knight_power; // 骑士力量映射 queue<int> bfs_queue; // BFS队列 stack<int> dfs_stack; // DFS栈 priority_queue<pair<int, int>> pq; // 优先队列
// 统计信息 int total_operations = 0; int merge_count = 0; int pushdown_count = 0;}
using namespace Data;
// 工具函数命名空间namespace Utils { // 随机数生成器 random_device rd; mt19937 gen(rd()); uniform_int_distribution<int> dis(1, 1000000);
int random() { return dis(gen); }
// 哈希函数 struct Hash { size_t operator()(const pair<int, int>& p) const { return p.first * 131 + p.second; } };
// 计时器类 class Timer { private: chrono::high_resolution_clock::time_point start_time; public: Timer() { reset(); } void reset() { start_time = chrono::high_resolution_clock::now(); } double elapsed() { auto end = chrono::high_resolution_clock::now(); return chrono::duration<double>(end - start_time).count(); } };
// 调试输出(仅在DEBUG模式下) #ifdef DEBUG #define debug(x) cerr << #x << " = " << x << endl #else #define debug(x) #endif}
// 节点操作函数int newnode(int id, int val) { static int cnt = 0; cnt++; tr[cnt] = node(id, val); debug(cnt << " " << id << " " << val); return cnt;}
// 复杂化的pushdownvoid pushdown(int u) { if(u == 0) { return; } pushdown_count++;
// 处理基础懒标记 if(tr[u].ls) { // 乘法标记 tr[tr[u].ls].val = tr[tr[u].ls].val * tr[u].mul + tr[u].add; tr[tr[u].ls].add = tr[tr[u].ls].add * tr[u].mul + tr[u].add; tr[tr[u].ls].mul *= tr[u].mul;
// 更新统计信息 tr[tr[u].ls].sum = tr[tr[u].ls].sum * tr[u].mul + tr[u].add * tr[tr[u].ls].size; tr[tr[u].ls].max_val = tr[tr[u].ls].max_val * tr[u].mul + tr[u].add; tr[tr[u].ls].min_val = tr[tr[u].ls].min_val * tr[u].mul + tr[u].add; }
if(tr[u].rs) { tr[tr[u].rs].val = tr[tr[u].rs].val * tr[u].mul + tr[u].add; tr[tr[u].rs].add = tr[tr[u].rs].add * tr[u].mul + tr[u].add; tr[tr[u].rs].mul *= tr[u].mul;
tr[tr[u].rs].sum = tr[tr[u].rs].sum * tr[u].mul + tr[u].add * tr[tr[u].rs].size; tr[tr[u].rs].max_val = tr[tr[u].rs].max_val * tr[u].mul + tr[u].add; tr[tr[u].rs].min_val = tr[tr[u].rs].min_val * tr[u].mul + tr[u].add; }
// 处理异或懒标记 if(tr[u].lazy_xor != 0) { if(tr[u].ls) { tr[tr[u].ls].val ^= tr[u].lazy_xor; tr[tr[u].ls].lazy_xor ^= tr[u].lazy_xor; } if(tr[u].rs) { tr[tr[u].rs].val ^= tr[u].lazy_xor; tr[tr[u].rs].lazy_xor ^= tr[u].lazy_xor; } tr[u].lazy_xor = 0; }
// 处理翻转标记 if(tr[u].rev) { if(tr[u].ls) { tr[tr[u].ls].rev ^= 1; swap(tr[tr[u].ls].ls, tr[tr[u].ls].rs); } if(tr[u].rs) { tr[tr[u].rs].rev ^= 1; swap(tr[tr[u].rs].ls, tr[tr[u].rs].rs); } tr[u].rev = false; }
tr[u].add = 0; tr[u].mul = 1;}
// 更新节点信息void update(int u) { if(u == 0) return;
tr[u].size = 1; tr[u].sum = tr[u].val; tr[u].max_val = tr[u].val; tr[u].min_val = tr[u].val; tr[u].height = 1;
if(tr[u].ls) { tr[u].size += tr[tr[u].ls].size; tr[u].sum += tr[tr[u].ls].sum; tr[u].max_val = max(tr[u].max_val, tr[tr[u].ls].max_val); tr[u].min_val = min(tr[u].min_val, tr[tr[u].ls].min_val); tr[u].height = max(tr[u].height, tr[tr[u].ls].height + 1); }
if(tr[u].rs) { tr[u].size += tr[tr[u].rs].size; tr[u].sum += tr[tr[u].rs].sum; tr[u].max_val = max(tr[u].max_val, tr[tr[u].rs].max_val); tr[u].min_val = min(tr[u].min_val, tr[tr[u].rs].min_val); tr[u].height = max(tr[u].height, tr[tr[u].rs].height + 1); }}
// 复杂化的合并操作int merge(int x, int y) { if(x == 0 || y == 0) { return x + y; }
merge_count++; total_operations++;
pushdown(x); pushdown(y);
// 根据多种条件决定合并顺序 if(tr[x].val > tr[y].val) { swap(x, y); } else if(tr[x].val == tr[y].val) { // 如果值相等,根据id和随机数决定 if(tr[x].id > tr[y].id || (tr[x].id == tr[y].id && Utils::random() % 2)) { swap(x, y); } }
// 随机决定合并到左边还是右边 if(Utils::random() % 2) { tr[x].ls = merge(tr[x].ls, y); if(tr[tr[x].ls].dis < tr[tr[x].rs].dis) { swap(tr[x].ls, tr[x].rs); } } else { tr[x].rs = merge(tr[x].rs, y); if(tr[tr[x].ls].dis < tr[tr[x].rs].dis) { swap(tr[x].ls, tr[x].rs); } }
tr[x].dis = min(tr[tr[x].ls].dis, tr[tr[x].rs].dis) + 1; update(x);
return x;}
// 深度优先搜索(递归版)void dfsdep(int u, int d) { dep[u] = d; for(auto v : e[u]) { dfsdep(v, d + 1); }}
// 复杂化的DFS(使用栈实现)void dfs(int u) { dfs_stack.push(u);
while(!dfs_stack.empty()) { int cur = dfs_stack.top(); dfs_stack.pop();
// 处理子节点 for(auto v : e[cur]) { dfs_stack.push(v); // 合并骑士 root[cur] = merge(root[cur], root[v]); }
// 处理当前节点的骑士 while(root[cur] != 0) { pushdown(root[cur]);
if(tr[root[cur]].val < h[cur]) { dead[cur]++; diedep[tr[root[cur]].id] = dep[cur]; alive_knights[cur].erase(tr[root[cur]].id); root[cur] = merge(tr[root[cur]].ls, tr[root[cur]].rs); } else { break; } }
// 应用城池效果 if(cur != 1 && root[cur] != 0) { if(a[cur] == 0) { // 加法 tr[root[cur]].val += v[cur]; tr[root[cur]].add += v[cur]; tr[root[cur]].sum += v[cur] * tr[root[cur]].size; tr[root[cur]].max_val += v[cur]; tr[root[cur]].min_val += v[cur]; } else { // 乘法 tr[root[cur]].val *= v[cur]; tr[root[cur]].add *= v[cur]; tr[root[cur]].mul *= v[cur]; tr[root[cur]].sum *= v[cur]; tr[root[cur]].max_val *= v[cur]; tr[root[cur]].min_val *= v[cur]; }
// 随机应用一些额外效果 if(Utils::random() % 100 < 5) { // 5%的概率应用异或 int x = Utils::random() % 100; tr[root[cur]].val ^= x; tr[root[cur]].lazy_xor ^= x; }
if(Utils::random() % 100 < 3) { // 3%的概率翻转 tr[root[cur]].rev ^= 1; swap(tr[root[cur]].ls, tr[root[cur]].rs); } }
// 更新统计信息 update(root[cur]); }}
// BFS实现(备用)void bfs(int start) { bfs_queue.push(start);
while(!bfs_queue.empty()) { int u = bfs_queue.front(); bfs_queue.pop();
for(auto v : e[u]) { bfs_queue.push(v); } }}
// 输出统计信息void printStatistics() { cout << "\n=== Statistics ===\n"; cout << "Total operations: " << total_operations << endl; cout << "Merge count: " << merge_count << endl; cout << "Pushdown count: " << pushdown_count << endl; cout << "Memory usage: " << sizeof(tr) / 1024 / 1024 << " MB\n"; cout << "==================\n";}
// 复杂化的主函数signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// 使用计时器 Utils::Timer timer;
// 输入优化 auto read = []() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; };
n = read(); m = read();
FOR(i, 1, n) { h[i] = read(); }
FOR(i, 2, n) { fa[i] = read(); a[i] = read(); v[i] = read(); e[fa[i]].push_back(i); }
dfsdep(1, 1);
FOR(i, 1, m) { s[i] = read(); c[i] = read(); int id = newnode(i, s[i]); root[c[i]] = merge(root[c[i]], id); alive_knights[c[i]].insert(i); knight_power[i] = s[i]; }
// 执行主DFS dfs(1);
// 输出结果 FOR(i, 1, n) { cout << dead[i] << endl; }
FOR(i, 1, m) { cout << dep[c[i]] - diedep[i] << endl; }
// 输出统计信息(可选) if(n > 1000) { printStatistics(); }
debug("Time elapsed: " << timer.elapsed() << "s");
return 0;}
// 额外的未使用函数,增加代码量namespace Unused { // 快速幂 int qpow(int a, int b, int mod = MOD) { int res = 1; while(b) { if(b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; }
// 欧拉函数 int phi(int n) { int res = n; for(int i = 2; i * i <= n; i++) { if(n % i == 0) { res = res / i * (i - 1); while(n % i == 0) n /= i; } } if(n > 1) res = res / n * (n - 1); return res; }
// 扩展欧几里得 int exgcd(int a, int b, int &x, int &y) { if(b == 0) { x = 1; y = 0; return a; } int g = exgcd(b, a % b, y, x); y -= a / b * x; return g; }
// 线段树模板(未使用) class SegmentTree { private: vector<int> tree, lazy; int n; public: SegmentTree(int _n) : n(_n) { tree.resize(4 * n); lazy.resize(4 * n); }
void pushdown(int p) { if(lazy[p]) { tree[p * 2] += lazy[p]; tree[p * 2 + 1] += lazy[p]; lazy[p * 2] += lazy[p]; lazy[p * 2 + 1] += lazy[p]; lazy[p] = 0; } }
void update(int p, int l, int r, int ql, int qr, int val) { if(ql <= l && r <= qr) { tree[p] += val; lazy[p] += val; return; } pushdown(p); int mid = (l + r) >> 1; if(ql <= mid) update(p * 2, l, mid, ql, qr, val); if(qr > mid) update(p * 2 + 1, mid + 1, r, ql, qr, val); tree[p] = max(tree[p * 2], tree[p * 2 + 1]); }
int query(int p, int l, int r, int ql, int qr) { if(ql <= l && r <= qr) return tree[p]; pushdown(p); int mid = (l + r) >> 1, res = -INF; if(ql <= mid) res = max(res, query(p * 2, l, mid, ql, qr)); if(qr > mid) res = max(res, query(p * 2 + 1, mid + 1, r, ql, qr)); return res; } };> }``````::::
### 48粉:[LoyalSoldier](https://www.luogu.com.cn/user/937774)
[ [JSOI2014] 学生选课](https://www.luogu.com.cn/problem/P4835)
::::info[]```pythonprint(int(input())-2)`````:::::
### 49粉:[ChargedCharge](https://www.luogu.com.cn/user/1051385)
[「ROI 2025 Day2」沼泽里的青蛙](https://www.luogu.com.cn/problem/P12506)
::::info[]```cpp#include <bits/stdc++.h>using namespace std;
#define int long long#define fi first#define se second
const int N=100005;
int n,r;int x[N],y[N],fa[N<<1];map<pair<int,int>,vector<int>> mp;
int getdis(int i,int j){ int xi=x[i],xj=x[j],yi=y[i],yj=y[j]; return (xi-xj)*(xi-xj)+(yi-yj)*(yi-yj)<=r*r;}
int find(int x){ if(x==fa[x]) { return x; } return fa[x]=find(fa[x]);}
void merge(int x,int y){ fa[find(x)]=find(y+n); fa[find(y)]=find(x+n);}
signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>r; for(int i=1;i<=n;i++) { cin>>x[i]>>y[i]; mp[{2*x[i]/r,2*y[i]/r}].push_back(i); } for(int i=1;i<=2*n;i++) { fa[i]=i; } for(auto it:mp) { vector<int> v=it.se; int sz=v.size(); for(int i=1;i<sz;i++) { merge(v[i-1],v[i]); } if(sz>=3) { merge(v[0],v[2]); } if(sz<3) { for(int dx=-2;dx<=2;dx++) { for(int dy=-2;dy<=2;dy++) { if(dx==0 and dy==0) { continue; } auto key=make_pair(it.fi.fi+dx,it.fi.se+dy); auto pos=mp.find(key); if(pos!=mp.end()) { for(auto p:v) { for(auto q:pos->se) { if(getdis(p,q)) { merge(p,q); } } } } } }ava } } for(int i=1;i<=n;i++) { cout<<(char)('0'+(find(i)==find(i+n))); } cout<<"\n"; return 0;}```````::::