/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 1.062 MiB
#2 Accepted 2ms 1.312 MiB
#3 Accepted 2ms 1.312 MiB
#4 Accepted 2ms 1.312 MiB
#5 Accepted 3ms 1.312 MiB
#6 Accepted 3ms 1.312 MiB
#7 Accepted 6ms 1.391 MiB
#8 Accepted 6ms 1.391 MiB
#9 Accepted 51ms 2.836 MiB
#10 Accepted 56ms 2.98 MiB
#11 Accepted 51ms 2.801 MiB
#12 Accepted 50ms 2.859 MiB
#13 Accepted 2ms 1.312 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-11 02:33:59
Judged By
Score
100
Total Time
56ms
Peak Memory
2.98 MiB