Skip to content

Commit c84c8d2

Browse files
authored
Update and rename Others/6077.Sum-of-Total-Strength-of-Wizards/6077.Sum-of-Total-Strength-of-Wizards.cpp to Others/2281.Sum-of-Total-Strength-of-Wizards/2281.Sum-of-Total-Strength-of-Wizards.cpp
1 parent 668082c commit c84c8d2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Others/6077.Sum-of-Total-Strength-of-Wizards/6077.Sum-of-Total-Strength-of-Wizards.cpp renamed to Others/2281.Sum-of-Total-Strength-of-Wizards/2281.Sum-of-Total-Strength-of-Wizards.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class Solution {
1111
for (int i=1; i<=n; i++)
1212
presum[i] = (presum[i-1]+(LL)nums[i]) % M;
1313

14-
vector<LL>presum1(n+2, 0);
14+
vector<LL>presum2(n+2, 0);
1515
for (int i=1; i<=n; i++)
16-
presum1[i] = (presum1[i-1]+(LL)nums[i]*i) % M;
16+
presum2[i] = (presum2[i-1]+(LL)nums[i]*i) % M;
1717

1818
stack<int>Stack;
1919
vector<int>nextSmaller(n+2,n+1);
@@ -35,9 +35,9 @@ class Solution {
3535
{
3636
LL a = prevSmaller[i], b = nextSmaller[i];
3737
LL x = i-a, y = b-i;
38-
LL first = ((presum1[i-1] - presum1[a]) - (presum[i-1] - presum[a]) * a %M + M) % M;
38+
LL first = ((presum2[i-1] - presum2[a]) - (presum[i-1] - presum[a]) * a %M + M) % M;
3939
first = first * y % M;
40-
LL second = ((presum[b-1] - presum[i]) * (b-1+1) - (presum1[b-1] - presum1[i]) + M ) % M;
40+
LL second = ((presum[b-1] - presum[i]) * (b-1+1) - (presum2[b-1] - presum2[i]) + M ) % M;
4141
second = second * x % M;
4242
LL mid = (LL)nums[i] * x * y % M;
4343

0 commit comments

Comments
 (0)