-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDisappearance in an order.cpp
48 lines (48 loc) · 1.23 KB
/
Disappearance in an order.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
vector<int> DisappearanceOfIntegers (vector<int> a, int Q, vector<int> M,vector<long long int> t,int n){
vector<int>ans;
long long int k = a.size()*4,z;
int temp;
for(int i=0;i<Q;i++){
int res=0;
z = t[i]%k;
if(z<n){
temp = M[i]+z-1;
if(temp>=0 && temp < n){
res = a[temp];
}else{
res = -1;
}
}else if(z<2*n){
if(M[i]<=z-n){
if(M[i]-1>=0 && M[i]-1<n){
res = a[M[i]-1];
}else{
res = -1;
}
}else{
res = -1;
}
}else if(z<3*n){
z = z-2*n;
temp = M[i]+z-1;
if(temp>=0 && temp < n){
res = a[temp];
}else{
res = -1;
}
}else{
z = z-2*n;
if(M[i]<=z-n){
if(M[i]-1>=0 && M[i]-1<n){
res = a[M[i]-1];
}else{
res = -1;
}
}else{
res = -1;
}
}
ans.push_back(res);
}
return ans;
}