/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 492.0 KiB
#2 Accepted 2ms 480.0 KiB
#3 Accepted 2ms 332.0 KiB
#4 Accepted 2ms 332.0 KiB
#5 Accepted 3ms 716.0 KiB
#6 Accepted 4ms 576.0 KiB
#7 Accepted 11ms 748.0 KiB
#8 Accepted 12ms 600.0 KiB
#9 Accepted 99ms 2.637 MiB
#10 Wrong Answer 101ms 2.609 MiB
#11 Wrong Answer 101ms 2.488 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) ;
    int even = freqOddEvenOfR.F - freqOddEvenOfL.F ;
    int odd = freqOddEvenOfR.S - freqOddEvenOfL.S ;
    ll Ans = power(2 , even + odd - 1) % Mod ;
    if(type == 0) Ans-- ;
    cout << Ans << "\n" ;
  }
}
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:45:08
Judged At
2024-11-11 02:37:27
Judged By
Score
60
Total Time
101ms
Peak Memory
2.637 MiB