跳到正文

chenjialang2024

1615372

这个家伙很勤奋,什么也没有留下

这是 2026年10月22日 存档的第 1 版,不是当前版本。查看当前版本

资料、奖项与版本

资料

编号
1615372
抓取

奖项

2025 CSP-J
一等奖
2025 CSP-S
二等奖

版本

  1. v3当前
  2. v2
  3. v1
C++
for(int i=0;i<la;i++){
		int j=i+1;
		while(p[j-1])j=p[j-1];
		if(p[i])p[i]=j;	//路径压缩 
		sum+=i+1-j;
		
	}
C++
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
const int mod=998244353;
int n,m;
ll ans;
int fa[N];
struct Node{
	int l,r;
}a[N];
int find(int x){
	if(fa[x]==x)return fa[x];
	return fa[x]=find(fa[x]);
}
ll s(int g){
	if(g==1)return 2;
	ll ans=s(g>>1);
	ans=(ans*ans)%mod;
	if(g&1)ans=(ans*2)%mod;
	return ans;
}
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		a[i].l=u;a[i].r=v;
	}
	int cnt=0;
	for(int i=m;i>=1;i--){
		int rx=find(a[i].l);
		int ry=find(a[i].r);
		if(rx==ry)continue;
		else if(cnt!=n-2){
			cnt++;
			fa[rx]=ry;
			continue;
		}
		ans=(ans+s(i))%mod;
	}
	cout<<ans%mod;
	return 0;
}

思顿密码:2013212zmm
C++
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,ans;
signed main(){
	cin>>n;
	ans=(ll)(2*n/7)-(ll)ceil(n/4.0)+1;
	if(ans<=0)cout<<"No Answer.";
	else cout<<ans;
	return 0;
} 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,ans;
signed main(){
	cin>>n;
	ans=(ll)(2*n/7)-(ll)ceil(n/4.0)+1;
	if(ans<=0)cout<<"No Answer.";
	else cout<<ans;
	return 0;
} 
C++
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
const int M=1e6+5;
int n,m,p,t,ss,tt;
int a[N],e[N];
int b[N],bb[M];
struct Node{
	int l,r,t,id;
}g[N];
struct str{
	int p,c;
}s[N];
bool cmp(Node x,Node y){
	if(b[x.l]!=b[y.l])return b[x.l]<b[y.l];
	if(b[x.r]!=b[y.r])return b[x.r]<b[y.r];
	return x.t<y.t;
}
void add(int x){
	bb[a[x]]++;
	if(bb[a[x]]==1)t++;
}
void del(int x){
	bb[a[x]]--;
	if(bb[a[x]]==0)t--;
}
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	int now=pow(n,2.0/3.0);
	int o=n/now;
	if(n%now!=0)o++;
	for(int i=1;i<=o;i++){
		for(int j=now*(i-1)+1;j<=min(now*i,n);j++){
			b[j]=i;
		}
	}
	for(int i=1;i<=m;i++){
		char sx;
		int x,y;
		cin>>sx;
		scanf("%d %d",&x,&y);
		if(sx=='Q'){
			g[++tt].l=x;g[tt].r=y;g[tt].t=ss;g[tt].id=tt;
		}
		else{
			ss++;
			s[ss].p=x;s[ss].c=y;
		}
	}
	sort(g+1,g+1+tt,cmp);
	bb[0]=3;
	int l=g[1].r+1,r=g[1].r,time=0;
	for(int i=1;i<=tt;i++){
		while(l<g[i].l)del(l++);
		while(l>g[i].l)add(--l);
		while(r<g[i].r)add(++r);
		while(r>g[i].r)del(r--);
		while(time<g[i].t){
			time++;
			if(l<=s[time].p&&s[time].p<=r){
				bb[a[s[time].p]]--;
				if(bb[a[s[time].p]]==0)t--;
				bb[s[time].c]++;
				if(bb[s[time].c]==1)t++;
			}
			swap(a[s[time].p],s[time].c);
		}
		while(time>g[i].t){
			if(l<=s[time].p&&s[time].p<=r){
				bb[a[s[time].p]]--;
				if(bb[a[s[time].p]]==0)t--;
				bb[s[time].c]++;
				if(bb[s[time].c]==1)t++;
			}
			time--;
			swap(a[s[time].p],s[time].c);
		}
		e[g[i].id]=t;
	}
	for(int i=1;i<=tt;i++)printf("%d\n",e[i]); 
	return 0;
}