#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9
// #define fisier
using namespace std;
typedef long long ll;
int add(int a, int b)
{
ll x = a+b;
if(x >= mod)
x -= mod;
if(x < 0)
x += mod;
return x;
}
ll mul(ll a, ll b)
{
return (a*b) % mod;
}
ll pw(ll a, ll b)
{
ll ans = 1;
while(b)
{
if(b & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
long long a = rng();
return a;
}
int n, k, val, v[200002], v2[200002], ign[200002];
ll fact[200002], inv[200002];
ll C(int n, int k)
{
return mul(fact[n], mul(inv[k], inv[n-k]));
}
int solve(int val)
{
int st = val-1;
int dr = val+1;
int ans = 1;
bool prveq = 0;
int lst = 0;
while(st >= 1 && dr <= n)
{
if(v[st] == v[dr])
{
int xx = st;
while(xx && v[xx] == v[st])
--xx;
int yy = dr;
while(yy <= n && v[yy] == v[dr])
++yy;
if(!prveq || lst > v[st])
ans = mul(ans, C(st - xx + yy - dr, st - xx));
prveq = 1;
lst = v[st];
st = xx;
dr = yy;
}
else
if(v[st] > v[dr])
{
int xx = st;
lst = v[st];
while(xx && v[xx] == v[st])
--xx;
st = xx;
prveq = 0;
}
else
{
int yy = dr;
lst = v[dr];
while(yy <= n && v[yy] == v[dr])
++yy;
dr = yy;
prveq = 0;
}
}
return ans;
}
int main()
{
#ifdef fisier
ifstream f("input.in");
ofstream g("output.out");
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for(int i = 1; i <= n; ++i)
cin >> v[i];
fact[0] = inv[0] = 1;
for(int i = 1; i <= n; ++i)
{
fact[i] = mul(fact[i-1], i);
inv[i] = pw(fact[i], mod - 2);
}
for(; k; --k)
{
cin >> val;
cout << solve(val) << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |