首页 > 其他分享 >CSP-S模拟2(联考)

CSP-S模拟2(联考)

时间:2022-09-04 17:01:14浏览次数:62  
标签:int ll mid long CSP maxn include 联考 模拟

差点又双叒叕模拟退役

上来先\(\% T2\), 然后感觉就差一点, 最后搞出来就十点多了..

然后心态一度爆炸,有点小摆烂,上厕所冷静一下觉得还有时间,能抢救一下

然后开了 \(T1\), 没啥思路瞎搞,开根号在附近找数用 \(pow\),发现大数据丢精异常严重 $pow(n, 1.0 / 1) $比 \(n\)大了好几百你敢信, 看一下时限\(6s\),于是手写二分, 然后打挂了一堆细节,调完就 \(11:22\) 了

看\(T3\), 感谢\(T3\),上来想到主席树二分直接莽, 然后一遍码对了? \(11:44\)拿到 \(95pts\)(主席树空间不对),防止了模拟退役

\(T4\)打了个\(DP\),显然没打过,不过离正解就差了亿点

感觉上来搞 \(T2\) 策略有点问题,还好切掉了,并且稳住了心态

A. 谜之阶乘

枚举相邻的数的个数\(i\),然后在\(^i\sqrt n\)左右找数, \(pow\)精度有问题,手写二分,但是数很大会炸 \(long long\), 所以先判 \(n / now >= mid\)再 \(now = now * mid\)

code
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = -1;
ll fac[55];
void init(){
	fac[0] = 1;
	for(int i = 1; i <= 20; ++i)fac[i] = fac[i - 1] * i;
}
inline ll read(){
	ll x = 0; char c = getchar();
	while(c < '0' || c > '9')c = getchar();
	do{x = x * 10 + (c ^ 48); c = getchar();}while(c <= '9' && c >= '0');
	return x;
}
ll a[105], b[105];
ll mr(ll n, int i){
	ll l = 1, r = n, ans = 1;
	while(l <= r){
		ll mid = (l + r) >> 1;
		ll now = 1; bool f = 1;
		for(int j = 1; j <= i; ++j){
			if(n / now >= mid)now = mid * now;
			else now = n + 1;
			if(now >= n || now < 0){
				r = mid - 1; ans = mid;
				f = 0; break;
			}
		}
		if(f)l = mid + 1;
	}
	return ans;
}
void solve(){
	ll n = read();
	if(n == 1){printf("-1\n");return;}
	int cnt = 0, mx = 0;
	for(int i = 1; i <= 20; ++i)if(fac[i + 1] > n){mx = i; break;}
	if(fac[mx] == n){
		++cnt;
		a[cnt] = mx;
		b[cnt] = 1;
	}
	for(int i = mx - 1; i > 0; --i){
		ll r = mr(n, i);
		ll l = max(3ll, r - i - i - i);
		for(ll j = l; j <= r; ++j){
			ll now = 1;
			for(ll p = 0; p < i; ++p){
				now = now * (j + p);
				if(now > n)break;
				if(now < 0)break;
			}
			if(now == n){
				++cnt;
				a[cnt] = j + i - 1;
				b[cnt] = j - 1;
				break;
			}
		}
	}
	printf("%d\n",cnt);
	for(int i = 1; i <= cnt; ++i)printf("%lld %lld\n",a[i], b[i]);
}
int main(){
	init();
	int t = read();
	for(int ask = 1; ask <= t; ++ask)solve();
	return 0;
}

B. 子集

构造很有意思,但是很费时间,很是人类智慧,所以下次。。。

还是先试试逝世

设 \(sum = n * (n - 1) / 2\)

\(k \nmid sum\) 或者 \(sum / k < n\)无解

\(n/ k\) 为偶数的话对应首尾项相加,然后得到 \(n/ 2\)个和相同的二元组,随便分一下就行

对于 \(n / k\) 为奇数的,每\(k\)项写成一行,每行的 \(k\) 个分入不同的集合里

定义这\(k\)列的权值为 \(- k / 2, -k/2 + 1 ...... 0 ...... k/ 2 - 1, k / 2\)

特殊处理前三行,后面的\(Z\)字形,(就是 \(x, -x, x , -x\)这样取权值)

对于前三行,先考虑前两行,我们先强制 \(x, -x\)配对, 这样第三行需要的都是 \(0\)

考虑对 \((x, -x) (y, -y)\)交换为 \((x, -y)(y, -x)\)那么他们需要的第三行就是 \(|x - y|, -|x - y|\)

那么我们只需要交换距离为 \(1, 2 .... (k + 1)/ 2\) 的不同的二元组的第二项,发现可以对应\(reverse[1, (k + 1)/ 2][(k + 1)/ 2 +1, k]\)两个区间对应的第二行元素即可

code
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

inline int read(){
	int x = 0; char c = getchar();
	while(c < '0' || c > '9')c = getchar();
	do{x = x * 10 + (c ^ 48); c = getchar();}while(c <= '9' && c >= '0');
	return x;
}
ll n, k, sum;
int ls[1000005];
void nosolution(){printf("No\n");}
void solve(){
	if(k == 1){
		printf("Yes\n");
		for(int i = 1; i <= n; ++i)printf("%d ",i);printf("\n");return;
	}
	sum = 1ll * n * (n + 1) / 2;
	if(sum % k)return nosolution();
	if(sum / k < n) return nosolution();
	if((n / k) & 1){
		printf("Yes\n");
		int s = (1 + k * 3) * (k * 3) / 2 / k;
		for(int i = 1; i <= k; ++i)ls[i] = k + k + 1 - i;
		reverse(ls + 1, ls + (k + 1) / 2 + 1);
		reverse(ls + (k + 1) / 2 + 1, ls + k + 1);
		for(int i = 1; i <= k; ++i){
			printf("%d %d %d ",i, ls[i], s - i - ls[i]);
			int dt = (i + 1) / 2, f = i % 2;
			for(int j = 4; j <= n / k; ++j){
				if(f)printf("%lld ", (j - 1) * k + dt);
				else printf("%lld ",j * k - dt + 1);
				f = 1 - f;
			}
			printf("\n");
		}
		return;
	}else{
		printf("Yes\n");
		int cnt = 1;
		for(int i = 1; i <= k; ++i){
			for(int j = n / k / 2; j; --j){
				printf("%d %lld ",cnt, n - cnt + 1);
				++cnt;
			}
			printf("\n");
		}
		return;
	}

}
int main(){
	int t = read();
	for(int ask = 1; ask <= t; ++ask){
		n = read(), k = read();
		solve();
	}
	return 0;
}

C. 混凝土粉末

主席树 + 标记永久化 + 二分 + \(22min\)= \(95pts\)

得分效率奇高

95pts
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 1000005;

inline ll read(){
	ll x = 0; char c = getchar();
	while(c < '0' || c > '9')c = getchar();
	do{x = x * 10 + (c ^ 48); c = getchar();}while(c <= '9' && c >= '0');
	return x;
}
int n, q;
int root[maxn], tot;
struct tree{
	struct node{
		int l, r; ll val;
	}t[maxn * 40];
	int cnt;
	void insert(int &x, int hrt, int l, int r, int L, int R, ll hi){
		if(!x) x = ++cnt, t[x] = t[hrt];
		if(L <= l && r <= R){
			t[x].val += hi;
			return;
		}
		int mid = (l + r) >> 1;
		if(L <= mid){
			t[x].l = 0;
			insert(t[x].l = 0, t[hrt].l, l, mid, L, R, hi);
		}
		if(R > mid){
			t[x].r = 0;
			insert(t[x].r, t[hrt].r, mid + 1, r, L, R, hi);
		}
	}
	ll query(int x, int l, int r, int pos){
		if(!x)return 0;
		if(l == r)return t[x].val;
		int mid = (l + r) >> 1;
		if(pos <= mid)return t[x].val + query(t[x].l, l, mid, pos);
		else return t[x].val + query(t[x].r, mid + 1, r, pos);
	}
}t;
int bound(int r){
	int x = read(), l = 1; ll y = read();
	if(t.query(root[r], 1, n, x) < y)return 0;
	int ans = r;
	while(l <= r){
		int mid = (l + r) >> 1;
		if(t.query(root[mid], 1, n, x) >= y)ans = mid, r = mid - 1;
		else l = mid + 1;
	}
	return ans;
}
int main(){
	n = read(), q = read();
	for(int i = 1; i <= q; ++i){
		int op = read();
		if(op & 1){
			int l = read(), r = read();
			ll h = read();
			t.insert(root[i], root[i - 1], 1, n, l, r, h);
		}else{
			root[i] = root[i - 1];
			printf("%d\n",bound(i));
		}
	}
	return 0;
}

正解扫描线,对每个位置分开二分,用树状数组维护每个时间对应的高度

对应修改\(time, l, r,h\)在 \(l\)位置对\(time\)时刻 \(+h\), \(r + 1\) 位置对 \(time\)时刻 \(-h\)这样

code
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>

using namespace std;

typedef long long ll;
const int maxn = 1000005;

inline ll read(){
	ll x = 0; char c = getchar();
	while(c < '0' || c > '9')c = getchar();
	do{x = x * 10 + (c ^ 48); c = getchar();}while(c <= '9' && c >= '0');
	return x;
}
int n, q;

struct tree{
	ll t[maxn];
	int lowbit(int x){return x & -x;}
	void add(int x, ll h){
		while(x <= q){
			t[x] += h;
			x += lowbit(x);
		}
	}
	ll query(int x){
		ll ans = 0;
		while(x){
			ans += t[x];
			x -= lowbit(x);
		}
		return ans;
	}
}t;
struct node{int time; ll val;};
vector<node>modify[maxn], query[maxn];
int ans[maxn], tot;
bool flag[maxn];
int bound(node x){
	if(t.query(x.time) < x.val)return 0;
	int l = 1, r = x.time;
	int ans = r;
	while(l <= r){
		int mid = (l + r) >> 1;
		if(t.query(mid) >= x.val)ans = mid, r = mid - 1;
		else l = mid + 1;
	}
	return ans;
}
int main(){
	n = read(), q = read();
	for(int i = 1; i <= q; ++i){
		int op = read();
		if(op & 1){
			int l = read(), r = read();
			ll h = read();
			modify[l].push_back({i, h});
			modify[r + 1].push_back({i, -h});
		}else{
			int x = read();
			query[x].push_back({i, read()});
			flag[i] = 1;
		}
	}
	for(int i = 1; i <= n; ++i){
		for(node x : modify[i])t.add(x.time, x.val);
		for(node x : query[i])ans[x.time] = bound(x);
	}
	for(int i = 1; i <= q; ++i)if(flag[i])printf("%d\n",ans[i]);
	return 0;
}

D. 排水系统

\(g_{x, 0}\)表示推到 \(x\)的原流(没有损坏), \(g_{x, 1}\)表示期望流

在拓扑过程中,可以以均等概率直接推送

然后考虑如果断掉了当前点的某条出边对其他点的贡献

断边概率 \(a/sum\) 断边对其他边流量的影响\(g_{x, 0} / cd[x]/(cd[x] - 1)\)

把该点出边的这部分 \(\sum\) 起来,然后再扫一遍,减去自己的就是其他断边对该点新推流的贡献,还有 \(a/sum\) 的概率断该边需要减去 \(g_{x,0}/cd[x]\)

感谢 \(Delov\) 大佬的巨大帮助

code
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 200005;
const int maxm = 500005;
const int mod = 998244353;
inline int read(){
	int x = 0; char c = getchar();
	while(c < '0' || c > '9')c = getchar();
	do{x = x * 10 + (c ^ 48); c = getchar();}while(c <= '9' && c >= '0');
	return x;
}
int qpow(int x, int y){
	int ans = 1;
	for(; y; y >>= 1, x = 1ll * x * x % mod)if(y & 1)ans = 1ll * ans * x % mod;
	return ans;
}
struct edge{
	int to, net, val;
}e[maxm];
int head[maxn], tot;
void add(int u, int v, int w){
	e[++tot].net = head[u];
	head[u] = tot;
	e[tot].to = v;
	e[tot].val = w;
}
int n, m, r, k, inv;
int g[maxn][2], rd[maxn], cd[maxn], iv[maxm];
queue<int>q;
signed  main(){
	n = read(), m = read(), r = read(), k = read();
	iv[1] = 1;
	for(int i = 2; i <= k; ++i)iv[i] = 1ll * (mod - mod / i) * iv[mod % i] % mod;
	int suma = 0;
	for(int i = 1; i <= k; ++i){
		int u = read(), v = read(), w = read();
		add(u, v, w); suma = (suma + w) % mod;
		++rd[v]; ++cd[u];
	}
	inv = qpow(suma, mod - 2);
	for(int i = 1; i <= n; ++i)if(!rd[i])q.push(i);
	for(int i = 1; i <= m; ++i)g[i][0] = 1, g[i][1] = 1;
	while(!q.empty()){
		int x = q.front(); q.pop();
		int sum = 0;
		for(int i = head[x]; i; i = e[i].net){
			int v = e[i].to;
			--rd[v]; if(rd[v] == 0)q.push(v);
			g[v][1] = (g[v][1] + 1ll * g[x][1] * iv[cd[x]] % mod) % mod;
			g[v][0] = (g[v][0] + 1ll * g[x][0] * iv[cd[x]] % mod) % mod;
			sum = (sum + 1ll * g[x][0] * inv % mod * e[i].val % mod * iv[cd[x] - 1] % mod * iv[cd[x]]) % mod;
		}
		for(int i = head[x]; i; i = e[i].net){
			int v = e[i].to;
			g[v][1] = (g[v][1] + sum - 1ll * g[x][0] * inv % mod * e[i].val % mod * iv[cd[x] - 1]  % mod * iv[cd[x]] % mod + mod) % mod;
			g[v][1] = (g[v][1] + mod - 1ll * g[x][0] * inv % mod * e[i].val % mod * iv[cd[x]] % mod) % mod;
		}
	}
	for(int i = n - r + 1;  i <= n; ++i)printf("%d ",g[i][1]);
	return 0;
}

标签:int,ll,mid,long,CSP,maxn,include,联考,模拟
From: https://www.cnblogs.com/Chencgy/p/16655420.html

相关文章

  • CSP-S模拟2(联考) 谜之阶乘 子集 混凝土粉末 排水系统
    rank4040多分?T1:暴力;T2:构造T2:构造出(1--n)的连续整数分成k组,每组的数加起来一样。(n<=1e6)只要能实现一种构造方案,使得3k个连续数字分k组可以达到(a+b+c)相同(或2k,很显然......
  • 2022.9.4 模拟赛
    ForNOIP.谜之阶乘题意:问\(n\)能够被多少组\((a,b)\)表示,满足\(n=\dfrac{a!}{b!}\)。\(n\leq10^{18}\),多组询问。首先猜测\(a-b\)并不大,然后就枚举这个差值......
  • CSP-S模拟1 [斐波那契,数颜色,分组]
    CSP-S模拟1洛谷上原题,不挂题面了。A.斐波那契P3938斐波那契观察上图,可发现规律:一个数的父亲等于这个数减去最大的小于它的斐波那契数。特殊的,如果这个数是斐波那契......
  • 9.3 noip 模拟赛 1 题解
    noip模拟赛1题解目录noip模拟赛1题解\(\tolink\leftarrow\)A一步之遥退位计划退役以后重在参与\(\tolink\leftarrow\)A一步之遥构造题手玩了一下没有什么......
  • CSP-S加赛1
    A.antipalindrome真·签到题然后忘了给\(m\)取模,挂了\(10pts\)考虑任何大于\(1\)的回文,必然存在相邻两个字母相同,或者中间隔一个字母,那么从前往后考虑每一个位......
  • CSP-S模拟1
    下发文件和题解A.斐波那契对于上面这张图,尝试从2开始依次写下每个兔子的父亲的标号:那么转换成数列就是这样的:111212312345...可以发现这个序列由多个......
  • android studio 创建模拟器报错问题 An error occurred while creating the AVD. See
    用androidstudio安装模拟器遇到的问题由于我是下载的zip版android,而且自定义了androidsdk路径为D:\andriodSDK\,导创这问题.1.无法创建虚拟设备2.启动设备报错解决方......
  • CCF CSP-J/S 2021第二轮获奖分数线及评级规则
    CCFNOI科学委员会、竞赛委员会召开会议,确定了CCFCSP-J/S2021第二轮评级规则及评级名额方案。提高级一等名额分配方案提高级一等全国认证基准线:100分CCFCSP-J/S第二......
  • CSP_202206-2_寻宝!大冒险!
    CSP_202206-2_寻宝!大冒险题目链接思路相当于判断两个有限集合AB之间是不是满射和单射,只需要保证以下两点A和B元素个数相等A中每个元素都能通过映射\(\psi\)到B中一个......
  • P4363 [九省联考 2018] 一双木棋 题解
    一道状压dp题,我写的记忆化搜索。注意到这道题已经下子的区域和未下子的区域有一条轮廓线分割,因此考虑右上到左下记纵向为1,横向为0,状压一下,然后顺着记忆化搜索(有点类似......