QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#748786#9543. Good PartitionsQingTian#WA 389ms33860kbC++202.9kb2024-11-14 21:26:412024-11-14 21:26:42

Judging History

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

  • [2024-11-14 21:26:42]
  • 评测
  • 测评结果:WA
  • 用时:389ms
  • 内存:33860kb
  • [2024-11-14 21:26:41]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define debug(x) cerr <<#x <<" = " << x << endl
#define fi first
#define se second
using namespace std;
const int N = 2e5 +10;
int T= 1;

int n, q, a[N];

struct node {
    int val = -1, g = -1;
    int fl = 0;
    int lb = 0, rb = 0;
    int st = 0, ed = 0;
};
node tr[N << 2];

node acc(node l, node r){
    node res;
    res.st = l.st;
    res.ed = r.ed;
    res.rb = r.rb;
    res.lb = l.lb;
    int u = a[l.ed], v = a[r.st];
    int cg = -1;
    if (u <= v){
        int len = r.lb - l.rb + 1;
        if (r.lb != r.ed && l.rb != l.st){
            cg = len;
        }
        else if (r.lb != r.ed){
            res.lb = r.lb;
        }
        else if (l.rb != l.st){
            res.rb = l.rb;
        }
        else{
            res.lb = r.lb;
            res.rb = l.rb;
        }
    }
    else{
        int llen = l.ed - l.rb + 1;
        int rlen = r.lb - r.st + 1;
        if (l.rb != l.st){
            if (cg == -1) cg = llen;
            else cg = __gcd(cg, llen);
        }
        if (r.lb != r.ed){
            if (cg == -1) cg = rlen;
            else cg = __gcd(cg, rlen);
        }
    }
    if (r.g != -1){
        if (cg != -1) cg = __gcd(cg, r.g);
        else cg = r.g ;
    }
    if (l.g != -1){
        if (cg != -1) cg = __gcd(cg, l.g);
        else cg = l.g;
    }
    res.g = cg;
    return res;
}

void bd(int p, int cl, int cr){
    if (cl == cr){
        tr[p].val = a[cl];
        tr[p].g = -1;
        tr[p].lb = tr[p].rb = tr[p].st = tr[p].ed = cl;
        if (cl == n) tr[p].fl = 1;
        return;
    }
    int mid = cl + cr >> 1;
    bd(p << 1, cl, mid);
    bd(p << 1 | 1, mid + 1, cr);
    tr[p] = acc(tr[p << 1], tr[p << 1 | 1]);
}

void upd(int x, int k, int p, int cl, int cr){
    if (cl == cr){
        a[cl] = k;
        tr[p].val = k;
        tr[p].g = -1;
        tr[p].lb = tr[p].rb = tr[p].st = tr[p].ed = cl;
        if (cl == n) tr[p].fl = 1;
        return;
    }
    int mid = cl + cr >> 1;
    if (x <= mid) upd(x, k, p << 1, cl, mid);
    else upd(x, k, p << 1 | 1, mid + 1, cr);
    tr[p] = acc(tr[p << 1], tr[p << 1 | 1]);
}

int qry(){
    int len = tr[1].lb;
    if (tr[1].g == -1) return len;
    return __gcd(len, tr[1].g);
}

void solve(){
	cin >> n >> q;
	for (int i = 1; i <= n; i ++) cin >> a[i];
	bd(1, 1, n);
    auto get = [&](int x) -> int {
    	int res = 0;
    	for (int i = 1; i * i <= x; i ++) if (x % i == 0){
    		if (i * i == x) res ++;
    		else res += 2;
    	}
    	return res;
    };
    cout << get(qry()) << endl;
    while (q --){
    	int x, k;
    	cin >> x >> k;
    	upd(x, k, 1, 1, n);
    	cout << get(qry()) << endl;
    }
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> T;
	while(T --) solve();

	return 0;
}
/*
1
5 2
4 3 2 6 1
2 5
3 5
*/


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3656kb

input:

1
1 1
2000000000
1 1999999999

output:

1
1

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 389ms
memory: 33860kb

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
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42
160
42...

result:

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