小萌新96pts求助卡常,玄二关
查看原帖
小萌新96pts求助卡常,玄二关
1539991
__ZYX__楼主2025/2/3 19:43

rt,卡了七八十发了,孩子人快疯了。

得分在 849684-96 分之间游荡,萌新知道的所有卡常技巧除了循环展开全上了。

#include<bits/stdc++.h>
#define push_back emplace_back
using namespace std;
const int N=1200010,mod=1e9+7; 
vector<int> vx[N],vy[N];
char *p1,*p2,buf[100000];
#define nc() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
int read(){
    int x=0,f=1;
    char ch=nc();
    while(ch<48||ch>57){
        if(ch=='-')f=-1;
        ch=nc();
    }
    while(ch>=48&&ch<=57)
        x=x*10+ch-48,ch=nc();
   	return x*f;
}
long long quick_pow(long long a,long long b){
	long long ans=1;
	while(b>0)b%2==0?((a*=a)%=mod,b/=2):((ans*=a)%=mod,b--);
	return ans;
}
int n,q,cnt[N],a[N],b[N];
long long sum[N],flag[N],c[N];
int main(){
	n=read(),q=read();
	int B(sqrt(n/30));
	for(int i=1;i<=n;++i)
		a[i]=read(),b[i]=read(),c[i]=read(),cnt[b[i]]++;
	for(int i=1;i<=n;++i){
		flag[i]=1;
		if(cnt[b[i]]>=B){
			vx[a[i]].push_back(i);
			(sum[b[i]]+=c[i])%=mod;
		}
		else vy[b[i]].push_back(i);
	}
	while(q--){
		int op(read());
		if(op==1){
			int x(read());
			for(int i=0,t;i<vx[x].size();++i){
				t=vx[x][i];
				sum[b[t]]=(sum[b[t]]+c[t]*c[t]-c[t])%mod;
				c[t]=c[t]*c[t]%mod;
			}
			flag[x]=(flag[x]*2ll)%(mod-1ll);
		}
		else{
			int y(read());
			long long temp(sum[y]);
			for(int i=0,t;i<vy[y].size();++i){
				t=vy[y][i];
				temp+=quick_pow(c[t],flag[a[t]]);
			}
			cout<<(temp+mod)%mod<<'\n';
		}
	}
	return 0;
}
2025/2/3 19:43
加载中...