Editorial for Clue Contest 05 - Tăng đoạn
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Authors: ,
Nhận xét: Đề chỉ hỏi tổng của dãy số, vì vậy ta không cần dựng mảng, chỉ cần có một biến kết quả lưu tổng của dãy hiện tại.
Với mỗi truy vấn, kết quả được tăng lên ~x \times z~, với ~z~ là tổng các số từ ~1~ đến ~r - l + 1~.
Độ phức tạp: ~O~ (~q~).
Code mẫu:
import sys import math def main(): n, q = map(int, input().split()) mod = 20032024 total = 0 for _ in range(q): l, r, x = map(int, input().split()) m = r - l + 1 total += x * m * (m + 1) // 2 total %= mod print(total) if __name__ == "__main__": main()
Comments