Sie sind auf Seite 1von 6

Assignment 5

Deadline - November 7, 2013 (9PM)

The Rank Problem


1. Display the marks of a given student in all subjects. 2. Delete a student from the records. 3. Given a student name and subject, print the name and marks in all subjects of the student who ranks just above/below this student in the given subject. You can not print the marks of a deleted student.

You are given the marks obtained by N students in K subjects and some queries. Queries are of 3 types :

Input format: First line will contain three integers : N K Q N is the total number of students K is the number of subjects Q is the number of queries Next N lines describe the marks obtained by each student, along with his student_id in the following format : <student_id> <m_1> <m_2> ...... <m_K> ( m_i is marks obtained in the ith subject) The next Q lines describe the queries. The formats for the 3 types of query are ( in the order as stated in description and the rst int denotes the query type ): 1 <student_id> 2 <student_id> 3 <student_id> <subject_number> <next/prev> Subject number will always be within 1 and K, both inclusive. next refers to the student who will be just below this student in the ranklist of the mentioned subject. Similarly, prev refers to the student who is just above this student in the ranklist of the mentioned subject. Output : The output must contain Q lines, one line per query. For the 3 types of query, following is the expected output : For the rst type : <student_id> <m1> <m2> ... <mK> where mI denotes the marks obtained in the ith subject For the second type : "done" ( just one word without quotes and no spaces after it ) For the third type : <student_id> <m1> <m2> ... <mK> where mI denotes the marks obtained in the ith subject. If the student in input ranks rst/last in the mentioned subject and next/prev is not possible, output rst or last depending on rank of given student. For the rst and third type of query, no space at the end. Constraints : 1 <= N <= 105 1 <= K <= 10 1 <= Q <= 106 student_id is a string consisting of lowercase letters and digits and its length will be a max of 10 characters. 0 <= mi <= 109 Warning : Large input/output. The memory limits are also very tight for this question. Sample Input 1 : 3 1 9 a 3 1

b c 1 3 3 3 2 3 3 3 3

2 1 b b b a a b b c c

1 next 1 prev 1 prev 1 1 1 1 next prev next prev

Sample Output 1 : b 2 c 1 a 3 first done c 1 first last b 2

The Bits

Although Fugga is a very good coder, but he does not like bits at all! Certainly, he got an intern oer at company XYZ. The company wants him to work on a problem related to bit streams - large streams of bits consisting of 0s and 1s. Neither Fugga wants to loose the job nor does he wants to solve the problem. So, he seeks your help. You will be given a snapshot of a bit stream and you have to perform the following operations: 1. Set a particular index in a bit stream 2. Toggle the bit at location index 3. Reset a particular index in a bit stream 4. Print an unsigned long integer starting from position index. Note: You should think about the limit of the bit stream. 5. Print the total number of 0 bits starting from a particular index unless you encounter 1. 6. Print the total number of 1 bits starting from a particular index unless you encounter 0. Following is the input specication: The rst line of the input will contain N as the length of the bit stream (104 < N < 109 ). The next line will contain the bit stream in a single line. Next line will have Q as number of queries (1 < Q < 1000) where you have to perform the above operations. The next Q lines will contain the following operations as: s <index> t <index> r <index> p <index> print it. // // // // set the bit at position index to 1 toggle the bit at position index reset the bit at position index to 0 construct an unsigned long integer starting from position index and

0 <index> // print the total number of 0s that occur before the occurrence of 1 from the position index. 1 <index> // print the total number of 1s that occur before the occurrence of 0 from the position index. Warning : Large input/output. The memory limits are also very tight for this question. Sample Input: 100 01000001110101001101011000000010010111100010111111100100011110010100101010010101 01011010000111100010 10 p 30 s 3 r 5 p 20 0 1 1 89 p 23 p 32 r 5 p 34 Sample Output: 16242976745335017961 12291776810752386054 1 0 13065687147412518016 8672430204761142394 2168107551190285598

The Beautiful Rings

You have been given two rings A and B, of the same size. Each ring has N cells. Each cell has two integer values : rank and key. When the two rings are placed one on top of the other, the beauty of the arrangement is dened as the sum of beauty of the combination of the N pairs of cells. The beauty of two cells, one from A and other from B, such that both face each other in the arrangement is given by : ( (key of cell in A)^(rank of cell in B) + (key of cell in B)^(rank of cell in A) ) % M where M is (10^9 + 7). ^is to be regarded as the power operator. Therefore, 2^3 is 8 and 3^2 is 9. You have been given the initial arrangement of both the rings. You have to rotate one or both the rings in clockwise/anti-clockwise fashion as explained in the next section in some predened operations. In some of the operations, you may also be asked to delete certain cells from both the rings ( beautiful stu is easy to break ). Since the rings are circular, you will be given the linear arrangement of cells starting from any one position. The rst position ( and not cell ) in this linear arrangement will hence be called the head. The position before this will be termed as tail, which would point to the last cell. One clockwise rotation would mean : place the cell pointed by head at the end in the linear arrangement.

One anti-clockwise rotation would mean : place the cell pointed by tail at the beginning in the linear arrangement. The head and tail would ALWAYS point to the rst and last positions in the linear arrangement. As an example, assume the ring A has been given as follows (rank,key) : (1,2) , (2,3) , (3,4) , (4,5). There are 4 cells in this ring. Head points to the (1,2). Tail points to (4,5). After one clockwise-rotation, the arrangement becomes : (2,3) , (3,4) , (4,5) , (1,2) head now points to the (2,3) and tail points to (1,2) Input The rst line will contain two integers : N M N is the total number of cells in each ring. M is the number of operations you have to perform. The next 4 lines contain keys of ring A ,keys of ring B, ranks of cells of ring A and ranks of cells of ring B. There are two types of operations: 1. Delete head/tail 2. Rotate rings The next M lines indicate the operations to be performed. The rst integer indicates the type of operation as stated above. The other information provided is : For rst type of operation: <head/tail> ( This means delete the cell pointed by head or tail in both ring A AND B) The new head in case of delete head is the cell which would have been the head after 1 clockwise-rotation. The new tail in case of delete tail is the cell which would have been the tail after 1 anti-clockwise rotation. For second type of operation : R L where R and L are integers. Rotate ring A clockwise R times and ring B anti-clockwise L times. Output : The output must contain M lines, one per operation. For the rst type, output one word : "done" For the second type, output one integer denoting the beauty of the arrangement M where M = (10^9 + 7). Constraints : 5 <= N <= 105 5 <= M <= 105 0 <= R, L < 1018 1 <= key, rank of any cell <= 106 Sample input: 4 1 5 1 5 2 2 1 2 1 2 6 2 3 4 6 7 8 2 3 4 6 7 8 0 0 1 2 head 0 0 tail 0 0

Sample output: 72268

8906 done 8729 done 8722 Explanation: The initial arrangement is (rank,key): Ring A : (1,1) (2,2) (3,3) (4,4) Ring B : (5,5) (6,6) (7,7) (8,8) The rst operation does not rotate either of the rings. The beauty is : ( 1^5 + 5^1 + 2^6 + 6^2 + 3^7 + 7^3 + 4^8 + 8^4 ) % M = 72268 The second operation rotates the Ring A 1 times clockwise and Ring B 2 times anti-clockwise. The new arrangement of rings will be : Ring A : (2,2) (3,3) (4,4) (1,1) Ring B : (7,7) (8,8) (5,5) (6,6) The beauty is : ( 2^7 + 7^2 + 3^8 + 8^3 + 4^5 + 5^4 + 1^6 + 6^1 ) % M = 8906 The third operation deletes the head from both the rings. The new arrangement is : Ring A : (3,3) (4,4) (1,1) Ring B : (8,8) (5,5) (6,6) The beauty after fourth operation is : 8906 - ( 2^7 + 7^2 ) = 8729 The fth operation deletes the tail. The new arrangement is : Ring A : (3,3) (4,4) Ring B : (8,8) (5,5) The beauty after sixth operation is : 8729 - ( 1^6 + 6^1 ) = 8722

The String Frenzy

After 4 successive submissions in the last 3 days, Buddhe and Desha are fed up of the assignments given to them in the college. But, still one assignment is left and they are not at all in the mood to solve that. So, they seek your help. They were given some statements and have to build an index table that provides information about the words. With the help of the index table, you need to perform the following queries: 1. Find the frequency of the a word in all the statements. 2. Find the dierence in frequency of two words from all the statements. 3. Output the ith statement, where i will be given as an input. 4. Output all the occurrences of the words in the alphabetical order along with statement index and the position in the statement. 5. Output the total number of words, statement by statement. 6. Output the total number of words in all the statements. 7. Output the total number of unique words present in the statements.

Following is the input specication: First line of the input will contain n (100 < n < 104 ). Next n lines will contain words (each word can be a max of 16 characters). The number of words is variable. The next will line will have Q (10 < Q < 1000) as the number of queries. Next Q lines will have queries that are of the form: 1 <word> // print the frequency of the words from the statements 2 <word1> <word2> // freq(word1) - freq(word2) 3 // print all the words in alphabetical order along with the statement index and position index 4 i // print the ith statement. 5 // print the total count of the words 6 // print the total count of the unique words. 7 // print all the statements index along with the total number of words in the statement. NOTE: The numbers denote the following operations that need to be performed. Sample Input: 3 haha haha hahhah test 1234 haha hello hello haha 7 1 haha 2 haha hello 4 2 3 5 6 7 Sample Output: 4 2 hello hello haha 1234 (1,1) haha (0,0) (0,1) (1,2) (2,2) hahhah (0,2) hello (2,0) (2,1) test (1,0) 9 5 0 3 1 3 2 3 Explanation: For 3, you need to print the word along with the statement index and the position index in the alphabetical order. Occurrence of the statement index and the position index should be in increasing order. The position index and statement index start from 0.

Das könnte Ihnen auch gefallen