patterncppMinor
2D Fenwick-tree with combinatorics and modular arithmetic
Viewed 0 times
combinatoricswithfenwickmodularandtreearithmetic
Problem
This is a contest problem;
Description:
In the winter, children started to build snowmen. The snowmen were becoming adorable, except for a detail: none of them had a nose. The king, touched, decided to give some of his carrots away so they could be distributed in rectangular-shaped regions of the Town. But the children of the city are greedy and do not mind putting several noses on their snowmen, no matter if other children end up with no noses to put on their snowmen.
Input:
The input describes, in sequence, all events that happened during the winter and consists of at most 10^5 lines. The first line of the input consists of two integers: N and M (\$1 ≤ N\$, \$M ≤ 10^3\$), which represent the dimensions of the Town. Each one of the following lines describes an event, characterised by the number of integers present in the line:
Ouput:
For each day of the winter, ended in the input by a five integer line, print a line containing the number of the day and the number of possibilities for the distribution of the carrots among the snowmen at the delimited area. Consider that the counting of the days starts in 1. As the number of possibilities can be very large, print only the
Description:
In the winter, children started to build snowmen. The snowmen were becoming adorable, except for a detail: none of them had a nose. The king, touched, decided to give some of his carrots away so they could be distributed in rectangular-shaped regions of the Town. But the children of the city are greedy and do not mind putting several noses on their snowmen, no matter if other children end up with no noses to put on their snowmen.
Input:
The input describes, in sequence, all events that happened during the winter and consists of at most 10^5 lines. The first line of the input consists of two integers: N and M (\$1 ≤ N\$, \$M ≤ 10^3\$), which represent the dimensions of the Town. Each one of the following lines describes an event, characterised by the number of integers present in the line:
- If the line consists of three integers, X, Y and B (\$1 ≤ X ≤ N, 1 ≤ Y ≤ M\$, \$1 ≤ B ≤ 100\$), it means that a child has built B snowmen at the position in the Town of coordinates (X, Y);
- If the line consists of two integers, X and Y (\$1 ≤ X ≤ N, 1 ≤ Y ≤ M\$), it means that a child has destroyed all snowmen at the position of coordinates (X, Y);
- If the line consists of five integers, X1, Y1, X2, Y2 and C (\$1 ≤ X1 ≤ X2 ≤ N\$, \$1 ≤ Y1 ≤ Y2 ≤ M\$, \$1 ≤ C ≤ 10^3\$), it means that the king has awarded C identical carrots to be distributed among the snowmen built inside the rectangular-shaped region defined by the positions of coordinates (X1, Y1) and (X2, Y2), marking the end of a day.
- The last line of the input is always a five integer line.
Ouput:
For each day of the winter, ended in the input by a five integer line, print a line containing the number of the day and the number of possibilities for the distribution of the carrots among the snowmen at the delimited area. Consider that the counting of the days starts in 1. As the number of possibilities can be very large, print only the
Solution
Stack Usage?
I looked over your code and couldn't find any problems with it. So I ran it on my machine to see if it would work. But when I ran it, it got a segfault. When I debugged the program, it turned out that it wasn't a problem with the program logic, the problem was that the variable
I looked over your code and couldn't find any problems with it. So I ran it on my machine to see if it would work. But when I ran it, it got a segfault. When I debugged the program, it turned out that it wasn't a problem with the program logic, the problem was that the variable
T was causing the stack to overflow.T is defined as a local variable to main, so it is put on the stack. But the size of T is roughly 4 MB because of the big array inside of it. Apparently, my default stack limit isn't set up to handle that, and perhaps the judges setup is similar to mine? An easy fix for this is to make T be a global variable.Context
StackExchange Code Review Q#101370, answer score: 3
Revisions (0)
No revisions yet.