QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#166901#6863. OrPPP#AC ✓501ms26860kbC++173.9kb2023-09-06 20:27:362023-09-06 20:27:36

Judging History

你现在查看的是最新测评结果

  • [2023-09-06 20:27:36]
  • 评测
  • 测评结果:AC
  • 用时:501ms
  • 内存:26860kb
  • [2023-09-06 20:27:36]
  • 提交

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod = 998244353;
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
int pw(int a, int b) {
    if (b == 0) return 1;
    if (b & 1) return mult(a, pw(a, b - 1));
    int res = pw(a, b / 2);
    return mult(res, res);
}
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int n, m;
const int maxN = 1e5 + 10;
int a[maxN];
int pref[maxN];
int b[maxN];
int X[maxN], Y[maxN];
const int LOG = 18;
int lg[maxN];
int mx[LOG][maxN];
const int maxP = 1e6 + 10;
int ans[maxP];
int l[maxP], r[maxP];
int at_least[maxN];
void solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    lg[1] = 0;
    for (int i = 2; i <= n; i++) {
        lg[i] = lg[i - 1];
        if (!(i & (i - 1))) lg[i]++;
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
        pref[i] = pref[i - 1] + b[i];
        a[i] -= pref[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> l[i] >> r[i];
        ans[i] = 0;

//        int bb = 0;
//        for (int j = l[i]; j <= r[i]; j++) {
//            for (int k = j; k <= r[i]; k++) {
//                bb |= (a[j] + pref[k]);
//            }
//        }
//        cout << " HI " << bb << endl;
    }

    for (int bit = 0; bit < 30; bit++) {
        for (int i = 1; i <= n; i++) {
            X[i] = (a[i] % (1 << (bit + 1)));
            if (X[i] < 0) X[i] += (1 << (bit + 1));
            Y[i] = (pref[i] % (1 << (bit + 1)));
            mx[0][i] = Y[i];
        }
        at_least[n + 1] = n + 1;
        multiset<int> s;
        for (int i = n; i >= 1; i--) {
            at_least[i] = at_least[i + 1];
            s.insert(Y[i]);
            while (at_least[i] - 1 >= i) {
                if (at_least[i] != (n + 1)) {
                    s.erase(s.find(Y[at_least[i]]));
                }
                auto it = s.lower_bound((1 << (bit)) - X[i]);
                if (it != s.end() && X[i] + (*it) < (1 << (bit + 1))) {
                    at_least[i]--;
                    continue;
                }
                it = s.lower_bound(3 * (1 << bit) - X[i]);
                if (it != s.end() && X[i] + (*it) < (1 << (bit + 2))) {
                    at_least[i]--;
                    continue;
                }
                if (at_least[i] != (n + 1)) {
                    s.insert(Y[at_least[i]]);
                }
                break;
            }
        }
        for (int i = 1; i <= n; i++) {
            mx[0][i] = -at_least[i];
//            if (bit == 4) {
//                cout << " HI " << i << " "
//            }
        }
        for (int k = 0; k + 1 < LOG; k++) {
            for (int i = 1; i + (1 << (k + 1)) - 1 <= n; i++) {
                mx[k + 1][i] = max(mx[k][i], mx[k][i + (1 << k)]);
            }
        }
        for (int i = 1; i <= m; i++) {
            int L = l[i];
            int R = r[i];
            int k = lg[R - L + 1];
            int D = max(mx[k][L], mx[k][R - (1 << k) + 1]);
            if (D >= -R) {
                ans[i] |= (1 << bit);
//                cout << " HI " << i << " " << (1 << bit) << endl;
            }
        }
    }
    int coef = 1;
    int base = 233;
    int tot = 0;
    for (int i = 1; i <= m; i++) {
        coef = mult(coef, base);
        tot = sum(tot, mult(coef, ans[i] % mod));
    }
    cout << tot << '\n';


}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int tst;
    cin >> tst;
    while (tst--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 501ms
memory: 26860kb

input:

4
40000 400000
548 4 34696904 0 7256657 310 0 253420460 0 89450757 759109 77 0 505042 382936044 1481860 986 6785 6683 477367350 88280508 0 78412 0 22978423 266 47 7409042 8 98452 437468733 0 909816 426136882 38 851 22645 387376803 0 32419 45 884 35 477851795 68713 6242 89402749 0 0 292244 605599 471...

output:

447795610
14292334
96619037
930487124

result:

ok 4 lines