QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745854#9543. Good PartitionsP3KOWA 240ms10716kbC++171.9kb2024-11-14 12:02:082024-11-14 12:02:09

Judging History

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

  • [2024-11-14 12:02:09]
  • 评测
  • 测评结果:WA
  • 用时:240ms
  • 内存:10716kb
  • [2024-11-14 12:02:08]
  • 提交

answer

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

const int MAXN=2e5+5;

int n,q,a[MAXN],d[MAXN];
int prime[MAXN],num[MAXN],v[MAXN],cnt;
struct Seg{
	int g;
}tr[MAXN*4];

void getfac(int x){
	num[0]=x,num[1]=1;
	for(int i=2;i<=x;i++){
		if(!v[i]){
			prime[++cnt]=i,num[i]=2,v[i]=1;
		}
		for(int j=1;j<=cnt&&prime[j]*i<=x;j++){
			if(i%prime[j]==0){
				v[i*prime[j]]=v[i]+1;
				num[i*prime[j]]=num[i]/(v[i]+1)*(v[i*prime[j]]+1);
				break;
			}else{
				v[i*prime[j]]=1;
				num[i*prime[j]]=num[i]*2;
			}
		}
	}
}

int gcd(int x,int y){
	return y==0?x:gcd(y,x%y);
}

void pushup(int p){
	tr[p].g=gcd(tr[p<<1].g,tr[p<<1|1].g);
}

void build(int p,int l,int r){
	if(l==r){
		tr[p]={d[l]};
		return;
	}
	int mid=l+r>>1;
	build(p<<1,l,mid);
	build(p<<1|1,mid+1,r);
	pushup(p);
}

void insert(int p,int l,int r,int tag,int v){
	if(l==r){
		tr[p].g=v;
		return;
	}
	int mid=l+r>>1;
	if(tag<=mid)insert(p<<1,l,mid,tag,v);
	else insert(p<<1|1,mid+1,r,tag,v);
	pushup(p);
}

int query(int p,int s,int t,int l,int r){
	if(s>=l&&t<=r)return tr[p].g;
	int mid=s+t>>1;
	int ans=0;
	if(l<=mid)ans=gcd(query(p<<1,s,mid,l,r),ans);
	if(r>mid)ans=gcd(query(p<<1|1,mid+1,t,l,r),ans);
	return ans;
}

void input(){
	cin>>n>>q;
	for(int i=1;i<=n;i++)cin>>a[i];
}

void solve(){
	input();
	if(n==1){
		for(int i=0;i<=q;i++)
			cout<<1<<"\n";
		return;
	}
	for(int i=1;i<n;i++){
		if(a[i+1]<a[i])d[i]=i;
		else d[i]=0;
	}
	n--;
	build(1,1,n);
	cout<<num[query(1,1,n,1,n)]<<"\n";
	for(int i=1;i<=q;i++){
		int p,v;cin>>p>>v;
		a[p]=v;
		if(p>1){
			if(a[p]>=a[p-1])insert(1,1,n,p-1,0);
			else insert(1,1,n,p-1,p-1);
		}
		if(p<=n){
			if(a[p]<=a[p+1])insert(1,1,n,p,0);
			else insert(1,1,n,p,p);
		}
		cout<<num[query(1,1,n,1,n)]<<"\n";
	}
}

int main(){
	getfac(2e5);
	int t;cin>>t;
	while(t--){
		solve();	
	}
}
/*
1
5 2
4 3 2 6 1
2 5
3 5
*/
/*
1
5 1
1 2 3 4 5
5 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

1
1 1
2000000000
1 1999999999

output:

1
1

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 189ms
memory: 10716kb

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: 191ms
memory: 10592kb

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: 240ms
memory: 10628kb

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: -100
Wrong Answer
time: 2ms
memory: 7640kb

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:

200000
200000
1
1
1
1
1
1
1
1
1
1

result:

wrong answer 1st lines differ - expected: '2', found: '200000'