Problem Statement
You are given a list of N numbers, {a1,a2,…,aN} , to be added to a database.
Each of these numbers must be added to the database in the order in which they are given.
If a number has already been added to the database, print "REDUNDANT" (without quotation marks).
Otherwise, add it to the database and print "ADDED"(again, without quotation marks).
The answer of each operation should be printed in a new line.
Each of these numbers must be added to the database in the order in which they are given.
If a number has already been added to the database, print "REDUNDANT" (without quotation marks).
Otherwise, add it to the database and print "ADDED"(again, without quotation marks).
The answer of each operation should be printed in a new line.
Input Format
The first line contains a single integer N , denoting the number of numbers to be added.
The second line contains theN space-separated integers - a1,a2,…aN .
The second line contains the
Output Format
Constraints
1≤N≤105 −109≤ai≤109, where i∈[1,N]
Sample Input
5
4
3
-3
3
100000
Sample Output
ADDED
ADDED
ADDED
REDUNDANT
ADDED
Explanation
- After the first addition, the database is now [4].
- After the second addition, the database is now [3,4].
- After the third addition, the database is now [-3,3,4].
- In the fourth addition, since 3 is already in the database, the database is now [-3,3,4].
- After the fifth addition, the database is now [-3,3,4,100000].
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
long int neg[1000000]={0},pos[1000000]={0};
int main() {
long int t;
cin>>t;
while(t--)
{
long int val;
cin>>val;
if(val>=0)
{
if(pos[val]==0)
{
printf("ADDED\n");
pos[val]=1;
}
else
{
printf("REDUNDANT\n");
}
}
else
{
val=val*-1;
if(neg[val]==0)
{
printf("ADDED\n");
neg[val]=1;
}
else
{
printf("REDUNDANT\n");
}
}
}
return 0;
}
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
long int neg[1000000]={0},pos[1000000]={0};
int main() {
long int t;
cin>>t;
while(t--)
{
long int val;
cin>>val;
if(val>=0)
{
if(pos[val]==0)
{
printf("ADDED\n");
pos[val]=1;
}
else
{
printf("REDUNDANT\n");
}
}
else
{
val=val*-1;
if(neg[val]==0)
{
printf("ADDED\n");
neg[val]=1;
}
else
{
printf("REDUNDANT\n");
}
}
}
return 0;
}