/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 1.27 MiB
#2 Accepted 2ms 1.27 MiB
#3 Accepted 2ms 1.273 MiB
#4 Accepted 2ms 1.27 MiB
#5 Accepted 3ms 1.27 MiB
#6 Accepted 4ms 1.27 MiB
#7 Accepted 11ms 1.27 MiB
#8 Accepted 11ms 1.27 MiB
#9 Accepted 41ms 3.02 MiB
#10 Accepted 42ms 3.02 MiB
#11 Accepted 42ms 2.961 MiB
#12 Accepted 43ms 2.828 MiB
#13 Accepted 2ms 1.27 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define bug(a) cout<< #a << " : " << a <<endl;
#define bug2(a, b) cout<< #a << " : " << a  << " " << #b << " : " << b << endl;

const int N = 1e5 + 10;
const int mod = 1e9 + 7;
int even[N], odd[N];

ll pw[N];

void solve(int cs){
    int n, q;
    cin >> n >> q;
    for(int i = 1;i <= n;i++){
        int x;
        cin >> x;
        if(x & 1){
            odd[i] = odd[i - 1] + 1;
            even[i] = even[i - 1];
        }
        else{
            even[i] = even[i - 1] + 1;
            odd[i] = odd[i - 1];
        }
    }
    while(q--){
        int t, l, r;
        cin >> t >> l >> r;
        ll od = odd[r] - odd[l - 1];
        ll ev = even[r] - even[l - 1]; 
        if(t == 1){
            if(od == 0) cout << 0 << '\n';
            else{
                ll ans = pw[od - 1] * pw[ev];
                ans %= mod;
                cout << ans << '\n';
            }
        }
        else{
            ll ans = (od == 0 ? 1 : pw[od - 1]) * pw[ev];
            ans %= mod;
            ans = ((ans - 1) + mod) % mod;
            cout << ans << '\n';
        }
    }

}


int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    cout.tie(0);

    int tc = 1;
    // cin >> tc;

    pw[0] = 1;
    for(int i = 1;i < N;i++){
        pw[i] = pw[i - 1] * 2;
        pw[i] %= mod;
    }

    for(int cs = 1; cs <= tc; cs++){
        solve(cs);
    }
}

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-03 17:47:47
Judged At
2024-11-03 17:47:47
Judged By
Score
100
Total Time
43ms
Peak Memory
3.02 MiB