COCI '12 Contest 2 #6 Inspektor

View as PDF

Submit solution


Points: 25 (partial)
Time limit: 4.0s
Memory limit: 32M

Problem type

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.

Input Specification

The first line of input contains two positive integers, N (1 \leq N \leq 100\,000) and M (1 \leq M \leq 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.

Output Specification

For each one of Mirko's strolls output a line containing the account balance of the company that Mirko will inspect, or the word nema if all offices that he will pass by are empty.

Sample Input 1

2 4
1 1 1 2 4
1 2 2 3 2
2 5 1 2
2 7 1 2

Sample Output 1

12
17

Sample Input 2

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

Sample Output 2

8
10
14

Sample Input 3

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

Sample Output 3

-1
nema
7
31
17

Comments

There are no comments at the moment.