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 Challenge 2013
    • May Cook-Off 2013
    • May Challenge 2013
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • Campus Chapters
    • Host your Contest
    • Go for Gold
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
    • Top Contributors on Discuss
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » Paradigm Shift contest 2012 » Martian Coin Game

Martian Coin Game

Problem code: IITI05

  • All Submissions

All submissions for this problem are available.

Freakin' news has recently claimed that they have discovered a civilization on mars and that they have established contact with the martians. Following is a summary of the midnight hour breakin' news on freakin' news :

Playful Configuration
A configuration of n coins placed in a 2 × n grid (2 rows, n columns) such that every column contains exactly one coin is called a playful configuration.
(Coins can only be placed inside a cell, and not on the boundary of two cells. Every coin is facing either heads-up or tails-up.)

One can update a playful configuration in the following ways :
1) switch(i, j) , where 1<=i<=j<=n :
For all integers r such that i<=r<=j, do the following :
If there is a coin at (1, r), remove it and place it, facing same side up at (2, r).
Otherwise remove the coin at (2, r) and place it, facing same side up at (1, r).
2) flip(i, j) , where 1<=i<=j<=n :
For all integers r such that i<=r<=j, do the following :
Flip the coin in column r without changing its position. (If the coin is initially facing heads-up then after flipping it will face tails-up and vice versa.)

One can query a playful configuration in the following way :
query(i, j) , where 1<=i<=j<=n :
Let h1 be the number of integers r such that i<=r<=j and there is a coin facing heads-up at (1,r).
Let h2 be the number of integers r such that i<=r<=j and there is a coin facing heads-up at (2,r).
Let t1 be the number of integers r such that i<=r<=j and there is a coin facing tails-up at (1,r).
Let t2 be the number of integers r such that i<=r<=j and there is a coin facing tails-up at (2,r).
query(i, j) returns h1,h2,t1 and t2.

The king of mars plays the following game every month :
He arranges n coins in a playful configuration. Initially all coins are in the first row (facing either heads-up or tails-up). He periodically performs operations on the configurations. Each operation is either an update (flip or switch) or a query. Any player who responds correctly to each query wins a large prize. Unfortunately, the game is too difficult and no player has yet won the coveted prize.

This month however, one of the ministers has gained access to the initial configuration as well as a list of all the operations. The minister has asked freakin' news to help him answer all queries correctly. Your job is to do this task for freakin' news.

Input Format

The first line contains a single integer n : The number of coins in the playful configuration.

The next line contains n space seperated integers f[1],f[2],...f[n] which describe the inital state of the coins. The coin in column i is initially at (1,i). If f[i] is 1, the coin at (1,i) is initially facing heads-up. Otherwise, the coin at (1,i) is initially facing tails-up.

The next line contains a single integer m : The number of operations.

The k'th of the next m lines contains 3 integers op,i,j which describe the k'th operation. Each operation is described as follows :
If op is 0, the operation is query(i,j).
If op is 1, the operation is flip(i,j).
If op is 2, the operation is switch(i,j).

Output Format

For each query, the program must output a single line consisting of 4 space seperated integers h1, h2, t1 and t2.

Constraints

1<=n<=100000
Each f[i] is either 0 or 1.
1<=m<=100000
For each operation, op is either 0,1 or 2.
For each operation, 1<=i<=j<=n.

Sample Input

10
1 1 1 1 1 0 0 0 0 0
5
0 1 7
2 3 5
0 1 7
1 1 10
0 1 7

Sample Output

5 0 2 0
2 3 2 0
2 0 2 3

Explanation

At the time of the first query, the configuration is :
H H H H H T T T T T
E E E E E E E E E E

At the time of the second query the configuration is :
H H E E E T T T T T
E E H H H E E E E E

At the time of the third query the configuration is :
T T E E E H H H H H
E E T T T E E E E E


Author: architk
Date Added: 23-03-2012
Time Limit: 2 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, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

Result of judgment: internal

dj3500 @ 31 Mar 2012 06:49 PM
Result of judgment: internal error :?

Regarding Internal Errors :

architk @ 31 Mar 2012 07:13 PM
Regarding Internal Errors : Currently, I am not sure what it means. Have contacted Codechef regarding this. I will post an update as soon as I receive a response from Codechef. Thank you for your patience.

Please rejudge my old

dj3500 @ 31 Mar 2012 07:47 PM
Please rejudge my old submission number 934422 (I submitted the same code three times over the course of the last hour and finally got AC).

Yes. Will do.

architk @ 31 Mar 2012 07:55 PM
Yes. Will do.

All solutions which were not

architk @ 31 Mar 2012 08:09 PM
All solutions which were not accepted (including internal errors) are being tested again.

Still no change.

dj3500 @ 31 Mar 2012 08:21 PM
Still no change.

Don't know whether the

architk @ 31 Mar 2012 08:28 PM
Don't know whether the rejudging is complete. We will sort this out before putting up the final ranklist.

Seems like some submissions

dj3500 @ 31 Mar 2012 08:33 PM
Seems like some submissions have been rejudged from AC to Internal Error :> See EgorK's solution to Interesting Martian Trips for an example.

will the problem be available

damians @ 31 Mar 2012 09:55 PM
will the problem be available in practice mode?

when internal error will be

jehad @ 1 Apr 2012 01:03 PM
when internal error will be recovered?

This contest is never going

dj3500 @ 6 Apr 2012 10:39 PM
This contest is never going to be rejudged properly, is it?

SUCCESSFUL SUBMISSIONS


Fetching successful submissions

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.