QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#735028#9543. Good PartitionsCCFRE 228ms16632kbC++203.1kb2024-11-11 16:44:352024-11-11 16:44:36

Judging History

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

  • [2024-11-11 16:44:36]
  • 评测
  • 测评结果:RE
  • 用时:228ms
  • 内存:16632kb
  • [2024-11-11 16:44:35]
  • 提交

answer

#include<bits/stdc++.h>
#include<numeric>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define fs first
#define sc second
#define pb push_back
#define epb emplace_back
#define endl
#define SZ(X) (int)((X).size())
template<typename T>T mabs(T x){return x>=0?x:-x;}
const int N=1.1e6,mod=998244353;
int a[N],n;
struct trar{
	ll tree[N];
	#define lb(i) ((i)&-(i))
	void _add(int i,ll x){
		for(;i<=n;i+=lb(i))tree[i]+=x;
	}
	ll _sum(int r){
		assert(r>0);
		ll res=0;
		for(;r>0;r^=lb(r))res+=tree[r];
		return res;
	}
	ll query(int i){
		return _sum(i);
	}
	void modify(int l,int r,ll x){
		assert(l<=r);
		ll adt=x;//-query(l);
		_add(l,adt);
		_add(r+1,-adt);
	}
}L,R;
int ss[N];
void work(){
	int q;
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	int sq=sqrt(n+1);
	map<int,int>bl;
	auto era=[&](int x){
		//cerr<<"ERA"<<x<<"#\n";
		assert(bl[x]>0);
		if(bl[x]>1)bl[x]--;
		else if(bl[x]==1)bl.erase(x);
	};
	auto getans=[&](){
		if(bl.size()<=sq){
			if(bl.size()==0)return n;
			int res=bl.begin()->fs;
			for(auto e:bl)res=gcd(res,e.fs);
			return ss[res];
		}
		else return 1;
	};
	
	int las=1;
	for(int i=2;i<=n+1;i++){
		if(a[i]<a[i-1]){
			int l=las,r=i-1;
			L.modify(l,r,l);
			R.modify(l,r,r);
			if(r<n)bl[r-l+1]++;
			las=i;
		}
	}
	cout<<getans()<<"\n";
	
	// for(int i=1;i<=n;i++)
		// cerr<<'('<<L.query(i)<<','<<R.query(i)<<")";cerr<<"\n";
	// for(auto e:bl)
		// cerr<<'('<<e.fs<<','<<e.sc<<")";cerr<<"\n";

	
	a[0]=2e9+1;
	for(int j=1;j<=q;j++){
		int i,x;
		scanf("%d%d",&i,&x);
		set<pii>tmp;
		for(int k=max(i-1,1);k<=min(i+1,n);k++)
			tmp.insert(pii(L.query(k),R.query(k)));
		for(auto e:tmp){
			if(e.sc<n)era(e.sc-e.fs+1);
		}
		//cerr<<"$";
		
		a[i]=x;
		vector<pii>temp;
		auto update=[&](int l,int r){
			//cerr<<"up#"<<l<<" "<<r<<"\n";//
			temp.pb(pii(l,r));
		};
		int l,r;
		if(a[i-1]<=x&&x<=a[i+1]){
			l=L.query(i-1),r=R.query(i+1);
			update(l,r);
		}
		else if(a[i-1]<=x){
			l=L.query(i-1),r=i;
			update(l,r);
			if(i<n){
				l=i+1,r=R.query(i+1);
				update(l,r);
			}
		}
		else if(x<=a[i+1]){
			l=i,r=R.query(i+1);
			update(l,r);
			if(i>1){
				l=L.query(i-1),r=i-1;
				update(l,r);
			}
		}
		else{
			if(i<n){
				l=i+1,r=R.query(i+1);
				update(l,r);
			}
			if(i>1){
				l=L.query(i-1),r=i-1;
				update(l,r);
			}
			update(i,i);
		}
		for(auto e:tmp)
			L.modify(e.fs,e.sc,-e.fs),R.modify(e.fs,e.sc,-e.sc);
		
		// for(int i=1;i<=n;i++)
			// cerr<<'('<<L.query(i)<<",_"<<R.query(i)<<")";cerr<<"\n";
		
		
		for(auto e:temp){
			l=e.fs,r=e.sc;
			L.modify(l,r,l),R.modify(l,r,r);
			if(r<n)bl[r-l+1]++;
		}
			
		cout<<getans()<<"\n";
		
		////
		// for(int i=1;i<=n;i++)
			// cerr<<'('<<L.query(i)<<','<<R.query(i)<<")";cerr<<"\n";
		// for(auto e:bl)
			// cerr<<'('<<e.fs<<';'<<e.sc<<")";cerr<<"\n";
	}
	for(int i=1;i<=n;i++)L.tree[i]=R.tree[i]=0;
}
int main(){
	for(int i=1;i<=2e5;i++){
		for(int j=1;j*j<=i;j++){
			if(i%j==0)ss[i]+=1+(j!=i/j);
		}
	}
	int t;
	scanf("%d",&t);
	while(t--)work();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 109ms
memory: 10800kb

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: 113ms
memory: 10604kb

input:

1
1 1
2000000000
1 1999999999

output:

1
1

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 212ms
memory: 16632kb

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: 228ms
memory: 14704kb

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: 204ms
memory: 14704kb

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: 114ms
memory: 10608kb

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
Runtime Error

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:


result: