All submissions for this problem are available.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef is playing a game named "Killing monsters". In this game, at the beginning, there are n monsters arranged in a row (numbered 0 through n-1 from left to right). The i-th monster initially has hi health points. A monster dies if its health points become ≤ 0.
Chef is going to perform q actions. For each action, Chef chooses two numbers x, y and shoots all living monsters whose index k satisfies k & x = k (& denotes the bitwise AND operator). Each monster he shoots loses y health points.
After each action, please help Chef determine the number of living monsters.
- The first line of the input contains a single integer n denoting the number of monsters.
- The second line contains n space-separated integers h0, h1, ..., hn-1 denoting the initial health of monsters.
- The third line contains a single integer q denoting the number of actions.
- q lines follow. Each of these lines contains two space-separated integers x and y describing one action.
For each action, print a single line containing one integer — the number of living monsters afterwards.
- 1 ≤ n ≤ 217
- 1 ≤ hi ≤ 109 for each valid i
- 1 ≤ q ≤ 218
- 0 ≤ x ≤ 109
- 1 ≤ y ≤ 109
Subtask #1 (10 points):
- 1 ≤ n ≤ 210
- 1 ≤ q ≤ 211
Subtask #2 (20 points):
- hi = 1 for each valid i
- y = 1 for each action
Subtask #3 (70 points): original constraints
Input: 5 1 2 3 4 5 5 1 1 2 2 3 3 4 4 5 5 Output: 4 4 2 2 1
|Tags||chemthan, chemthan, jan18, medium|
|Time Limit:||3 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.