Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from wisdompeak:master #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 2 commits into AlgorithmAndLeetCode:master from wisdompeak:master
Aug 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<int>& nums, vector<vector<int>>& queries) {
int n = nums.size();
const int B = 400;

vector<ll>multipliers(n,1);

vector<vector<int>>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;
vector<ll>diff(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<n+1) diff[r+k] = diff[r+k] * modInverse(v) % MOD;
}

for (int i=k; i<n; i++)
diff[i] = diff[i]*diff[i-k] % MOD;

for (int i=0; i<n; i++)
multipliers[i] = multipliers[i] * diff[i] % MOD;
}

int ret = 0;
for(int i=0; i<n; i++) {
ll val = (ll)nums[i]*multipliers[i]%MOD;
ret ^= (int)val;
}
return ret;
}
};
1 change: 1 addition & 0 deletions Readme.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

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