12565 - Vector Implementation (mid2)   

Description

No memes, stories, jokes, or javascript that makes the problem disappears, yay o(* ̄▽ ̄*)o


This problem is partial judge. And you are going to implement a vector by yourself.

Things you need to implement:

  • vector(): Constructor of our vector. CAPACITY and SIZE are initially 0.

  • void push_back(T x): Same as push_back function in STL. Note that if CAPACITY equals to SIZE, you have to double the size of arr first, then push element in.

  • T & operator [] (const int &x): Random access, same as STL. A vector<int> V should be able to access every element of arr by calling V[x].

  • const T & operator [] (const int &x) const: Random access for any constant object.

  • vector<T> & operator = (const vector<T> &x): Implementation of assignment operator =. Use to copy the content of a vector into another vector by =, for example: v1=v2. Note that you must copy the content of v2.arr into v1.arr instead of just copy the pointer of arr.

  • size_t size() const: Same as size function in STL. Return the size of the vector.

  • size_t capacity() const: Same as capacity function in STL. Return the total size that arr has allocated.

  • void reserve(size_t x): Same as reserve function in STL. This function will increase the capacity to x, which means to extend the size of arr to size x. Note that if x is not greater than the current capacity, the function do nothing. After reserving, all the data that had pushed in should remain the same.

  • void clear(): Same as clear function in STL. The function reset SIZE to 0. Note that CAPACITY won't change in this function. Also, this function will destruct all the elements.

After implementing these functions, we'll give you several commands:

  • push_back <t1>: call push_back(t1)

  • pop_back: call pop_back()

  • access <t1>: call v[t1]

  • size: output size()

  • capacity: output capacity()

  • reserve <t1>: call reserve(t1)

  • clear: call clear

  • backup: store the current state of the vector into a temporary storage.

  • restore: load the previous saved vector and replace the current vector.

It is guaranteed that no illegal operation will appear, such as pop_back while the vector is empty, accessing index that exceeds the size, or restore without any backup.

Input

The first line contains an integer, indicates the number of commands.

The next lines are all commands that describe above.

The number of commands won't exceed .

The parameter of reserve will be in range of , and all other parameters will be in range of .

Output

Output when the corresponding commands appears.

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

12565.cpp

Partial Judge Header

12565.h

Tags




Discuss