Charges Solution Codechef -There are NN subatomic particles lined up in a row. There are two types: protons and electrons. Protons have a positive charge and are represented by 11,

  

Charges Solution Codechef -  

SOLUTION

” CLICK HERE “


There are N subatomic particles lined up in a row. There are two types: protons and electrons. Protons have a positive charge and are represented by 1, while electrons have a negative charge and are represented by 0.

Our current understanding of physics gives us a way to predict how the particles will be spaced out, if we know their charges. Two adjacent particles will be separated by 1 unit if they have opposite charges, and 2 units if they have the same charge.

When Chef is not in the kitchen, he is doing physics experiments on subatomic particles. He is testing the hypothesis by having N particles in a row, and he will change the charge of a particle K times. In the i-th update, he will change the charge of the Qi-th particle. After each update, find the distance between the first and last particle.

Note: Each update is persistent for further updates.

Input

  • The first line contains an integer T, the number of test cases. Then the test cases follow.
  • Each test case contains three lines of input.
  • The first line contains two integers NK.
  • The second line contains a string S of length N, where Si represents the initial charge on i-th particle.
  • The third line contains K integers Q1,Q2,,QK, the positions of the changed particles.

Output

For each test case, output K lines, where the i-th line contains the answer after the updates Q1,,Qi have been made.

Constraints

  • 1T5
  • 1N,K105
  • S contains only 0 and 1 characters.
  • 1QiN
  • The sum of K over all testcases is at most 2105

Subtasks

Subtask #1 (100 points): original constraints

Sample Input

1
3 3
010
2 1 3

Sample Output

4
3
2

Explanation

Update 1: After reversing the parity of particle 2, the new configuration is 000. Since all the particles have a similar charge, each is separated from the previous by a distance of 2 units. So the location of particle 3 is 2+2=4 units from the first particle.

Update 2: After reversing the parity of particle 1, the new configuration is 100. Here, the charges of particles 1 and 2 differ, so they are separated by 1 unit. The charges of particles 2 and 3 agree, so they are separated by 2 units. So, the location of particle 3 is 1+2=3 units from the first particle.

Update 3: After reversing the charge of particle 3, the new configuration is 101. Here, particles 1 and 2 are separated by 1 unit and particles 2 and 3 are separated by 1 unit. So the location of particle 3 is 1+1=2 units from the first particle.


SOLUTION

” CLICK HERE “


Charges Solution Codechef -   



Details


CodeChef is happy to welcome Junglee Games who is looking to hire programmers who showcase their mettle via May Lunchtime 2021. Interested programmers must compete in this contest and apply via the form below to get considered.

Junglee Games

Junglee Games Hiring Drive

Junglee Games is a leader in the skill-gaming space, with over 25 million users. Founded in San Francisco in 2012, and funded by top-tier Silicon Valley VCs, Junglee Games is the fastest-growing skill-gaming company in the world. Some of Junglee Games' notable games are Junglee Rummy, Eatme.io, Junglee Teen Patti, and Howzat. Its team has worked on international AAA titles like Transformers, Real Steel, Mech Conquest, and Dueling Blades and its designers have worked on some of Hollywood’s biggest hits, including the movie Avatar. CodeChef is happy to announce that Junglee Games is on the lookout for ace programmers in CodeChef’s community for SDE II BackendSDE III BackendSDE II DataSDE III Data, and SDE II Frontend roles for its fast-paced environment. We encourage you to compete and apply for the roles you’re interested in.

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.

About CodeChef Lunchtime:

CodeChef Lunchtime is a three hours coding contest where you can show off your computer programming skills.

Contest Details:

  • Duration: 3 hours
  • Start Date: Monday, 31st May, 2021 at 20:00 HRS (IST)
  • End Date: Monday, 31st May, 2021 at 23:00 HRS (IST)
  • Check your timezone here.

Eligibility Criteria: Anyone with a knack for Programming :P

Our contests are open to all the programmers across the globe.

What's in it for you?

The idea behind these programming contests is that we want you to learn while competing. Also we believe that it is alright to refer to tutorials, books and other materials, learn a concept and then apply the same to solve a problem during a contest. But it is not alright to copy other people's solutions or seek other people's help to solve a problem without understanding it. The dividing line may seem to be thin but it can be captured by the spirit of learning. If whatever you are doing is making you learn while you do so, we tend to believe that it is alright. However, all the participants are expected to abide to

Rules and Regulations:

  • This is an IOI style contest. This means that the problems will be partially graded. You will get score for passing certain test data.
  • The details of the failed test cases will also be visible on your solution page.
  • You can submit solutions as many times as you'd like, there are no penalties for incorrect submissions. Only your best correct submission will be considered.
  • Those who achieve the score first will be placed higher in the ranklist in case of a tie.
  • We have removed all the Institutions that we could not identify from our database. We request you to update your institutions once again by going to your profile page.
  • You can also send in your queries in an email to help@codechef.com, during the contest.
  • Please do not discuss strategy, suggestions or tips in the comments during a live contest. Posting questions clarifying the problem statement is ok. If you are unsure, email us at feedback@codechef.com .
  • Discussing CodeChef's problems or any aspect of problem, on any other platform on web, on identification, could lead to disabling of respective account and banning from the community.
  • Residents of the following countries and territories are not eligible to win cash prizes/laddus/goodies due to legal restrictions: Albania, The Bahamas, Barbados, Botswana, Cambodia, Crimea region of Russia, Cuba, Ghana, Iceland, Iran, Jamaica, Mauritius, Mongolia, Myanmar, Nicaragua, North Korea, Pakistan, Panama, Sudan, Syria, Uganda, Yemen, Zimbabwe.

Note: You can now "Code, Compile, and Run" your codes on our Online IDE.

However, if you are using any other online development environment, make sure that other contestants don't have access to your code. As a contestant, you are responsible for making sure others don't access the code that you submit. If you use Ideone, make sure to mark your submission "private" (not secret)".

Reactions