CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » November 2010 Challenge » Bombing

Bombing

Problem code: BOMBING

  • All Submissions

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


  • Submit

Comments

  • Login or Register to post a comment.

do enemy can bomb different

killers @ 1 Nov 2010 07:50 PM

do enemy can bomb different houeses??? if yes, then we have to give systems for each house??

i am using java Language. and

kewlRV @ 1 Nov 2010 07:59 PM

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

ishan.mail28 @ 1 Nov 2010 08:33 PM

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

melwin_jose @ 1 Nov 2010 08:38 PM

does the house number go from 0 to n??

if yes .. can they bomb the 0th house??

Can a defense system go in

mcsharma1990 @ 1 Nov 2010 10:11 PM

Can a defense system go in the right nth house after moving?

@Gagandeep Singh: your

anhdq_adm @ 1 Nov 2010 10:28 PM

@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

killers @ 2 Nov 2010 07:20 AM

is it possible??

P 1 5

B 1

P 2 6

B 3

then wts the result???

Is there some constraint on

nitishgarg91 @ 2 Nov 2010 09:25 AM

Is there some constraint on the number of defense systems?

YES ... maximum of 250000

gopi6sigma @ 2 Nov 2010 03:56 PM

YES ... maximum of 250000

All systems will be indexed

balajiganapath @ 2 Nov 2010 09:41 PM

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,

anhdq_adm @ 3 Nov 2010 06:10 AM

@Balajiganapathi: just 1, 2, 3...  ;-)

Hi admin,   As Ravi said, I

arun26oct @ 4 Nov 2010 05:13 PM

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.

anhdq_adm @ 4 Nov 2010 08:17 PM

@Arun M: yes, there is.

System isn't accepting array

akshar_1006 @ 4 Nov 2010 09:23 PM

System isn't accepting array sizes of 10^9

Hi !  Is there any

dinesh.cape @ 4 Nov 2010 09:32 PM

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

gopi6sigma @ 5 Nov 2010 12:37 AM

@ dinesh kumar:

m tells you where to stop. Read the description, input and output sections carefully

hi friends i m getting

tarun_kumar @ 5 Nov 2010 01:38 PM

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

kyun @ 6 Nov 2010 02:45 AM

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.

triplem @ 6 Nov 2010 03:51 AM

The latter is correct.

As time limit is 3 sec and

killers @ 6 Nov 2010 12:12 PM

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

theeporithirumugam @ 6 Nov 2010 10:17 PM

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

kyun @ 7 Nov 2010 09:49 AM

@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

kyun @ 7 Nov 2010 02:15 PM

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

tarun_kumar @ 7 Nov 2010 05:23 PM

hey vaibhav

i m already over 50 submissions and still getting TLE. :(

any suggestions

can anyone please post a

tarun_kumar @ 8 Nov 2010 12:31 AM

can anyone please post a bigger test case...

I am new to this site.... how

pratidnya @ 8 Nov 2010 06:55 PM

I am new to this site....

how to clear buffer???

plzz help...

M GETTING RUNTIME

pratidnya @ 8 Nov 2010 07:36 PM

M GETTING RUNTIME ERROR....

PLZZ TELL ME SOMETHING ABOUT THAT

@admin: Every one has

manoharsingh23 @ 8 Nov 2010 07:52 PM

@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

kyun @ 9 Nov 2010 12:05 AM

@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

codegambler @ 9 Nov 2010 11:47 AM

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

ishandutta2007 @ 10 Nov 2010 05:20 PM

@radhakrishnan-Memory limit is 250 MB..

No Successfull submissions

shivamvds @ 11 Nov 2010 08:15 PM

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.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com