From 375a6355002272f50e96cbfc30b10b48e687ac8a Mon Sep 17 00:00:00 2001 From: wisdompeak Date: 2025年8月19日 00:40:35 -0700 Subject: [PATCH 1/2] Create 3655.XOR-After-Range-Multiplication-Queries-II.cpp --- ...-After-Range-Multiplication-Queries-II.cpp | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Others/3655.XOR-After-Range-Multiplication-Queries-II/3655.XOR-After-Range-Multiplication-Queries-II.cpp diff --git a/Others/3655.XOR-After-Range-Multiplication-Queries-II/3655.XOR-After-Range-Multiplication-Queries-II.cpp b/Others/3655.XOR-After-Range-Multiplication-Queries-II/3655.XOR-After-Range-Multiplication-Queries-II.cpp new file mode 100644 index 000000000..7fe8adba3 --- /dev/null +++ b/Others/3655.XOR-After-Range-Multiplication-Queries-II/3655.XOR-After-Range-Multiplication-Queries-II.cpp @@ -0,0 +1,65 @@ +using ll = long long; +class Solution { + int MOD = 1e9+7; +public: + long long power(long long base, long long exp) { + long long res = 1; + const int MOD = 1e9 + 7; + base %= MOD; + while (exp> 0) { + if (exp % 2 == 1) res = (res * base) % MOD; + base = (base * base) % MOD; + exp /= 2; + } + return res; + } + + long long modInverse(long long n) { + const int MOD = 1e9 + 7; + return power(n, MOD - 2); + } + + int xorAfterQueries(vector& nums, vector>& queries) { + int n = nums.size(); + const int B = 400; + + vectormultipliers(n,1); + + vector>small_k_queries[B+1]; + + for (auto q: queries) { + int l = q[0], r = q[1], k = q[2], v = q[3]; + if (k>B) { + for (int i=l; i<=r; i+=k) + multipliers[i] = (multipliers[i]*v) % MOD; + } else { + small_k_queries[k].push_back(q); + } + } + + for (int k=1; k<=b; k++) { + if (small_k_queries[k].empty()) + continue; + vectordiff(n+1,1); + for (auto& q: small_k_queries[k]) { + int l = q[0], r = q[1], v = q[3]; + r = (r-l)/k*k+l; + diff[l] = (diff[l]*v)%MOD; + if (r+k Date: 2025年8月19日 00:41:10 -0700 Subject: [PATCH 2/2] Update Readme.md --- Readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Readme.md b/Readme.md index 71c0a6d6c..7934d93db 100644 --- a/Readme.md +++ b/Readme.md @@ -1648,6 +1648,7 @@ [2963.Count-the-Number-of-Good-Partitions](https://github.com/wisdompeak/LeetCode/tree/master/Others/2963.Count-the-Number-of-Good-Partitions) (H-) [3009.Maximum-Number-of-Intersections-on-the-Chart](https://github.com/wisdompeak/LeetCode/tree/master/Others/3009.Maximum-Number-of-Intersections-on-the-Chart) (H) [3169.Count-Days-Without-Meetings](https://github.com/wisdompeak/LeetCode/tree/master/Others/3169.Count-Days-Without-Meetings) (M) +[3655.XOR-After-Range-Multiplication-Queries-II](https://github.com/wisdompeak/LeetCode/tree/master/Others/3655.XOR-After-Range-Multiplication-Queries-II) (H+) * ``二维差分`` [850.Rectangle-Area-II](https://github.com/wisdompeak/LeetCode/tree/master/Others/850.Rectangle-Area-II) (H) [2132.Stamping-the-Grid](https://github.com/wisdompeak/LeetCode/tree/master/Others/2132.Stamping-the-Grid) (H)

AltStyle によって変換されたページ (->オリジナル) /