/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 320.0 KiB
#2 Accepted 2ms 324.0 KiB
#3 Accepted 2ms 328.0 KiB
#4 Accepted 2ms 324.0 KiB
#5 Accepted 4ms 532.0 KiB
#6 Accepted 4ms 572.0 KiB
#7 Accepted 25ms 692.0 KiB
#8 Accepted 25ms 756.0 KiB
#9 Accepted 236ms 2.527 MiB
#10 Accepted 236ms 2.633 MiB
#11 Accepted 236ms 2.562 MiB
#12 Accepted 242ms 2.461 MiB
#13 Accepted 1ms 532.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define F                first
#define S                second
#define pb               push_back
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define P(ok)            cout << (ok ? "YES\n": "NO\n")
#define __Heart__              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll>                   PII;
const int Mod = 1e9 + 7 ;
const int MX = 1e5 + 5 ;
int evenFreq[MX] , oddFreq[MX] , n , q;
ll power(ll x, ll y)
{
    ll Res = 1;
    x = x % Mod;
    while (y > 0)
    {
        if (y & 1) Res = (Res * x) % Mod ;
        y = y >> 1;
        x = (x * x) % Mod;
    }
    return Res;
}
void update(int index, int value) {

    while(index <= n){
        evenFreq[index] += (value == 0) ;
        oddFreq[index] += (value == 1) ;
        index += index & -index ;
    }
}
pair < int , int > query(int index) {
  int odd = 0 , even = 0;
  while(index > 0){
    even += evenFreq[index];
    odd += oddFreq[index] ;
    index -= index & -index ;
  }
  return  {even , odd};
}
void solve()
{
    cin >> n >> q ; int a[n] ;
    for(auto &x : a) cin >> x ;
    for(int i = 0 ; i < n ; i++){
        update(i + 1 , a[i] % 2) ;
    }
  int type , l , r ;
  while(q--){
    cin >> type >> l >> r ;
    pair < int , int > freqOddEvenOfR = query(r) ;
    pair < int , int > freqOddEvenOfL =  query(l - 1) ;
    ll even = freqOddEvenOfR.F - freqOddEvenOfL.F ;
    ll odd = freqOddEvenOfR.S - freqOddEvenOfL.S ;
    ll EvenSubSequence = (power(2 , even) % Mod) ;
    ll oddSubSequence = (odd > 0 ? power(2 , odd - 1) % Mod : 1) ;
    ll Ans = (EvenSubSequence % Mod * oddSubSequence % Mod) % Mod ;
    if(type == 0) Ans-- ;
    cout << Ans << endl ;
  }
}
int main()
{
     __Heart__
     int t ; t = 1; while(t--) solve() ;
}

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-10-13 02:13:18
Judged At
2024-11-11 02:37:25
Judged By
Score
100
Total Time
242ms
Peak Memory
2.633 MiB