/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 1.133 MiB
#2 Accepted 3ms 1.07 MiB
#3 Accepted 3ms 1.27 MiB
#4 Accepted 3ms 1.23 MiB
#5 Accepted 5ms 1.27 MiB
#6 Accepted 5ms 1.496 MiB
#7 Accepted 30ms 1.402 MiB
#8 Accepted 30ms 1.387 MiB
#9 Accepted 311ms 2.457 MiB
#10 Accepted 313ms 2.609 MiB
#11 Accepted 308ms 2.594 MiB
#12 Accepted 308ms 2.43 MiB
#13 Accepted 2ms 1.066 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-10-20 23:38:18
Judged By
Score
100
Total Time
313ms
Peak Memory
2.609 MiB