/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 2ms 492.0 KiB
#3 Accepted 1ms 556.0 KiB
#4 Accepted 1ms 768.0 KiB
#5 Accepted 3ms 796.0 KiB
#6 Accepted 2ms 540.0 KiB
#7 Accepted 13ms 540.0 KiB
#8 Accepted 13ms 716.0 KiB
#9 Accepted 126ms 2.59 MiB
#10 Wrong Answer 125ms 2.566 MiB
#11 Wrong Answer 125ms 2.57 MiB

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 Ans = power(2 , even + odd - 1) % 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 00:50:47
Judged At
2024-10-13 01:18:26
Judged By
Score
60
Total Time
126ms
Peak Memory
2.59 MiB