Submission #283772

# Submission time Handle Problem Language Result Execution time Memory
283772 2020-08-26T07:07:41 Z 최은수(#5746) Žarulje (COI15_zarulje) C++17
60 / 100
1000 ms 2688 KB
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
const int mod=1e9+7;
const int mx=200010;
inline int add(int x,int y)
{
    return x+y<mod?x+y:x+y-mod;
}
inline int mul(int x,int y)
{
    return(int)((ll)x*y%mod);
}
inline int pw(int x,int y)
{
    int ret=1;
    while(y>0)
    {
        if(y%2==1)
            ret=mul(ret,x);
        x=mul(x,x);
        y/=2;
    }
    return ret;
}
int fac[mx],invf[mx];
inline int ncr(int n,int r)
{
    return mul(fac[n],mul(invf[n-r],invf[r]));
}
int a[mx];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin>>n>>k;
    fac[0]=1;
    for(int i=0;i++<n;)
        fac[i]=mul(fac[i-1],i);
    invf[n]=pw(fac[n],mod-2);
    for(int i=n;i>0;i--)
        invf[i-1]=mul(invf[i],i);
    for(int i=0;i++<n;)
        cin>>a[i];
    for(int qi=0;qi<k;qi++)
    {
        int x;
        cin>>x;
        vector<pi>vl,vr;
        for(int i=x;i-->1;)
        {
            if(vl.empty()||vl.back().fi>a[i])
                vl.eb(a[i],1);
            else if(vl.back().fi==a[i])
                vl.back().se++;
        }
        for(int i=x;i++<n;)
        {
            if(vr.empty()||vr.back().fi>a[i])
                vr.eb(a[i],1);
            else if(vr.back().fi==a[i])
                vr.back().se++;
        }
        int ans=1;
        for(int i=0,j=0;i<(int)vl.size();i++)
        {
            while(j<(int)vr.size()&&vr[j].fi>vl[i].fi)
                j++;
            if(j<(int)vr.size()&&vr[j].fi==vl[i].fi)
                ans=mul(ans,ncr(vl[i].se+vr[j].se,vl[i].se));
        }
        cout<<ans<<'\n';
    }
    cout.flush();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 12 ms 384 KB Output is correct
4 Correct 10 ms 504 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 8 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1536 KB Output is correct
2 Correct 19 ms 2628 KB Output is correct
3 Correct 18 ms 2688 KB Output is correct
4 Correct 19 ms 2688 KB Output is correct
5 Correct 21 ms 2680 KB Output is correct
6 Correct 22 ms 2688 KB Output is correct
7 Correct 24 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 12 ms 384 KB Output is correct
4 Correct 10 ms 504 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 8 ms 384 KB Output is correct
7 Correct 10 ms 1536 KB Output is correct
8 Correct 19 ms 2628 KB Output is correct
9 Correct 18 ms 2688 KB Output is correct
10 Correct 19 ms 2688 KB Output is correct
11 Correct 21 ms 2680 KB Output is correct
12 Correct 22 ms 2688 KB Output is correct
13 Correct 24 ms 2688 KB Output is correct
14 Correct 171 ms 792 KB Output is correct
15 Execution timed out 1057 ms 1784 KB Time limit exceeded
16 Halted 0 ms 0 KB -