QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#723368#9543. Good PartitionsreisentyanWA 305ms19812kbC++144.5kb2024-11-07 21:58:012024-11-07 21:58:02

Judging History

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

  • [2024-11-07 21:58:02]
  • 评测
  • 测评结果:WA
  • 用时:305ms
  • 内存:19812kb
  • [2024-11-07 21:58:01]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stdio.h>
#include<stack>
#include<list>
using namespace std;
#define ffp(x,y,z) for(ll (x) = (y);(x)<=(z);(x++))
#define ffs(x,y,z) for(ll (x) = (y);(x)>=(z);(x--))
#define pii pair<ll ,ll> 
#define ll long long int
#define endl '\n'
#define q_ (qd())
#define lon(x) (R[x]-L[x]+1)
const double ex = 1e-7;
const int iINF = 0x3f3f3f3f;
const ll lINF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 998244353;
long long int qd() {
	long long w = 1, c, ret;
	while ((c = getchar()) > '9' || c < '0')
		w = (c == '-' ? -1 : 1); ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		ret = ret * 10 + c - '0';
	return ret * w;
}
ll qs(ll a, ll b)
{
	ll bei = a;
	a = 1;
	while (b)
	{
		if (b & 1) { a = a * bei % MOD; }
		bei = bei * bei % MOD;
		b >>= 1;
	}
	return a;
}
ll inv(ll a)
{
	return qs(a, MOD - 2);
}
static ll Max(ll a1 = -lINF, ll a2 = -lINF, ll a3 = -lINF, ll a4 = -lINF, ll a5 = -lINF)
{
	return max(max(max(max(a1, a2), a3), a4), a5);
}
static ll Min(ll a1 = lINF, ll a2 = lINF, ll a3 = lINF, ll a4 = lINF, ll a5 = lINF)
{
	return min(min(min(min(a1, a2), a3), a4), a5);
}

ll tr[200200 << 2];//值是gcd
int L[200200 << 2];//规定1为正
int R[200200 << 2];
int ml[200200 << 2];//区间左边,向右
int mr[200200 << 2];//区间右边,向左有多少个正号
ll num[200200];

ll gcd(ll a, ll b) {
	if (a % b == 0)
		return b;
	else
		return (gcd(b, a % b));
}

void updata(int now)
{
	//两个子树都是空的
	if (ml[now * 2] == lon(now * 2) && ml[now * 2 + 1] == lon(now * 2 + 1))
	{
		if (tr[now * 2] && tr[now * 2 + 1]) { tr[now] = gcd(tr[now * 2], tr[now * 2 + 1]); }
		else if (tr[now * 2] || tr[now * 2 + 1]) { tr[now] = tr[now * 2] + tr[now * 2 + 1]; }
		else tr[now] = 0;
		mr[now] = ml[now] = lon(now);
	}
	//左边没点,右边有点
	if (ml[now * 2] == lon(now * 2) && ml[now * 2 + 1] != lon(now * 2 + 1))
	{
		if (tr[now * 2] && tr[now * 2 + 1]) { tr[now] = gcd(tr[now * 2], tr[now * 2 + 1]); }
		else if (tr[now * 2] || tr[now * 2 + 1]) { tr[now] = tr[now * 2] + tr[now * 2 + 1]; }
		else tr[now] = 0;
		mr[now] = mr[now * 2 + 1];
		ml[now] = lon(now*2) + ml[now * 2 + 1];
	}
	//左边有点,右边没点
	if (ml[now * 2] != lon(now * 2) && ml[now * 2 + 1] == lon(now * 2 + 1))
	{
		if (tr[now * 2] && tr[now * 2 + 1]) { tr[now] = gcd(tr[now * 2], tr[now * 2 + 1]); }
		else if (tr[now * 2] || tr[now * 2 + 1]) { tr[now] = tr[now * 2] + tr[now * 2 + 1]; }
		else tr[now] = 0;

		ml[now] = ml[now * 2];
		mr[now] = mr[now * 2] + lon(now * 2 + 1);
	}
	//两边都有点
	if (ml[now * 2] != lon(now * 2) && ml[now * 2 + 1] != lon(now * 2 + 1))
	{
		mr[now] = mr[now * 2 + 1];
		ml[now] = ml[now * 2];
		tr[now] = mr[now * 2] + ml[now * 2 + 1]+1;
		if (tr[now * 2]) { tr[now] = gcd(tr[now], tr[now * 2]); }
		if (tr[now * 2 + 1]) { tr[now] = gcd(tr[now], tr[now * 2 + 1]); }
	}
	if (now == 1)
	{
		//tr[now] = gcd(tr[now * 2], tr[now * 2 + 1]);
		if (tr[now])
		{
			tr[now] = gcd(tr[now], ml[now]);
		}
		else
		{
			tr[now] = ml[now];
		}
	}
}

void bud(int now, int l, int r)
{//规定1为正

	L[now] = l;
	R[now] = r;

	if (l == r)
	{
		if (num[l-1] <= num[l])
		{//当前是
			ml[now] = mr[now] = 1;
		}
		else
		{
			ml[now] = mr[now] = 0;
		}
		return;
	}

	int med = (l + r) >> 1;
	bud(now * 2, l, med);
	bud(now * 2 + 1, med + 1, r);
	updata(now);
}
void ask(int now,int l,int r,int p,ll v)
{
	if (l == r) 
	{
		num[l] = v;
		if (num[l - 1] <= num[l])
		{//当前是
			ml[now] = mr[now] = 1;
		}
		else
		{
			ml[now] = 0;
			mr[now] = 0;
		}
		return;
	}
	int med = (l + r) >> 1;
	if (p <= med)ask(now * 2, l, med, p, v);
	if (p > med)ask(now * 2 + 1, med + 1, r, p, v);
	updata(now);
}

ll getans(ll x)
{
	ll k = 0;
	for (ll i = 1; i * i <= x; i++)
	{
		if (x % i == 0)
		{
			if (x / i != i) { k += 2; }
			else { k += 1; }
		}
	}
	return k;
}

int main()
{
	int t = q_;
	while (t--)
	{
		ll n = q_;
		ll q = q_;
		ffp(i, 1, n)
		{
			num[i] = q_;
		}
		bud(1, 1, n);
		num[0] = 0;
		if (tr[1] && tr[1]!= n)
		{
			cout << getans(tr[1]) << endl;
		}
		else { cout << n << endl; }
		ffp(i, 1, q)
		{
			ll p = q_;
			ll v = q_;
			ask(1, 1, n, p, v);
			if (p != n) 
			{ ask(1, 1, n, p + 1, num[p + 1]); }

			if (tr[1] && tr[1]!=n)
			{
				cout << getans(tr[1]) << endl;
			}
			else { cout << n << endl; }
		}
	}
	
	return 0;
}

详细

Test #1:

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

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: 2ms
memory: 9720kb

input:

1
1 1
2000000000
1 1999999999

output:

1
1

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 176ms
memory: 19744kb

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

result:

ok 200001 lines

Test #4:

score: 0
Accepted
time: 67ms
memory: 19768kb

input:

1
200000 200000
200001 200000 199999 199998 199997 199996 199995 199994 199993 199992 199991 199990 199989 199988 199987 199986 199985 199984 199983 199982 199981 199980 199979 199978 199977 199976 199975 199974 199973 199972 199971 199970 199969 199968 199967 199966 199965 199964 199963 199962 1999...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200001 lines

Test #5:

score: 0
Accepted
time: 305ms
memory: 19812kb

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:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 200001 lines

Test #6:

score: 0
Accepted
time: 2ms
memory: 11792kb

input:

2
2 2
17017 63462
2 94054
2 13504
8 8
14380 5840 34752 73602 60279 26105 44308 78318
7 8597
2 70671
6 56663
5 90093
5 96853
3 10700
1 76875
6 27325

output:

2
2
1
1
1
1
1
1
1
1
1
1

result:

ok 12 lines

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 11772kb

input:

10
9 15
850456 510799 912572 938543 215712 758501 850577 149454 330027
7 740992
7 73826
1 993823
7 143019
8 152824
2 109975
5 151989
7 851016
3 157534
8 491512
6 987473
7 272348
3 842756
4 278214
5 707564
10 17
494099 922564 124251 422938 100551 915266 18436 74858 885629 897256
8 798574
7 49544
7 83...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

wrong answer 63rd lines differ - expected: '2', found: '1'