#include <bits/stdc++.h>
#define print(a) for (auto i : a) cout << i << " "; cout << "\n";
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

const int mod = 998244353;

ll binpow(int a, int n) {
    if (n == 1) return a;
    ll res = 1;
    while (n > 1) {
        if (n&1) res = res*a % mod;
        res = res*a*a % mod;
        n >>= 1;
    }
    return res % mod;
}

int main() {
    freopen("C:/work/untitled/input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin>>p[i];
    }
    ll ab = 0, a = 0 , b = 0, s = 0;
    vector<int> p2(n, 0);
    for (int i = 0; i < n; i++) {
        p2[i] = n - p[i] + 1;
    }
    for (int i = 0; i < n; i++) {
        ab += binpow(p2[i], n-i);
        ab %= mod;
        a += binpow(p[i], n-i);
        a %= mod;
        b += binpow(p2[i], i+1);
        b %= mod;
        s += binpow(p[i], i+1);
        s %= mod;
    }
    int c1 = 0, c2 = 0;
    while (q--) {
        int t; cin >> t;
        if (t == 1) c1++;
        else c2++;

        if (c1&1 & c2&1) cout << ab;
        else if (c1&1) cout << a;
        else if (c2&1) cout << b;
        else cout << s;
        cout << " ";
    }
}