-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLittle Shino and the tournament.cpp
112 lines (84 loc) · 1.88 KB
/
Little Shino and the tournament.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define mod 1000000007
#define F first
#define S second
typedef long long ll;
using namespace std;
pair<long long int, int> a[100005];
int answer[100005]={0};
int main()
{
int n,q;
long long int temp;
scanf("%d %d",&n,&q);
for(int i = 1; i<=n; i++)
{
scanf("%lld",&temp);
a[i].F = temp;
a[i].S = i;
}
int count = n;
while(count!=1)
{
int p = 1;
// printf("%d\n",count);
// for(int i = 1; i<=n; i++)
// printf("%d ",answer[i]);
// printf("\n");
// for(int i = 1; i<=n; i++)
// printf("%d ",a[i].F);
// printf("\n");
// for(int i = 1; i<=n; i++)
// printf("%d ",a[i].S);
// printf("\n\n");
for(int i = 1; i<count; i+=2)
{
answer[a[i].S]++;
answer[a[i+1].S]++;
if(a[i].F>a[i+1].F)
{
a[p].F = a[i].F;
a[p].S = a[i].S;
p++;
}
else if(a[i+1].F>a[i].F)
{
a[p].F = a[i+1].F;
a[p].S = a[i+1].S;
p++;
// if(count==2)
// {
// printf("am here\n");
// for(int i = 1; i<=n; i++)
// printf("%d ",a[i]);
// cout<<endl;
// }
}
// if(count == 2)
// {
// for(int i = 1; i<=n; i++)
// printf("%d ",answer[i]);
// cout<<endl<<a[1].F<<endl;
// cout<<endl;
// }
}
if(count%2==1)
{
a[(count/2) + 1].F = a[count].F;
a[(count/2) + 1].S = a[count].S;
count = (count/2) + 1;
}
else if(count%2==0)
{
count = count/2;
}
}
for(int j = 1; j<=q; j++)
{
int temp;
scanf("%d",&temp);
printf("%d\n",answer[temp]);
}
return 0;
}