SID - Search Insert Delete


You are given a bunch of data (all are positive 32 bit numbers) to operate on. The only operations on the data are search, insert, and delete. When storing the data you have to remember its rank, that is the original position when the data is being inserted. All successful operations must return the ranks of the data. Failed operations should return NONE as the answer.

Your objective is to execute all of the operations as fast as possible.

Input

The first line of input is N and M, separated by a space, N is the number of initial data. (0 <= N < 1000000) and M is the number of operations against the data. (0 <= M < 1000000).

The second line contains N data, separated by blanks. All data are positive 32 bits numbers

The next M lines contains operations against the data. Each line contains a symbol and a number, separated by a space. 

There are 3 symbols (S, I, D), each representing search, insert, and delete operation.

'S number' tries to find the number in the stored data, and outputs its first rank in the stored data (as originally inserted), or NONE if no such number exists.

'I number' inserts the number into the stored data, and outputs its rank in the stored data. (Data can be duplicated).

'D number' deletes the least ranked number found in the stored data, and outputs its rank, or NONE if no such number originally exists.

Output

There is an output for each executed operation. See the above input description about each operation for the detail of the output.

Example

Input:
10 6
20 12 10 28 20 50 49 8 51 1
S 20
I 3
S 11
D 20
I 2
S 20

Output:
1
11
NONE
1
12
5

hide comments
:D: 2013-02-08 07:40:07

Well somethings changed since I have an AC now. I will open it for now. Please e-mail me if you think there are still issues.

(Tjandra Satria Gunawan)(曾毅昆): 2012-12-24 07:32:35

I like this kind of problem very much, please fix this problem as soon as possible...

david_8k: 2012-11-14 04:31:39

Please, let me know when this problem gets fixed :D

:D: 2012-11-07 07:53:46

So I understand you didn't run you're sample solution before setting up the problem. Before making it visible you must do that, especially since you put a very strict time limit, high constrains and went for an old cluster. Verify that is't doable.

Mitch Schwartz: 2012-11-04 02:55:49

@Jimmy Tirtawangsa: That shouldn't be the issue; the "stderr" page truncates program output at a certain point, so in those cases you can't see the full user output (this seems reasonable in order to save hard drive space on SPOJ servers). If a program's output exceeds the allowed limit, there will be a SIGXFSZ (exceeded file size) runtime error.

Jimmy Tirtawangsa: 2012-11-04 02:29:37

Yup. Sorry guys. There is output limitation from spoj that I didn't realise. So your output are all truncated, hence are not the same as reference output.
I'll change the problem statement so that the output will be shorter. In the mean time, the problem is remain hidden.

:D: 2012-11-01 17:51:59

Yes, not saying that I'm 100% sure, but I did a decent amount of testing.

It maybe due to some reading problems when buffering, but you made the constrains so tight that it's pretty much required. Test files should have no formatting issues.

:D: 2012-11-01 13:41:26

I'm hiding it for now.

I'm in the process of writing O(N+M) solution (somewhat at least). I'll make extensive brute force tests. If it will fail (WA or TLE) it will be left closed until problem is corrected or setter shows me that those are only issues or solvers parts.

Ahmed AKram: 2012-11-01 11:53:22

something is wrong with the data please re-check the input/output

david_8k: 2012-11-01 00:44:18

Is it everything good with the input/output data?

Last edit: 2012-11-01 00:50:05

Added by:Jimmy Tirtawangsa
Date:2012-10-28
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ADA95 ASM32-GCC C-CLANG C NCSHARP CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG C99 COBOL FORTRAN GO GOSU JAVA JULIA KTLN LUA OBJC OBJC-CLANG PAS-GPC PAS-FPC PYTHON PYPY PYPY3 PYTHON3 RUST
Resource:Own problem