-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from kmyk/cumulative-sum
Use cumulative sums
- Loading branch information
Showing
22 changed files
with
531 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env python3 | ||
from typing import * | ||
|
||
def solve(n: int, a: List[int]) -> List[int]: | ||
l = [-1] * (n + 1) | ||
r = [-1] * (n + 1) | ||
for i in range(n): | ||
l[i + 1] = max(l[i], a[i]) | ||
for i in reversed(range(n)): | ||
r[i] = max(r[i + 1], a[i]) | ||
ans = [-1] * n | ||
for i in range(n): | ||
ans[i] = max(l[i], r[i + 1]) | ||
return ans | ||
|
||
def main() -> None: | ||
n = int(input()) | ||
_, *a = map(int, input().split()) | ||
ans = solve(n, a) | ||
print(len(ans), *ans) | ||
|
||
if __name__ == '__main__': | ||
main() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env python3 | ||
import random | ||
|
||
def main() -> None: | ||
n = random.randint(1, 5 * 10 ** 5) | ||
q = random.randint(1, 5 * 10 ** 5) | ||
a = [random.randint(1, 10 ** 9) for _ in range(n)] | ||
l = [random.randint(0, n - 1) for _ in range(q)] | ||
r = [random.randint(l[i] + 1, n) for i in range(q)] | ||
print(n) | ||
print(q) | ||
print(len(a), *a) | ||
print(len(l), *l) | ||
print(len(r), *r) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import * | ||
|
||
def solve(n: int, q: int, a: List[int], l: List[int], r: List[int]) -> List[int]: | ||
b = [0] * (n + 1) | ||
for i in range(n): | ||
b[i + 1] = b[i] + a[i] | ||
ans = [-1] * q | ||
for j in range(q): | ||
ans[j] = b[r[j]] - b[l[j]] | ||
return ans | ||
|
||
def main() -> None: | ||
n = int(input()) | ||
q = int(input()) | ||
_, *a = map(int, input().split()) | ||
_, *l = map(int, input().split()) | ||
_, *r = map(int, input().split()) | ||
ans = solve(n, q, a, l, r) | ||
print(len(ans), *ans, sep='\n') | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.