/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 2ms 560.0 KiB
#3 Wrong Answer 2ms 660.0 KiB

Code

#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<utility>
#define ll long long
#define nl '\n'
using namespace std;
 const ll N=1e9+7;
ll ncr(ll n, ll r) {
    if (r > n) return 0; 
    if (r == 0 || n == r) return 1;  
    ll mul = 1;
    for (int i = 0; i < r; i++) {
        mul = mul * (n - i) / (i + 1); 
    }
    return mul;
}


int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
    ll n,q;
    cin>>n>>q;
    ll a[n];
    ll pre[n];
   for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i == 0) {
            pre[i] = (a[i] % 2 == 1) ? 1 : 0;
        } else {
            pre[i] = pre[i - 1] + (a[i] % 2 == 1 ? 1 : 0);
        }
    }
    while(q-- ){
    ll x,y,z;
    cin>>x>>y>>z;
    y--;z--;
    ll odd=pre[z]-pre[y];
        if(a[x]%2==1){
            odd++;
        }
       
     ll even=z-y+1-odd;
    if(x==0){
        ll combination_odd=0;
        for(int i=2;i<= odd ;i+=2){
             combination_odd+=ncr(odd,i)%N;
        }
        ll combination_even=0;
        for(int i=1;i<=even ;i++){
             combination_even+=ncr(even,i)%N;
        }
        ll ans=(combination_even+combination_odd+combination_even*combination_odd)%N;
        cout<<ans<<nl;
    }
    else{
          ll combination_odd=0;
        for(int i=1;i<= odd ;i+=2){
             combination_odd+=ncr(odd,i)%N;
           
        }
        ll combination_even=0;
        for(int i=1;i<=even ;i++){
             combination_even+=ncr(even,i)%N;
        }
       
        ll ans=combination_odd+combination_even*combination_odd;
        cout<<ans%N<<nl;
    }
    
    
    
    }


}

Information

Submit By
Type
Submission
Problem
P1033 Lyra and the Secrets of the Grand Library
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-02 15:55:16
Judged At
2024-11-02 15:55:16
Judged By
Score
0
Total Time
2ms
Peak Memory
660.0 KiB