/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 1.066 MiB
#2 Accepted 3ms 1.246 MiB
#3 Accepted 3ms 1.289 MiB
#4 Accepted 3ms 1.18 MiB
#5 Accepted 6ms 1.301 MiB
#6 Accepted 6ms 1.309 MiB
#7 Accepted 31ms 1.418 MiB
#8 Accepted 32ms 1.418 MiB
#9 Accepted 323ms 2.562 MiB
#10 Accepted 318ms 2.602 MiB
#11 Accepted 318ms 2.445 MiB
#12 Accepted 321ms 2.5 MiB
#13 Accepted 2ms 1.27 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic warning "-std=c++11"
 
using ll = long long;

const ll mod = 1e9 + 7;

#define sqr( a ) ( ( a ) * ( a ) )
const int sz = 1e5 + 10;

int n, q;
int t, l, r;
int ar[sz];
ll pw[sz];
ll ans;

ll solve( int l, int r ) {
        ll ret = 0;
        int od = ar[r] - ar[l - 1];
        int ev = r - l + 1 - od;
        ret = ( pw[ev] - 1ll + mod ) % mod;
        ll od_sum_sv = od >= 1 ? ( pw[od - 1] - 1ll + mod ) % mod : 0ll;
        ll hand = ( od_sum_sv * pw[ev] ) % mod;
        ret = ( ret + hand ) % mod;
        return ret;
}

int main() {

        pw[0] = 1ll;

        for( int i=1; i<sz; i++ ) pw[i] = ( pw[i - 1] * 2ll ) % mod;

        cin >> n >> q;

        assert( 1 <= n && n <= 100000 );
        assert( 1 <= q && q <= 100000 );

        for( int i=1; i<=n; i++ ) {
                cin >> ar[i];
                assert( 1 <= ar[i] && ar[i] <= 1000000000 );
                ar[i] %= 2;
                ar[i] += ar[i - 1]; 
        }

        while( q-- ) {
                cin >> t >> l >> r;
                assert( 0 <= t && t <= 1 );
                assert( 1 <= l && l <= n );
                assert( 1 <= r && r <= n );
                if( t == 1 ) {
                        ans = ( pw[r - l + 1] - 1ll + mod ) % mod;
                        ans = ( ans - solve( l, r ) + mod ) % mod;
                }
                else {
                        ans = solve( l, r );
                }
                cout << ans << "\n";
        }

        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
2024-10-12 22:24:29
Judged At
2024-11-11 02:37:29
Judged By
Score
100
Total Time
323ms
Peak Memory
2.602 MiB