跳到正文

个人记录

6.3 周二下午训练 -- 东塘407

Meovow约 4 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年7月11日
篇幅
约 4 分钟

版本

  1. v1当前

T3

拓扑模版

这道题是作业,没做出来的原因是考试没时间了,所以没a

时间主要花在第四题上了,第三题最开始没想到拓扑,就打了个骗分代码,拿了部分分,想到拓扑的时候正在调T4的暴力,最后没调出来。所以这道题也没做。

C++
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5005;
int dis[N],in[N];
vector<int> e[N];
queue<int> q;
int n,k,p,R;
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k >> p;
	memset(dis, -1, sizeof(dis));
	for (int i = 1; i <= p; i++)
	{
		int x;
		cin >> x;
		q.push(x);
		dis[x] = 0;
	}
	cin >> R;
	for (int i = 1; i <= R; i++)
	{
		int v, s;
		cin >> v >> s;
		for (int j = 1; j <= s; j++)
		{
			int u;
			cin >> u;
			e[u].push_back(v);
			in[v]++;
		}
	}
	while(!q.empty())
	{
		int u = q.front();
		q.pop();
		for (int i = 0; i < e[u].size(); i++)
		{
			dis[e[u][i]] = max(dis[e[u][i]], dis[u] + 1);
			if (!--in[e[u][i]])
				q.push(e[u][i]);
		}
	}
	cout << dis[k];
	return 0;
}

T4

一眼线段树(bushi

注意到后面没有修改,所以可以用差分数组(如果要修改的话你还要改差分数组,用了跟没用一样/kel)

注意Final到了 10710^7,所以这里不是 O(1)O(1) 不行。

然后开始敲代码:

C++
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=8e4 + 5;
int diff[N],s[N],s2[N];
int n,T,mod,Min,Max;
signed main()
{
	cin>>n>>T>>mod>>Min>>Max;
	while(T--)
	{
		char op;
		cin>>op;
		if(op=='A')
		{
			int l,r,x;
			cin>>l>>r>>x;
			diff[l]+=x;
			diff[r+1]-=x;
		}
		else
		{
			int l,r;
			cin>>l>>r;
			for(int i=1;i<=n;i++)
				s[i]=s[i-1]+diff[i];
			for(int i=1;i<=n;i++)
			{
				int t=(s[i]*i)%mod;
				if(t>=Min && t<=Max)
					s2[i]=s2[i-1]+1;
				else
					s2[i]=s2[i-1];
			}
			cout<<s2[r]-s2[l-1]<<"\n";
		}
	}
	for(int i=1;i<=n;i++)
		s[i]=s[i-1]+diff[i];
	for(int i=1;i<=n;i++)
	{
		int t=(s[i]*i)%mod;
		if(t>=Min && t<=Max)
			s2[i]=s2[i-1]+1;
		else
			s2[i]=s2[i-1];
	}
	cin>>T;
	while(T--)
	{
		int l,r;
		cin>>l>>r;
		cout<<s2[r]-s2[l-1]<<"\n";
	}
	return 0;
}

广告:T5在考试完第二天被鉴定为错题

原文