답안 #1095792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095792 2024-10-03T07:32:07 Z sitablechair Žarulje (COI15_zarulje) C++17
100 / 100
318 ms 20668 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll n,k,a[maxN],p[maxN];
vector<int> dq,st;
vector<pli> D;
ll nho[maxN];
ll ans[maxN];
ll luu=1;
ll cnt[2][maxN];
ll f[2*maxN],fr[2*maxN];
ll pw(ll x,ll y)
{
    if(y==0) return 1;
    ll x1=pw(x,y/2);
    x1=x1*x1%mod;
    if(y&1) x1=x1*x%mod;
    return x1;
}
ll C(ll k,ll n)
{
    return f[n]*fr[k]%mod*fr[n-k]%mod;
}
void c(ll t,ll x,ll v)
{
    luu=luu*pw(C(cnt[t][x],cnt[t][x]+cnt[1-t][x]),mod-2)%mod;
    cnt[t][x]+=v;
    luu=luu*C(cnt[t][x],cnt[t][x]+cnt[1-t][x])%mod;
}
void rollback(ll x)
{
    while(D.size()>x)
    {
        if(D.back().fi==0)
        {
            dq.pb(D.back().se);
            c(1,D.back().se,1);
        }
        else
        {
            dq.pop_back();
            c(1,D.back().se,-1);
        }
        D.pop_back();
    }
}
void solve()
{
    cin >> n >> k;
    for(int i=1;i<=n;i++) cin >> a[i];
    //for(int i=1;i<=k;i++) cin >> p[i];
    f[0]=1;
    for(ll i=1;i<=2*n;i++)
    {
        f[i]=f[i-1]*i%mod;
    }
    fr[2*n]=pw(f[2*n],mod-2);
    for(ll i=2*n-1;i>=0;i--)
    {
        fr[i]=fr[i+1]*(i+1)%mod;
    }
    for(int i=n;i>=1;i--)
    {
        while(dq.size()>0&&a[i]<dq.back())
        {
            D.pb({0,dq.back()});
            c(1,dq.back(),-1);
            dq.pop_back();
        }
        dq.pb(a[i]);
        D.pb({1,dq.back()});
        c(1,dq.back(),1);
        nho[i]=D.size();
    }
 
    for(int i=1;i<=n;i++)
    {
        rollback(nho[i+1]);
        if(i>1)
        {
            while(st.size()>0&&a[i-1]<st.back())
            {
                c(0,st.back(),-1);
                st.pop_back();
            }
            st.pb(a[i-1]);
            c(0,st.back(),1);
        }
        ans[i]=luu;
    }
    for(int i=1;i<=k;i++)
    {
        ll p;
        cin >> p;
        cout << ans[p]<<'\n';
    }
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

Compilation message

zarulje.cpp: In function 'void rollback(ll)':
zarulje.cpp:41:19: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   41 |     while(D.size()>x)
      |           ~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 3 ms 600 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 5 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 145 ms 7904 KB Output is correct
2 Correct 272 ms 15040 KB Output is correct
3 Correct 285 ms 15000 KB Output is correct
4 Correct 307 ms 15296 KB Output is correct
5 Correct 288 ms 15768 KB Output is correct
6 Correct 308 ms 17232 KB Output is correct
7 Correct 318 ms 18996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 3 ms 600 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 5 ms 604 KB Output is correct
7 Correct 145 ms 7904 KB Output is correct
8 Correct 272 ms 15040 KB Output is correct
9 Correct 285 ms 15000 KB Output is correct
10 Correct 307 ms 15296 KB Output is correct
11 Correct 288 ms 15768 KB Output is correct
12 Correct 308 ms 17232 KB Output is correct
13 Correct 318 ms 18996 KB Output is correct
14 Correct 16 ms 1504 KB Output is correct
15 Correct 147 ms 9416 KB Output is correct
16 Correct 280 ms 18116 KB Output is correct
17 Correct 284 ms 16832 KB Output is correct
18 Correct 289 ms 18620 KB Output is correct
19 Correct 296 ms 16832 KB Output is correct
20 Correct 308 ms 19056 KB Output is correct
21 Correct 309 ms 20668 KB Output is correct