Counting In Byteland
Practice
2.6 (8 votes)
Data structures
Easy
Fenwick tree
Fenwick tree
Problem
47% Success 2602 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

For once, lets assume Byteland to be a 3 dimensional space of size N X N X N. The Lolympics Committee has decided that every contingent representing a country will stay in a hotel at a particular coordinate denoted by its x-axis, y-axis and z-axis. Now, the Players Welfare Association(PWA) has to answer some queries as well as give accommodation to the Lolympic players. There will be Q number of queries which can be of two types:-
1. 1 x y z val - A contingent consisting of val number of players have been alloted a hotel in the coordinate (x,y,z).
2. 2 x y z X Y Z- Calculate the total number of players who are not residing in the coordinates ranging from (x <= xi <= X, y <= yi <= Y, z <= zi <= Z)

Constraints:
1 <= N <= 102
1 <= Q <= 105
0 <= x,y,z <= X,Y,Z <= N
1 <= val <= 109

Input:
The first line consists of two numbers N and Q.
Next Q lines consists of queries of the two forms mentioned above.

Output:
Print the answer for query 2 in a single line.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
4 votes
Tags:
Data StructuresEasyFenwick tree
Points:30
463 votes
Tags:
Ad-HocApprovedBit ManipulationData StructuresEasyFenwick treeSorting
Points:30
50 votes
Tags:
ApprovedData StructuresEasyOpenSegment TreesTrees