QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#734366#9543. Good PartitionsYoimiyaWA 122ms8188kbC++201.9kb2024-11-11 09:25:422024-11-11 09:25:42

Judging History

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

  • [2024-11-11 09:25:42]
  • 评测
  • 测评结果:WA
  • 用时:122ms
  • 内存:8188kb
  • [2024-11-11 09:25:42]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n' 
using namespace std;
using ll = long long;
typedef pair<ll, ll> PII;
const ll N = 2e5 + 5;
const ll INF = 1e18;

typedef struct INFO {
    ll l, r, v;
}info;

info tree[N * 4];
ll n, q, a[N], fact[N];

void divide(ll x){
    vector <PII> v;
    ll n = x;
    for (ll i = 2; i <= x / i; i++){
        if (x % i == 0){
            ll cnt = 0;
            while(x % i == 0){
                x /= i;
                cnt++;
            }
            v.push_back({i, cnt});
        }
    }
    if (x > 1) v.push_back({x, 1});
    fact[n] = 1;
    for (auto &i: v) fact[n] *= (i.second + 1);
}

ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}

void build(ll p, ll l, ll r) {
    tree[p].l = l;
    tree[p].r = r;
    tree[p].v = 0;
    if (l == r) return;
    ll mid = (l + r) >> 1;
    build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);
}

void update(ll p, ll x, ll k) {
    if (tree[p].l == tree[p].r) {
        tree[p].v = k;
        return;
    }

    ll mid = (tree[p].l + tree[p].r) >> 1;
    ll ls = p << 1, rs = p << 1 | 1;
    if (x <= mid) update(ls, x, k);
    else update(rs, x, k);

    tree[p].v = gcd(tree[ls].v, tree[rs].v);
}

void solve() {
    cin >> n >> q;
    build(1, 1, n);
    for (ll i = 1; i <= n; i++)
        cin >> a[i];
    for (ll i = 1; i < n; i++) {
        if (a[i] > a[i + 1])
            update(1, i, i);
    }
    cout << fact[tree[1].v] << endl;
    while (q--) {
        ll p, v; cin >> p >> v;
        a[p] = v;
        if (a[p] >= a[p - 1])
            update(1, p - 1, 0);
        if (p < n && a[p] > a[p + 1])
            update(1, p, p);
        cout << fact[tree[1].v] << endl;
    }
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    for (ll i = 1; i <= N; i++)
        divide(i);
    ll t; cin >> t;
    while (t--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 118ms
memory: 8188kb

input:

1
5 2
4 3 2 6 1
2 5
3 5

output:

1
2
3

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 122ms
memory: 7888kb

input:

1
1 1
2000000000
1 1999999999

output:

0
0

result:

wrong answer 1st lines differ - expected: '1', found: '0'