BombingProblem code: BOMBING |
All submissions for this problem are available.
There are n+1 (0 < n <= 109, indexed 0..n) houses lying on a straight street. One day, they are bombed by an enemy. CodeChef is designing defence systems to protect the street from bombing. Each defense system can protect all houses in some interval, and a house can be protected by more than one system. A defence system can be also moved at any time. By agents, CodeChef knows the bombing schedule of the enemy. Each time they bomb a house and CodeChef wants to know how many systems are protecting that house.
Input
- The first line contains two integers n, m (0 < m <= 250 000).
- Each of the m following lines follows one of these:
- P u v: CodeChef adds a defence system protecting all houses from the u-th house to the v-th house (0 <= u <= v <= n). All systems will be indexed by order of appearance in the input, starting from 1.
- M i d: CodeChef moves the i-th system by d houses, d < 0 means moving nearer the 0-th house, and d > 0 means moving away (that is, if the i-th system covers houses u through v, it is moved to instead cover houses w=u+d through t=v+d). After being moved the system will protect from the w-th house to t-th house where 0 <= w <= t <= n.
- B x: The enemy bombs the x-th house.
Output
For each time of bombing by the enemy (by the appearance in the input), output on a single line a number of systems protecting that house.
Example
Input: 7 5 P 1 4 P 3 5 B 3 M 2 1 B 3 Output: 2 1
| Author: | anhdq |
| Date Added: | 6-08-2010 |
| Time Limit: | 3 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments

Fetching successful submissions

do enemy can bomb different
do enemy can bomb different houeses??? if yes, then we have to give systems for each house??
i am using java Language. and
i am using java Language.
and using br.readLine() for each line. is there is enter(new line) after last line ?
because i am always getting time limir exceeded error.
please help.
the codeis perfectly running
the codeis perfectly running on my machine . but i am getting runtime error. i am using g++ can you tell me what type of runtime error i am facing.
does the house number go from
does the house number go from 0 to n??
if yes .. can they bomb the 0th house??
Can a defense system go in
Can a defense system go in the right nth house after moving?
@Gagandeep Singh: your
@Gagandeep Singh: your question is not clear enough to answer :-) please give some more details.
@ravi pardeshi: yes, there is :-)
@Ishan Mahendru: it doesn't have to be answered, just see FAQ for details :-) and please use normal font size.
@Melwin Jose: YES for both questions!
@Mahesh Chandra Sharma: NO as the statement said.
is it possible?? P 1 5 B 1 P
is it possible??
P 1 5
B 1
P 2 6
B 3
then wts the result???
Is there some constraint on
Is there some constraint on the number of defense systems?
YES ... maximum of 250000
YES ... maximum of 250000
All systems will be indexed
All systems will be indexed by order of appearance in the input, starting from 1.
Suppose the input is:
5
P 1 5
P 10 100
M 1 2
P 10 12
B 10
Then the systems are numbered 1, 2 and 4 or just 1, 2 and 3 ?
@Balajiganapathi: just 1, 2,
@Balajiganapathi: just 1, 2, 3... ;-)
Hi admin, As Ravi said, I
Hi admin,
As Ravi said, I am also getting Time exceed Exception everytime. I am sure my logic is very simple. Will last newline can cause Time Exceed Exception ? I didnt get Ravi's question & your response for that.
@Arun M: yes, there is.
@Arun M: yes, there is.
System isn't accepting array
System isn't accepting array sizes of 10^9
Hi ! Is there any
Hi ! Is there any constraints on the number of bombings. If not means how can i identify whether the input is end.
Please help me.
@ dinesh kumar: m tells you
@ dinesh kumar:
m tells you where to stop. Read the description, input and output sections carefully
hi friends i m getting
hi friends
i m getting Runtime Error
by refering to FAQ i found that this error may be due to i m using too much memory.
my logic is simple.
for all the arrays i used dynamic memory allocation for each entry so to avoid unnecessary bloating.
excpet this i used just 4 int and 2 long variables.
my program is working fine on my system.
can anyone please help me...
Hi Just to confirm: A move of
Hi
Just to confirm:
A move of the form
M i d
moves the ith protection by d steps. Now, if another query
M i d1
were applied on the same index, the relative movement from the very first location would be (d+d1) or just d1?
For instance, if we had
P 1 4
with an index 1.
M 1 2 would move it from (1,4) to (3, 6). Now, if we apply
M 1 2 again, do we get (3,6) or (5,8) - I have assumed the latter.
Thanks!
The latter is correct.
The latter is correct.
As time limit is 3 sec and
As time limit is 3 sec and sol is taking execution time of .05 sec on my pc if i am giving delay(100) to calculate time... but every time i submit it show me error of time limit exceed.. do any one tell me why it so??
i means how much memory we
i means how much memory we have to use?
wats the memory LIMIT?
can we use a linear space for the total number of houses?
u had specified that number of houses is abt 10^9
clear ma doubt
@Gagandeep Try some larger
@Gagandeep
Try some larger test cases - not just the ones in the sample. Time limit exceeded just means your algorithm is not good enough
@radhakrishnan
a) Memory cannot be of the order of 1 GB as in the case of a linear array of size 10^9. You might want to use the other constraints specified in the problem.
b) Please read the FAQ before asking questions. To quote:
"Make sure you aren't declaring too much memory. 64 MB is guaranteed, but having an array of size [10000][10000] will never work."
I finally got my code AC
I finally got my code AC after something like 50 submissions (at least). I used ridiculous amounts of I/O and other optimisations before it worked and its still one of the worst among the AC. I am so looking forward to seeing everyone else's code at the end of the contest! :-)
hey vaibhav i m already over
hey vaibhav
i m already over 50 submissions and still getting TLE. :(
any suggestions
can anyone please post a
can anyone please post a bigger test case...
I am new to this site.... how
I am new to this site....
how to clear buffer???
plzz help...
M GETTING RUNTIME
M GETTING RUNTIME ERROR....
PLZZ TELL ME SOMETHING ABOUT THAT
@admin: Every one has
@admin:
Every one has submitted answer successfully with execution time more than 9 sec and given time limit is 3 sec.
Then y in my case it is sowing time limit exceeded ..... My code takes around 10 secs on my system.
@Manohar The 3s time limit is
@Manohar
The 3s time limit is typically per test case. There are likely to be many input files and the time shown is the sum of all of these cases. Also, as mentioned in the FAQ Codechef machines are likely to be slower than our home machines.
@$w@m!
FAQ might help.
The best thing in codechef
The best thing in codechef problems is you can make a brute force solution for the problem and then check the correctness of fast solution.
@radhakrishnan-Memory limit
@radhakrishnan-Memory limit is 250 MB..
No Successfull submissions
No Successfull submissions yet in JAVA language.
Can anybody help me on the approach for thinking/designing algos with reduced time/space complexity.
Like some basic checklist or some tips & tricks.
Any study material will also be highly appreciated.