QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748169#9543. Good PartitionsYg6189ML 1ms5980kbC++142.0kb2024-11-14 19:33:162024-11-14 19:33:17

Judging History

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

  • [2024-11-14 19:33:17]
  • 评测
  • 测评结果:ML
  • 用时:1ms
  • 内存:5980kb
  • [2024-11-14 19:33:16]
  • 提交

answer

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

#define int long long
#define il inline
#define rd read()
#define ls (p << 1)
#define rs (p << 1 | 1)

const int inf = 10e17 + 100, L = 2e5 + 100, mod = 1e9 + 7;
int n, q;
int a[L], s[L << 2];

il int read()
{
	int res = 0, f = 1;
	char c = getchar();
	while(c < '0' || c >'9')
	{
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9')
	{
		res = res * 10 + c - 48;
		c = getchar();
	}
	return res * f; 
}

il int gcd(int x, int y)
{
	return __gcd(x, y);
}

il void pushUp(int p)
{
	s[p] = gcd(s[ls], s[rs]);
}

il void build(int p = 1, int l = 1, int r = n - 1)
{
	if(l == r) 
	{
		s[p] = (a[l] > a[l + 1] || l == n) ? l : 0;
		return;
	}
	int mid = (l + r) / 2;
	build(ls, l, mid), build(rs, mid + 1, r);
	pushUp(p);
}

il void update(int pos, int x, int p = 1, int l = 1, int r = n - 1)
{
	if(l == r) 
	{
		s[p] = x; return;
	}
	int mid = (l + r) / 2;
	if(pos <= mid) update(pos, x, ls, l, mid);
	else update(pos, x, rs, mid + 1, r);
	pushUp(p);
}

signed main() {
	// freopen("test.out", "w", stdout);
	int t = rd;
	while(t --)
	{
		n = rd, q = rd;
		for(int i = 1; i <= n; ++ i) a[i] = rd;
		build();
		int ans = s[1], num = 0;
		for(int i = 1; i * i <= ans; ++ i)
		{
			if(ans % i == 0) 
			{
				num ++;
				if(ans / i != i) num ++;
			}
		}
		printf("%lld\n", num);
		int p, x;
		while(q --)
		{
			p = rd, x = rd;
			if(p > 1 && a[p] >= a[p - 1] && x < a[p - 1]) update(p - 1, p - 1);
			if(p > 1 && a[p] < a[p - 1] && x >= a[p - 1]) update(p - 1, 0);
			if(p < n && a[p] <= a[p + 1] && x > a[p + 1]) update(p, p);
			if(p < n && a[p] > a[p + 1] && x <= a[p + 1]) update(p, 0);
			a[p] = x;
			ans = s[1], num = 0;
			// cout << "test " << ans << endl;
			for(int i = 1; i * i <= ans; ++ i)
			{
				if(ans % i == 0) 
				{
					num ++;
					if(ans / i != i) num ++;
				}
			}
			printf("%lld\n", num);
		}
	}
    return 0;
}

/*
 1
 5 2
 4 3 2 6 1
 2 5
 3 5
*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5980kb

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
Memory Limit Exceeded

input:

1
1 1
2000000000
1 1999999999

output:


result: