/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 1.066 MiB
#2 Accepted 2ms 1.062 MiB
#3 Accepted 2ms 1.07 MiB
#4 Accepted 2ms 1.094 MiB
#5 Accepted 2ms 1.02 MiB
#6 Accepted 2ms 1.09 MiB
#7 Accepted 2ms 1.066 MiB
#8 Accepted 2ms 1.066 MiB
#9 Accepted 6ms 1.523 MiB
#10 Accepted 44ms 2.375 MiB
#11 Accepted 46ms 2.312 MiB
#12 Accepted 46ms 2.359 MiB

Code

#include <cstdio>
#include <cassert>
using ll = long long;
const int mod = 1e9 + 7;
const int sz = 1e5 + 10;

ll pw[sz];
int ar[sz];
int n, q;
int x, v;
int oddCount;
int eventCount;
// Limits
const int n_lim_low = 1;
const int n_lim_high = 1e5;
const int q_lim_low = 1;
const int q_lim_high = 1e5;
const int ai_lim_low = 1;
const int ai_lim_high = 1e9;
const int v_lim_low = 1;
const int v_lim_high = 1e9;
// Limits

int main() {
    pw[0] = 1ll;
    for (int i = 1; i < sz; i++) {
        pw[i] = (pw[i - 1] * 2ll) % mod;
    }
    int n, q;
    scanf("%d %d", &n, &q);
    assert(n_lim_low <= n && n <= n_lim_high && "n not within limit");
    assert(q_lim_low <= q && q <= q_lim_high && "q not within limit");
    eventCount = 0;
    oddCount = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &ar[i]);
        assert(ai_lim_low <= ar[i] && ar[i] <= ai_lim_high && "ai not within limit");
        eventCount += !(ar[i] & 1);
        oddCount += (ar[i] & 1);
    }
    ll ans = 0;
    while (q--) {
        scanf("%d %d", &x, &v);
        assert(n_lim_low <= x && x <= n && "x not within limit");
        assert(v_lim_low <= v && v <= v_lim_high && "v not within limit");
        eventCount -= !(ar[x] & 1);
        oddCount -= (ar[x] & 1);
        ar[x] = v;
        eventCount += !(ar[x] & 1);
        oddCount += (ar[x] & 1);
        ans = ((oddCount > 0 ? (pw[oddCount - 1] + mod) % mod : 0ll) * pw[eventCount]) % mod;
        printf("%lld\n", ans);
    }
}

Information

Submit By
Type
Submission
Problem
P1032 Odd Query
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-12 13:32:34
Judged At
2024-11-11 02:37:31
Judged By
Score
100
Total Time
46ms
Peak Memory
2.375 MiB