跳到正文

个人记录

二中T2

WAWA_QWQ约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年2月8日
收录
2025年12月12日
更新
2026年11月15日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=200005;
int n,Q,a[maxn],zs[maxn],cnt,ans;
unordered_map<int,int> mp[500];
multiset<int> Max[500];
int read(){
	char ch=getchar();int ret=0,f=1;
	while(ch<'0'||ch>'9'){if(ch=='-') f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9') ret=ret*10+(ch&15),ch=getchar();
	return ret*f;
}
int get(int x){return (*(--Max[x].end()));}
void eras(int x,int v){Max[x].erase(Max[x].find(v));}
signed main(){
	n=read(),Q=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int k=1;k<n;k++){
		if(n%k) continue;
		zs[++cnt]=k;
		for(int i=0;i<k;i++) mp[cnt][i%k]=0;
		for(int i=1;i<=n;i++) mp[cnt][i%k]+=a[i];
		for(int i=0;i<k;i++) Max[cnt].insert(mp[cnt][i]);
	}
	ans=0;
	for(int i=1;i<=cnt;i++) ans=max(ans,zs[i]*get(i));
	printf("%lld\n",ans);
	while(Q--){
		int id=read(),v=read();
		for(int i=1;i<=cnt;i++){
			eras(i,mp[i][id%zs[i]]);Max[i].insert(mp[i][id%zs[i]]-a[id]+v);
			mp[i][id%zs[i]]=mp[i][id%zs[i]]-a[id]+v;
		}
		ans=0;
		for(int i=1;i<=cnt;i++) ans=max(ans,zs[i]*get(i));
		printf("%lld\n",ans);
		a[id]=v;
	}
	return 0;
}
原文