프로그램 명: coci_inspektor
제한시간: 4 초
A new town was just inaugurated in a small country. As usual, Mirko has secured the position of the chief tax inspector. His duty is ensuring adequate accounting in all the different companies in the town.
There are N business offices along the main street, numbered 1 to N from left to right. All offices are empty in the beginning; in time, companies will move in and out of these offices. From time to time, Mirko will pass by some of the offices and inspect the accounting of only one company, the currently wealthiest one in those offices.
A company moving in is described by four integers:
- T - the move-in day, numbered from town inauguration (which is day 1),
- K - the office number,
- Z - the daily profit of the company (can be negative if the company is losing money),
- S - balance of the company's account on move-in day.
If there is already a company in office K, that company moves out when the new company moves in. The new company doesn't open for business (or earn profit) until the day after move-in.
Mirko's inspection stroll is described by three integers:
- T - the inspection day, numbered from town inauguration,
- A and B - Mirko will pass by all offices with numbers between A and B, inclusive.
Since Mirko works only at the end of the day, all companies will have already finished business and posted profit for the day by the time of Mirko's stroll.
Help Mirko by writing a program to find, for each stroll, the account balance of the currently wealthiest company that Mirko is passing by.
입력
The first line of input contains two positive integers, N (1 <= N <= 100 000) and M (1 <= M <= 300 000), the number of offices and events, respectively.
Each of the following M lines contains a description of one event, formatted either as ¨1 T K Z S〃 (for company move-in) or as ¨2 T A B〃 (for Mirko's inspection stroll).
All events are given chronologically, and at most one event will happen each day (that is, T will be strictly increasing). The last event's day number will be less than 10^6, and all Z and S numbers' absolute values will be less than 10^6.
출력
For each Mirko's stroll output a line containing the account balance of the company that Mirko will inspect, or the word “nema” (without quotes) if all offices that he will pass by are empty.
입출력 예
input
2 4
1 1 1 2 4
1 2 2 3 2
2 5 1 2
2 7 1 2
output
12
17
input
3 6 1 1 1 4 -2
1 2 2 2 6
2 3 3 1
2 4 3 1
1 5 3 -6 20
2 6 2 3
output
8
10
14
input
5 9
1 1 5 4 -5
2 2 3 5
1 3 4 6 9
2 4 1 2
1 6 2 2 3
2 8 2 1
1 9 4 0 17
2 10 5 5
2 11 1 4
output
-1
nema
7
31
17
출처:coci/2012-2013/contest2 6/6
[질/답]
[제출 현황]
[푼 후(0)]