首页 > 其他分享 >20240720周赛订正

20240720周赛订正

时间:2024-07-20 20:44:42浏览次数:15  
标签:周赛 typedef lc 订正 int ll long 20240720 define

20240720周赛订正

总结

本场比赛没有任何少拿的分。

题解

T1

尺取。

# include <bits/stdc++.h> 
using namespace std; 
typedef long long ll; 
// # define int long long 
# define lc u << 1
# define rc u << 1 | 1 
# define fi first
# define se second
const int N = 1000005;

int n;
int m[N], c[N];
struct node
{
	int val, row;
	bool operator < (const node &t) const { return val < t.val; }
} a[N]; int tot;
int cnt[N];
signed main ()
{
	scanf ("%d", &n);
	for (int i = 1; i <= n; i ++ )
	{
		scanf ("%d%d", &m[i], &c[i]);
		for (int j = 1; j <= m[i]; j ++ )
		{
			int x; scanf ("%d", &x);
			a[ ++ tot] = {x, i};
		}
	}
	sort (a + 1, a + 1 + tot);
	int full = 0;
	int ans = 1e9;
	for (int i = 1, j = 1; i <= tot; i ++ )
	{
		while (j <= tot && full < n)
		{
			cnt[a[j].row] ++ ;
			if (cnt[a[j].row] == c[a[j].row]) full ++ ;
			j ++ ;
		}
		if (full == n) ans = min (ans, a[j - 1].val - a[i].val);
		if (cnt[a[i].row] == c[a[i].row]) full -- ;
		cnt[a[i].row] -- ;
	}
	printf ("%d\n", ans);
	return 0;
}

T2

随便写

# include <bits/stdc++.h> 
using namespace std; 
typedef long long ll; 
// # define int long long 
# define lc u << 1
# define rc u << 1 | 1 
# define fi first
# define se second
const int N = 1000005;

int n, m;
bool vis[N];
signed main ()
{
	// freopen ("forward.in", "r", stdin); 
	// freopen ("forward.out", "w", stdout);
	int T; scanf ("%d", &T);
	while (T -- )
	{
		scanf ("%d%d", &n, &m);
		stack <int> q;
		for (int i = n; i >= 1; i -- ) q.push (i), vis[i] = 0;
		while (m -- )
		{
			int x; scanf ("%d", &x);
			q.push (x);
		}
		while (!q.empty ())
		{
			int u = q.top (); q.pop ();
			if (vis[u]) continue;
			vis[u] = 1;
			printf ("%d ", u);
		}
		printf ("\n");
	}
	return 0;
}

T3

容易发现一个数是 \(x\),后面的一个数就是 \(x\div p\) 或者 \(x \times p\)。

# include <bits/stdc++.h> 
using namespace std; 
typedef long long ll; 
// # define int long long 
# define lc u << 1
# define rc u << 1 | 1 
# define fi first
# define se second
const int N = 1000005;

int n;
bool com[N];
int pri[N], tot;
int ans[N], anstot;
signed main ()
{
	// freopen ("forward.in", "r", stdin); 
	// freopen ("forward.out", "w", stdout);
	int T; scanf ("%d", &T);
	while (T -- )
	{
		scanf ("%d", &n);
		int tmp = n;
		tot = 0;
		for (int i = 2; i * i <= tmp; i ++ )
		{
			while (tmp % i == 0)
			{
				tmp /= i;
				pri[ ++ tot] = i;
			}
		}
		if (tmp > 1) pri[ ++ tot] = tmp;
		sort (pri + 1, pri + 1 + tot);
		queue <int> q; q.push (1);
		anstot = 0;
		map <int, bool> vis; vis[1] = 1;
		// continue;
		while (!q.empty ())
		{
			int u = q.front (); q.pop ();
			ans[ ++ anstot] = u;
			for (int i = 1; i <= tot; i ++ )
			{
				if (!vis[u / pri[i]] && u % pri[i] == 0)
				{
					vis[u / pri[i]] = 1;
					q.push (u / pri[i]);
					break;
				}
				else if (!vis[u * pri[i]] && n % (u * pri[i]) == 0)
				{
					vis[u * pri[i]] = 1;
					q.push (u * pri[i]);
					break;
				}
			}
		}
		// random_shuffle (ans + 1, ans + 1 + anstot);
		printf ("%d\n", anstot);
		for (int i = 1; i <= anstot; i ++ ) printf ("%d ", ans[i]);
		printf ("\n");
	}
	return 0;
}

T4

设 \(f_i\) 表示前 \(i\) 个数的和的种类数。

# include <bits/stdc++.h> 
using namespace std; 
typedef long long ll; 
// # define int long long 
# define lc u << 1
# define rc u << 1 | 1 
# define fi first
# define se second
inline int read ()
{
    int w = 1, s = 0;
    char c = getchar ();
    for (; c < '0' || c > '9'; w *= (c == '-') ? -1 : 1, c = getchar ());
    for (; c >= '0' && c <= '9'; s = 10 * s + (c - '0'), c = getchar ());
    return s * w;
}
const int N = 500005, mod = 1e9 + 7;

int n;
ll a[N], sum[N];
map <ll, int> mp;
ll f[N];
signed main ()
{
	scanf ("%d", &n); for (int i = 1; i <= n; i ++ ) scanf ("%lld", &a[i]);
	for (int i = 1; i <= n; i ++ ) sum[i] = sum[i - 1] + a[i];
	ll he = 0;
	for (int i = 1; i <= n; i ++ )
	{
        f[i] = (1 + he) % mod;
        if (mp.find (sum[i]) != mp.end ()) 
        	he = (he + mod - mp[sum[i]]) % mod;
        he = (he + f[i]) % mod;
        mp[sum[i]] = f[i];
    }
    printf ("%lld\n", f[n]);
    return 0;
}

T5

不会

T6

首先离线。然后容易发现,每次询问都是单调不减的。
\(up_{i,j}\) 维护 \((i,j)\) 向上可以扩展的最远距离
\(down_{i,j}\) 维护 \((i,j)\) 向下可以扩展的最远距离。
每次 \(O(n)\) 处理信息。
我们还可以发现,每次询问就是要知道区间里的 \(up\) 的最小值,和 \(down\) 的最小值。

# include <bits/stdc++.h> 
using namespace std; 
typedef long long ll; 
// # define int long long 
# define lc u << 1
# define rc u << 1 | 1 
# define fi first
# define se second
inline int read ()
{
    int w = 1, s = 0;
    char c = getchar ();
    for (; c < '0' || c > '9'; w *= (c == '-') ? -1 : 1, c = getchar ());
    for (; c >= '0' && c <= '9'; s = 10 * s + (c - '0'), c = getchar ());
    return s * w;
}
const int N = 2005;

int n, m, k;
int a[N][N];
struct Query { int x, y; } Q[N];
int up[N][N], down[N][N];
int mnup[N << 2], mndn[N << 2];
void pushup (int u)
{
	mnup[u] = min (mnup[lc], mnup[rc]); 
	mndn[u] = min (mndn[lc], mndn[rc]);
}
void build (int u, int l, int r, int t)
{
	if (l == r)
	{
		mnup[u] = up[t][l];
		mndn[u] = down[t][l];
		return;
	}
	int mid = l + r >> 1;
	build (lc, l, mid, t);
	build (rc, mid + 1, r, t);
	pushup (u);
}
int ansup, ansdown;
void query (int u, int l, int r, int x, int y)
{
	if (x <= l && y >= r)
	{
		ansup = min (ansup, mnup[u]);
		ansdown = min (ansdown, mndn[u]);
		return;
	}
	int mid = l + r >> 1;
	if (x <= mid) query (lc, l, mid, x, y);
	if (y > mid) query (rc, mid + 1, r, x, y);
}
int f[N][N];
int res[N];
bool check (int bc, int y)
{
	if (bc > n || bc > m) return 0;
	for (int i = max (1, y - bc + 1); i <= m - bc + 1 ; i ++ )
	{
		ansup = ansdown = 1e9;
		query (1, 1, m, i, i + bc - 1);
		if (ansup + ansdown - 1 >= bc) return 1;
	}
	return 0;
}
char s[N];
signed main ()
{
	scanf ("%d %d %d", &n, &m, &k);
	for (int i = 1; i <= n; i ++ )
	{
		scanf ("%s", s + 1);
		for (int j = 1; j <= m; j ++ ) 
			a[i][j] = s[j] == '.';
	}
	for (int i = 1; i <= k; i ++ )
	{
		scanf ("%d %d", &Q[i].x,&Q[i].y);
		a[Q[i].x][Q[i].y] = 0;
	}
	for (int i = 1; i <= n; i ++ )
	{
		for (int j = 1; j <= m; j ++ )
		{
			if (a[i][j]) up[i][j] = up[i - 1][j] + 1;
			else up[i][j] = 0;
		}
	}
	for (int i = n; i >= 1; i -- )
	{
		for (int j = 1; j <= m; j ++ )
		{
			if (a[i][j]) down[i][j] = down[i + 1][j] + 1;
			else down[i][j] = 0;
		}
	}
	for (int i = 1; i <= n; i ++ )
	{
		for (int j = 1; j <= m; j ++)
		{
			if (a[i][j])
			{
				f[i][j] = min ({f[i - 1][j - 1], f[i - 1][j], f[i][j - 1]}) + 1;
				res[k] = max (res[k] , f[i][j]);
			}
		}
	}
	int ans = res[k];
	for (int i = k; i >= 1; i -- )
	{
		a[Q[i].x][Q[i].y] = 1 , res[i] = ans;
		up[Q[i].x][Q[i].y] = up[Q[i].x - 1][Q[i].y] + 1;
		for (int j = Q[i].x + 1; j <= n; j ++ ) 
		{
			if (!a[j][Q[i].y]) break;
			up[j][Q[i].y] += up[Q[i].x][Q[i].y];
		}
		down[Q[i].x][Q[i].y] = down[Q[i].x + 1][Q[i].y] + 1;
		for (int j = Q[i].x - 1; j >= 1; j -- )
		{
			if (!a[j][Q[i].y]) break;
			down[j][Q[i].y] += down[Q[i].x][Q[i].y];
		}
		build (1, 1, m, Q[i].x);
		while (check (ans + 1, Q[i].y)) ans ++ ;
	}
	for (int i = 1; i <= k; i ++ ) printf ("%d\n", res[i]);
	return 0;
}

标签:周赛,typedef,lc,订正,int,ll,long,20240720,define
From: https://www.cnblogs.com/legendcn/p/18313740

相关文章

  • 大一升大二暑假 NJU暑期课程 Linux系统基础(1) 20240720
    一.操作系统操作系统OperatingSystem简称OS,是软件的一部分,它是硬件基础上的第一层软件,是硬件和其它软件沟通的桥梁。操作系统会控制其他程序运行,管理系统资源,提供最基本的计算功能,如管理及配置内存、决定系统资源供需的优先次序等,同时还提供一些基本的服务程序。Q1:什么是文件......
  • 第 406 场周赛
    100352.交换后字典序最小的字符串枚举交换的位置classSolution{public:stringgetSmallestString(strings){stringres=s;for(inti=1;i<s.size();i++){if(((s[i]-'0')%2)==((s[i-1]-'0')%2)){......
  • leetcode周赛 - 406
    100352.交换后字典序最小的字符串给你一个仅由数字组成的字符串 s,在最多交换一次 相邻 且具有相同 奇偶性 的数字后,返回可以得到的字典序最小的字符串。如果两个数字都是奇数或都是偶数,则它们具有相同的奇偶性。例如,5和9、2和4奇偶性相同,而6和9奇偶性不......
  • 牛客周赛 Round 51
    A.小红的同余思路+解法:找到唯一一个x满足2x%m=1(0<=x<m)  就可以推出(m+1)*2即可Code: #include<bits/stdc++.h>usingnamespacestd;intmain(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);intm;cin>>m;......
  • 2024/7/14 每日一题 + 周赛P3/P4
    807.保持城市天际线问题描述给你一座由nxn个街区组成的城市,每个街区都包含一座立方体建筑。给你一个下标从0开始的nxn整数矩阵grid,其中grid[r][c]表示坐落于r行c列的建筑物的高度。城市的天际线是从远处观察城市时,所有建筑物形成的外部轮廓。从东、南......
  • 牛客周赛 Round50 E-小红的树上移动 (期望dp+逆元)
    E-小红的树上移动题目:题意:在一个树上从根节点移动,每次都会向更深的下一层走,如果此时已经是叶子节点没有下一层就会停留在这里。求出移动次数的期望,移动次数就是从根节点1开始到此节点的深度。思路:画一个草图不难看出其实在同一层中,到达每个点的概率是一样的。并且,对于每一层......
  • 第 405 场周赛
    3210.找出加密后的字符串classSolution{public:stringgetEncryptedString(strings,intk){intn=s.size();stringt=s;for(inti=0;i<n;i++)t[i]=s[(i+k)%n];returnt;}};3211.......
  • 牛客周赛 Round 50 D[小红的因式分解] 超级无敌大暴力
    牛客周赛Round50D小红的因式分解超级无敌大暴力首先拿到这个题,真的是一头雾水,本蒟蒻今天才想出来。。。首先拆开式子,我们可以得到a1a2==a;a1b2+a2b1==b;b1b2==c;那么,我们只需要求解一对a1与b1即可得到本题答案,因为剩下的一对a2b2由a/a1和b/b1得到所以我们可以运用......
  • 牛客周赛 Round 50
    这场还是差点 A.小红的最小最大题意:min(a,b)+x是不是比max(a,b)如果比它大输出YES否则输出NOCode:#include<bits/stdc++.h>usingnamespacestd;intmain(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);inta,b,x;cin>>......
  • leetcode404周赛(1,2,3)
    1.三角形的最大高度题意:给你两个整数red和blue,需要用这些求组成一个三角形,相邻行颜色必须不同,求最大高度思路:第一行放一个,第二行放两个第三行放三个,我们可以按奇数偶数行来计算总和,此时有两种情况,先蓝后红,先红后蓝,此时针对于第i行来说,如果先蓝后红此时对应奇偶行的蓝的......