跳到正文

mhs2023

1004505

始终相信,真远是真

在洛谷打开
资料、奖项与版本

资料

编号
1004505
抓取

奖项

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

海内存知己,天涯若比邻。——王勃

C++
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define INF 0x3f3f3f3f
#define endl '\n'
#define int ll
using namespace std;
ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while (ch<'0' or ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0' and ch<='9') x=x*10+(ll)(ch-'0'),ch=getchar();
	return x*f;
}
ll gcd(ll x,ll y){
	if (y==0) return x;
	return gcd(y,x%y);
}
ll qpow(ll x,ll y,ll mod){
	if (mod==-1)
		mod=2000000000000000000;
	ll ans=1;
	while (y){
		if (y&1) ans*=x,ans%=mod;
		x*=x;
		x%=mod;
		ans%=mod;
		y>>=1;
	}
	return ans;
}
const int N=2e5+5;
int n,m,val[N],dfn[N],low[N],cnt,col[N],colcnt,vis[N],sum[N],siz[N];
vector<int> e[N],a[N];
stack<int> st;
void tarjan(int u){
	dfn[u]=low[u]=++cnt;
	st.push(u);
	vis[u]=true;
	for (int v:e[u]){
		if (!dfn[v]){
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}
		else low[u]=min(low[u],dfn[v]);
	}
	if (dfn[u]==low[u]){
		col[u]=++colcnt;
		while (st.top()!=u){
			col[st.top()]=colcnt;
			vis[st.top()]=false;
			st.pop();
		}
		st.pop();
	}
	for (int i=1;i<=)
}
void solve(){
	n=read(),m=read();
	for (int i=1;i<=n;i++) val[i]=read();
	for (int i=1;i<=m;i++){
		int u=read(),v=read();
		e[u].push_back(v);
	}
	for (int i=1;i<=n;i++) if (!dfn[i]) tarjan(i);
	for (int i=1;i<=n;i++){
		siz[col[i]]++,sum[col[i]]+=val[i];
		for (int v:e[i]) if (col[i]!=col[v]) a[col[i]].push_back(col[v]);
	}
	
}
signed main(){
	// ios::sync_with_stdio(false);
	// cin.tie(0),cout.tie(0);
	// freopen("slice.in","r",stdin);
	// freopen("slice.out","w",stdout);
	ll t=read();
	while (t--) solve();
	return 0;
}

http://www.nflsoi.cc:20035/contest/2546/problem/4

C++
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define INF 0x3f3f3f3f
#define endl '\n'
#define int ll
using namespace std;
ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while (ch<'0' or ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0' and ch<='9') x=x*10+(ll)(ch-'0'),ch=getchar();
	return x*f;
}
ll gcd(ll x,ll y){
	if (y==0)
		return x;
	return gcd(y,x%y);
}
ll qpow(ll x,ll y,ll mod){
	if (mod==-1)
		mod=2000000000000000000;
	ll ans=1;
	while (y){
		if (y&1)
			ans*=x,ans%=mod;
		x*=x;
		x%=mod;
		ans%=mod;
		y>>=1;
	}
	return ans;
}
const int N=2e5+5;
int n,m,m1,m2,tim,a[N],b[N],zero[N],cnt[N],ans[N],s[N];
int block,l,r;
vector<int> num;
struct node{
	int l,r,tim,id;
}q[N];
struct node1{
	int pos,old,now;
}qq[N];
bool cmp(node x,node y){
	if (x.l/block!=y.l/block) return x.l<y.l;
	if (x.r/block!=y.r/block) return x.r<y.r;
	if ((x.r/block)&1) return x.tim<y.tim;
	return x.tim>y.tim;
}
void add(int pos){
	s[cnt[a[pos]]]--;
	if (cnt[a[pos]]>0 and s[cnt[a[pos]]]==0) zero[cnt[a[pos]]/block]++;
	cnt[a[pos]]++;
	s[cnt[a[pos]]]++;
	if (s[cnt[a[pos]]]==1) zero[cnt[a[pos]]/block]--;
}
void del(int pos){
	s[cnt[a[pos]]]--;
	if (s[cnt[a[pos]]]==0) zero[cnt[a[pos]]/block]++;
	cnt[a[pos]]--;
	s[cnt[a[pos]]]++;
	if (cnt[a[pos]]>0 and s[cnt[a[pos]]]==1) zero[cnt[a[pos]]/block]--;
}
void addtim(int pos){
	int p=qq[pos].pos;
	int oldv=qq[pos].old,newv=qq[pos].now;
	if(p<l or p>r){a[p]=newv;return;}
	a[p]=oldv;del(p);
	a[p]=newv;add(p);
}
void deltim(int pos){
	int p=qq[pos].pos;
	int oldv=qq[pos].old,newv=qq[pos].now;
	if(p<l or p>r){a[p]=oldv;return;}
	a[p]=newv;del(p);
	a[p]=oldv;add(p);
}
int query(){
	for (int i=0;i<(n+block-1)/block;i++)
		if (zero[i])
			for (int j=max(1ll,i*block);j<=min(n,(i+1)*block-1);j++)
				if (s[j]==0)
					return j;
}
void solve(){
	n=read(),m=read();
	for (int i=1;i<=n;i++) a[i]=b[i]=read(),num.push_back(a[i]);
	for (int i=1;i<=m;i++){
		int op=read();
		if (op==1) q[++m1].l=read(),q[m1].r=read(),q[m1].tim=tim,q[m1].id=m1;
		else qq[++m2].pos=read(),qq[m2].now=read(),qq[m2].old=b[qq[m2].pos],b[qq[m2].pos]=qq[m2].now,num.push_back(qq[m2].now),tim++;
	}
	sort(num.begin(),num.end());
	num.erase(unique(num.begin(),num.end()),num.end());
	for (int i=1;i<=n;i++) a[i]=lower_bound(num.begin(),num.end(),a[i])-num.begin();
	for (int i=1;i<=m2;i++) qq[i].old=lower_bound(num.begin(),num.end(),qq[i].old)-num.begin();
	for (int i=1;i<=m2;i++) qq[i].now=lower_bound(num.begin(),num.end(),qq[i].now)-num.begin();
	block=max(1ll,(ll)pow(n,2.0/3.0));
	sort(q+1,q+m1+1,cmp);
	for (int i=1;i<=n;i++) zero[i/block]++;
	l=1,r=0,tim=0;
	for (int i=1;i<=m1;i++){
		while (l<q[i].l) del(l++);
		while (l>q[i].l) add(--l);
		while (r<q[i].r) add(++r);
		while (r>q[i].r) del(r--);
		while (tim<q[i].tim) addtim(++tim);
		while (tim>q[i].tim) deltim(tim--);
		ans[q[i].id]=query();
	}
	for (int i=1;i<=m1;i++) printf("%lld\n",ans[i]);
}
signed main(){
	// ios::sync_with_stdio(false);
	// cin.tie(0),cout.tie(0);
	// freopen("mosquito.in","r",stdin);
	// freopen("mosquito.out","w",stdout);
	ll t=1;
	while (t--)
		solve();
	return 0;
}

https://www.luogu.com.cn/problem/CF402E

C++
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define INF 0x3f3f3f3f
#define endl '\n'
using namespace std;
ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while (ch<'0' or ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0' and ch<='9') x=x*10+(ll)(ch-'0'),ch=getchar();
	return x*f;
}
ll gcd(ll x,ll y){
	if (y==0)
		return x;
	return gcd(y,x%y);
}
ll po_w(ll x,ll y,ll mod){
	if (mod==-1)
		mod=2000000000000000000;
	ll ans=1;
	while (y){
		if (y&1)
			ans*=x,ans%=mod;
		x*=x;
		x%=mod;
		ans%=mod;
		y>>=1;
	}
	return ans;
}
int n,a[2005][2005],dfn[2005],low[2005],col[2005],cnt;
stuck<int> st;
void tarjan(int u){
    dfn[u]=low[u]=++cnt;
    st.push(u);
    for (int i=1;i<=n;i++){
        for (int j=1;j<=n;j++){
            
        }
    }
}
void solve(){
    n=read();
    for(int i=1;i<=n;i++)
        for (int j=1;j<=n;j++)
            a[i][j]=read(),a[i][j]=(a[i][j]>0?1:0);
    tarjan(1);
}
signed main(){
	// ios::sync_with_stdio(false);
	// cin.tie(0),cout.tie(0);
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
	ll t=1;
	while (t--)
		solve();
	return 0;
}

http://www.nflsoi.cc:20035/contest/2467/problem/2

C++
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define INF 0x3f3f3f3f
#define endl '\n'
using namespace std;
ll read(){
    ll x=0,f=1;
    char ch=getchar();
    while (ch<'0' or ch>'9') {if (ch=='-') f=-1;ch=getchar();}
    while (ch>='0' and ch<='9') x=x*10+(ll)(ch-'0'),ch=getchar();
    return x*f;
}
ll gcd(ll x,ll y){
    if (y==0)
        return x;
    return gcd(y,x%y);
}
ll po_w(ll x,ll y,ll mod){
    if (mod==-1)
        mod=2000000000000000000;
    ll ans=1;
    while (y){
        if (y&1)
            ans*=x,ans%=mod;
        x*=x;
        x%=mod;
        ans%=mod;
        y>>=1;
    }
    return ans;
}
int n,q,ans[3005][3005],pw[3005],hs[3005];
unordered_map<int,int> cnt;
const ll mod=1e9+7,base=233;
string a;
int f(int l,int r){
    return (hs[r]-hs[l-1]*pw[r-l+1]%mod+mod)%mod;
}
void solve(){
    cin>>n>>q>>a;
    a=" "+a;
    // pw[0]=1;
    // for (int i=1;i<=n;i++)
    //     pw[i]=pw[i-1]*base%mod;
    // for (int i=1;i<=n;i++)
    //     hs[i]=(hs[i-1]*base%mod+(ll)(a[i]-'a'))%mod;
    pw[0] = 1;
    for (int i = 1; i <= n; i++)
        pw[i] = pw[i - 1] * base % mod;

    // 2. 预处理字符串的前缀哈希值
    for (int i = 1; i <= n; i++)
        hs[i] = (hs[i - 1] * base % mod + (a[i] - 'a')) % mod;
    for (int i=1;i<=n;i++)
        printf("%d ",hs[i]);
    memset(ans,0,sizeof(ans));
    for (int i=1;i<=n;i++){
        cnt.clear();
        for (int j=1;j+i-1<=n;j++){
            int ha=f(j,j+i-1);
            int pas=cnt[ha];
            cnt[ha]=j;
            ans[j][j+i-1]++;
            ans[pas][j+i-1]--;
        }
    }
    for (int i=1;i<=n;i++){
        for (int j=1;j<=n;j++)
            printf("%d ",ans[i][j]);
        printf("\n");
    }
    for (int i=n;i>=1;i--)
        for (int j=1;j<=n;j++)
            ans[i][j]+=ans[i+1][j]+ans[i][j-1]-ans[i+1][j-1];
    while (q--){
        int l,r;
        cin>>l>>r;
        printf("%d\n",ans[l][r]);
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    ll t=1;
    // ll t=read();
    while (t--)
        solve();
    return 0;
}
C++
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define INF 0x3f3f3f3f
#define endl '\n'
using namespace std;
ll read(){
    ll x=0,f=1;
    char ch=getchar();
    while (ch<'0' or ch>'9') {if (ch=='-') f=-1;ch=getchar();}
    while (ch>='0' and ch<='9') x=x*10+(ll)(ch-'0'),ch=getchar();
    return x*f;
}
ll gcd(ll x,ll y){
    if (y==0)
        return x;
    return gcd(y,x%y);
}
ll po_w(ll x,ll y,ll mod){
    if (mod==-1)
        mod=2000000000000000000;
    ll ans=1;
    while (y){
        if (y&1)
            ans*=x,ans%=mod;
        x*=x;
        x%=mod;
        ans%=mod;
        y>>=1;
    }
    return ans;
}
ll a,b,n,fact[1000005],invfact[1000005];
const ll mod=1000000007;
ll c(int x,int y){
    if (k<0 or k>n)
        return 0;
    return (((fact[x]*invfact[y])%mod)*invfact[x-y])%mod;
}
bool check(ll x){
    while (x){
        int y=x%10;
        
    }
}
void solve(){
    a=read(),b=read(),r=read();
    ll sum=0;
    fact[0]=1;
    for (int i=1;i<=n;i++)
        fact[i]=fact[i-1]*i,fact[i]%=mod;
    invfact[n]=po_w(fact[n],mod-2,mod);
    for (int i=n-1;i>=0;i--)
        invfact[i]=(invfact[i+1]*(i+1))%mod;
    for (int i=0;i<=n;i++){
        ll num=1ll*i*a*(n-i)*b;
        if (check(num))
            sum+=c(n,i),sum%=mod;
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    // ll t=1;
    // ll t=read();
    ll t;
    cin>>t;
    while (t--)
        solve();
    return 0;
}
共 2 篇
  1. 个人记录

    NFLS暑假 2026 第四周总结

    没有学莫队,所以从刘聿讯(0)开始学习,总的来说,莫队就是一个离线的算法,用来处理区间的查询问题,并且答案区间可以用o(1)的复杂度来想两边移动一次区间边界pm1 ,复杂度O(n × √n)。 他的思路就是一种暴力的优化,可以先考虑纯暴力,对于一个区间,向下一个区间直接转移左右边…

  2. 个人记录

    NFLS暑假 2026 Day 2总结

    这是一份编程题解题笔记,记录了题目 A、B、C、E、G、F 的解决思路。内容涉及滑动窗口、ST 表、单调队列、二分答案、GCD 差分、双向链表及线段树优化等算法与数据结构。其中 B 题结合数论与二分,G 题利用数值减半特性优化取模,F 题通过断环为链处理循环,其余题目主要应用了相关数据结构的模板。