QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722237#9543. Good Partitionsfosov#RE 0ms3676kbC++171.7kb2024-11-07 18:15:092024-11-07 18:15:10

Judging History

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

  • [2024-11-07 18:15:10]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3676kb
  • [2024-11-07 18:15:09]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;

#define ll long long 
#define INF 0x3f3f3f3f
#define LNF 0x3f3f3f3f3f3f3f3fll
#define MOD 998244353
#define pii pair<int, int>

#define N 100010

set<int> factors(int x) {
    set<int> res;
    for (int i = 1; i <= sqrt(x); ++ i) {
        if (x % i == 0) {
            res.insert(i);
            res.insert(x/i);
        }
    }
    return res;
}

int cnt[N], a[N];

int main() {
#ifdef TEST
    freopen("zz.in", "r+", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t; cin >> t;
    while (t --) {
        set<int> s;

        int n, q; cin >> n >> q;
        for (int i = 0; i <= n; ++ i) cnt[i] = 0;
        for (int i = 1; i <= n; ++ i) cin >> a[i];

        auto add = [&](int i) {
            assert(!s.count(i));
            for (auto x : factors(i)) ++ cnt[x];
            s.insert(i);
        };

        auto rmv = [&](int i) {
            assert(s.count(i));
            for (auto x : factors(i)) -- cnt[x];
            s.erase(i);
        };

        auto get = [&]() {
            if (s.size() == 0) return n;
            int res = 0;
            for (auto x : factors(*s.begin())) res += (cnt[x] == s.size());
            return res;
        };

        for (int i = 1; i < n; ++ i) if (a[i] > a[i+1]) add(i);
        cout << get() << '\n';

        while (q --) {
            int p, v; cin >> p >> v;
            if (s.count(p)) rmv(p);
            if (s.count(p-1)) rmv(p-1);
            a[p] = v;
            if (p < n && a[p] > a[p+1]) add(p);
            if (p > 1 && a[p-1] > a[p]) add(p-1);
            cout << get() << '\n';
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3676kb

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: 0ms
memory: 3600kb

input:

1
1 1
2000000000
1 1999999999

output:

1
1

result:

ok 2 lines

Test #3:

score: -100
Runtime Error

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:


result: