/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 768.0 KiB
#3 Accepted 1ms 624.0 KiB
#4 Accepted 1ms 540.0 KiB
#5 Accepted 2ms 540.0 KiB
#6 Accepted 2ms 796.0 KiB
#7 Accepted 6ms 588.0 KiB
#8 Accepted 7ms 584.0 KiB
#9 Accepted 76ms 2.891 MiB
#10 Accepted 86ms 2.812 MiB
#11 Accepted 69ms 2.992 MiB
#12 Accepted 66ms 2.828 MiB
#13 Accepted 2ms 344.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define debug(a) cerr << #a << " = " << (a) << nl;
#define ll long long
#define nl '\n'
const int mod = 1e9+7;
const int N = 1e5+3;
int bigmod(int a, int b)
{
    int ans = 1;
    while (b > 0)
    {
        if (b & 1)
            ans = (ans * 1ll * a) % mod;
        a = (a * 1ll * a) % mod;
        b >>= 1;
    }
    return ans;
}

inline int add(int x, int y)
{
    return (x + y >= mod ? x + y - mod : x + y);
}

inline int sub(int x, int y)
{
    return (x - y < 0 ? x - y + mod : x - y);
}

inline int gun(int x, int y)
{
    return ((x * 1ll * y) % mod);
}

inline int vag(int x, int y)
{
    return (x * 1ll * bigmod(y, mod - 2)) % mod;
}
void TestCases()
{
    ll n,q;
    cin>>n>>q;
    ll a[n];
    ll odd[n+1];
    for(int i=0;i< n ;i++){
         cin>>a[i];
    }
    odd[0]=0;
    odd[1]=a[0]%2;
    for(int j=1;j<n ;j++){
        odd[j+1]=add(odd[j],(a[j]%2));
    }
    
      
    while(q-- ){
    ll op,l,r;
    cin>>op>>l>>r;
  
    if(op==0){
        ll ache=odd[r]-odd[l-1];
        ll even=(r-l+1)-ache;
      
        ll first=sub(bigmod(2,even),1);
        ll sec=sub(bigmod(2,ache-1),1);
        if(ache==0)sec=0;
        if(even==0)first=0;
        ll total=add(first,sec);
        total=add(total,gun(first,sec));
        cout<<total<<nl;
    }
    else{
         ll ache=odd[r]-odd[l-1];
         ll even=(r-l+1)-ache;
        ll first=sub(bigmod(2,ache-1),0);
        ll sec=sub(bigmod(2,even),1);
        ll total=add(first,gun(first,sec));
      
        if(ache==0)total=0;
        cout<<total<<nl;
    }
    
    
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int t = 1, cs = 0;
    //cin >> t;
    while (t--){
        // cout << "Case " << ++cs << ": ";
        TestCases();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1033 Lyra and the Secrets of the Grand Library
Language
C++17 (G++ 13.2.0)
Submit At
2025-05-15 15:19:18
Judged At
2025-05-15 15:19:18
Judged By
Score
100
Total Time
86ms
Peak Memory
2.992 MiB