#P2294. [HNOI2005] 狡猾的商人

    ID: 1264 远端评测题 1000ms 512MiB 尝试: 5 已通过: 1 难度: 6 上传者: 标签>2005并查集各省省选湖南差分约束前缀和

[HNOI2005] 狡猾的商人

Description

Diao Cha receives a task from the tax authority to investigate a merchant’s ledger and determine whether it is forged. The ledger records the income over nn months, where the income in month ii is aia_i, i=1,2,,n1,ni=1,2,\ldots,n-1,n. When ai>0a_i>0, it means the profit in that month is aia_i yuan; when ai<0a_i<0, it means the loss in that month is ai|a_i| yuan. The total income over a period is the sum of the monthly incomes within that period.

Her task is carried out in secret. To investigate the ledger, she goes to work for the merchant. When the merchant is away, she peeks at the ledger, but she cannot take it out. Each time she peeks, she can only look at the income recorded for some continuous period, and she can remember only the total income over that period.

Now, she has peeked at the ledger mm times and thus remembered the total incomes over mm periods. Your task is to determine, based on these remembered totals, whether the ledger is fake.

Input Format

The first line contains a positive integer ww, where w<100w<100, indicating that there are ww test cases (that is, ww ledgers) to judge.

For each test case, the first line contains two positive integers nn and mm, where n<100,m<1000n<100, m<1000, indicating how many months of income the ledger records and how many times she peeked at the ledger.

The next mm lines describe the mm pieces of information Diao Cha remembered after mm peeks. Each line contains three integers ss, tt and vv, meaning that the total income from month ss to month tt (including month tt) is vv. Here, assume ss is always less than or equal to tt.

Output Format

Output ww lines, each containing true or false. The ii-th line is true if and only if the ii-th test case, i.e., the ii-th ledger, is not fake; the ii-th line is false if and only if the ii-th test case, i.e., the ii-th ledger, is fake.

2
3 3
1 2 10
1 3 -5
3 3 -15
5 3
1 5 100
3 5 50
1 2 51

true
false

Hint

Translated by ChatGPT 5