payraiseProblem DescriptionA company has N employees, numbered 0 to N-1. The boss of the company is employee 0, while every other employee i has a direct superior Pi. Since employee 0 has no direct superior, P0 = -1. Each employee i starts with an initial salary of Si dollars.There will be a total of Q operations that you have to handle, each of them being one of two types:A raise operation, where we raise the salaries of employee x and all of their direct and indirect subordinates by d dollars.A query operation, where we want to know the current salary of employee x.InputThe first line of input will contain two integers, N and Q.The next line of input will contain N integers, indicating the array P.The next line of input will contain N integers, indicating the array S.The next Q lines of input will describe one operation each, in the following formats:0 x d, indicating a raise operation on employee x (and their subordinates) by d dollars.1 x, indicating a query operation on employee x.OutputThe output should contain one line with one integer for each query operation, indicating the current salary of the requested employee.Limits1 ≤ N, Q ≤ 106.0 ≤ Pi < i, for all 1 ≤ i < N.0 ≤ x < N0 ≤ d, Si ≤ 109.Sample Input5 5-1 0 0 1 11 3 2 3 20 1 31 40 0 21 11 3Sample Output588
Question
payraiseProblem DescriptionA company has N employees, numbered 0 to N-1. The boss of the company is employee 0, while every other employee i has a direct superior Pi. Since employee 0 has no direct superior, P0 = -1. Each employee i starts with an initial salary of Si dollars.There will be a total of Q operations that you have to handle, each of them being one of two types:A raise operation, where we raise the salaries of employee x and all of their direct and indirect subordinates by d dollars.A query operation, where we want to know the current salary of employee x.InputThe first line of input will contain two integers, N and Q.The next line of input will contain N integers, indicating the array P.The next line of input will contain N integers, indicating the array S.The next Q lines of input will describe one operation each, in the following formats:0 x d, indicating a raise operation on employee x (and their subordinates) by d dollars.1 x, indicating a query operation on employee x.OutputThe output should contain one line with one integer for each query operation, indicating the current salary of the requested employee.Limits1 ≤ N, Q ≤ 106.0 ≤ Pi < i, for all 1 ≤ i < N.0 ≤ x < N0 ≤ d, Si ≤ 109.Sample Input5 5-1 0 0 1 11 3 2 3 20 1 31 40 0 21 11 3Sample Output588
Solution
The problem is asking to implement a system that can handle two types of operations for a company with N employees.
The employees are numbered from 0 to N-1, with employee 0 being the boss. Each employee i has a direct superior Pi, except for the boss whose Pi is -1. Each employee i also has an initial salary of Si dollars.
The system needs to handle Q operations, which can be of two types:
-
A raise operation: This operation increases the salary of an employee x and all of their direct and indirect subordinates by d dollars. This operation is represented as "0 x d" in the input.
-
A query operation: This operation returns the current salary of an employee x. This operation is represented as "1 x" in the input.
The input will first provide two integers, N and Q, representing the number of employees and the number of operations respectively.
The next line will provide N integers, representing the array P, where Pi is the direct superior of employee i.
The next line will provide N integers, representing the array S, where Si is the initial salary of employee i.
The next Q lines will describe one operation each, either a raise operation or a query operation.
The output should contain one line with one integer for each query operation, indicating the current salary of the requested employee.
The constraints are as follows:
- 1 ≤ N, Q ≤ 106.
- 0 ≤ Pi < i, for all 1 ≤ i < N.
- 0 ≤ x < N
- 0 ≤ d, Si ≤ 109.
The sample input and output provided demonstrate how the input and output should be formatted.
Similar Questions
For given relation:Employee(eid, ename, address,deptname ,salary)Project(eid, pid, pname, location)(1) Display name and salary of employee who is taking maximum salary.(2) Display highest salary department wise and name of employee who is taking thatsalary.(3) Find details of employee who works on a pid equal to 10
Which of the below queries displays employees' name and new salary after the increment of 1000
Write a query to display the ename of employee who draw the highest salary. In case of multiple records, display the records sorted in ascending order based on ename.
we have following relationsEMP(empno, ename, jobtitle, manager, hiredate, salary, deptno)DEPT(deptno, dname,location)Answer the following queries .1) Find the Employees who get salary more than Chris salary.2) Display department number along with the number of employees which belongs to thatdepartment number
Create PL/pgSQL procedure for the increment of employees where in salary less than 35000 will get hike of 15% in their previoussalary and other will get 10% hike in their previous salary. Using following schema, Employees (id, name, department, salary)call the procedure by id and print employee’s name with their updated salary
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.