Nộp bài | Các bài nộp | Làm tốt nhất | Về danh sách bài |
PLACE - PLACE |
Mirko loves cars and he finally managed to start his own car factory! Factory has N employees, each of them has exactly one superior (except Mirko - he is by default everybody's superior). Mirko is denoted by number 1, and the rest of the employees with numbers 2 to N.
Every employee can raise or lower the wages of all of his subordinates (both direct subordinates and those lower in the hieararchy tree). Mirko‟s role is to prevent abuse of such power, so from time to time he wants to know wage of a particular employee.
He is asking you to write a program which will help him monitor wage changes, given a sequence of commands described in the input section.
Remark: at any time, all of the wages will be positive integers and will fit in standard 32-bit integer type (int in C/C++, longint in Pascal).
Input
First line of input contains two space-separated positive integers N (1 ≤ N ≤ 500 000), number of employees, and M (1 ≤ M ≤ 500 000), number of wage changes and wage queries.
Next N lines contain the information about employees 1, 2, ..., N (respectively): starting wage and the identifier of his direct supervisor. Remark: Mirko has no supervisor, so his line will contain only his starting wage.
Next M lines contain one of the following:
1. p A X - employee A increases (or decreases in case of a negative X) wage of all his subordinates by the amount X (-10 000 ≤ X ≤ 10 000);
2. u A - Mirko wants to know the wage of employee A.
Output
Output should contain one line for each '2' query in the input - the current wage of the given employee.
Example
Input:
6 7
5
4 1
3 2
7 3
2 3
3 5
p 3 2
p 2 4
u 3
u 6
p 5 -2
u 6
u 1
Output:
7
9
7
5
Được gửi lên bởi: | Alex & Friends |
Ngày: | 2012-01-05 |
Thời gian chạy: | 0.800s |
Giới hạn mã nguồn: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Ngôn ngữ cho phép: | Tất cả ngoại trừ: ADA95 ASM32 ASM64 GAWK BASH BF C99 CLPS CLOJURE LISP sbcl LISP clisp D ERL FSHARP FORTRAN GO GOSU HASK ICON ICK JS-RHINO NEM NICE OCAML PERL6 PIKE PRLG-swi PYTHON PYPY PYTHON3 RUST SCALA SCM guile SCM qobi SED ST TCL WHITESPACE |
Nguồn bài: | COCI 2011-2012 - Contest 3 |
hide comments
2017-10-09 10:24:44
{dinh truong lam} code mấy trăm dòng xong mới biết có thể giải = bit :( |
|
2017-10-09 10:17:50
{dinh truong lam} đúng như bác love vnoi nói, nhưng em chỉ cần thêm ios_base vào là full ^^0 |
|
2015-09-05 15:22:49
Tham khảo lời giải tại http://vnspoj.blogspot.com/p/blog-page_7.html |
|
2014-08-25 20:50:49 LOVE VNOI
tối ưu đến cả cách đọc dữ liệu :3. Time bài này chặt thật |
|
2012-12-07 09:42:57 treesseven
PS xem giúp em em bị WA hay là TLE ạ :(. nk spoj của em là treesseven |
|
2012-04-10 18:33:09 Noyethug
dễ TLE :( |