QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#734382#9543. Good PartitionsYoimiyaWA 183ms20600kbC++202.0kb2024-11-11 09:35:142024-11-11 09:35:14

Judging History

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

  • [2024-11-11 09:35:14]
  • 评测
  • 测评结果:WA
  • 用时:183ms
  • 内存:20600kb
  • [2024-11-11 09:35:14]
  • 提交

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] ? fact[tree[1].v] : fact[n]) << 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] ? fact[tree[1].v] : fact[n]) << 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: 122ms
memory: 7460kb

input:

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

output:

1
2
3

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 121ms
memory: 7468kb

input:

1
1 1
2000000000
1 1999999999

output:

1
1

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 183ms
memory: 20600kb

input:

1
200000 200000
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
...

result:

wrong answer 2nd lines differ - expected: '200000', found: '160'