首页 > 其他分享 >Codeforces Round #900 (Div. 3)

Codeforces Round #900 (Div. 3)

时间:2024-08-25 17:27:30浏览次数:9  
标签:900 int void pos tot Codeforces Maxn vec Div

三年之后第一次打比赛,用小号打了场 \(Div.3\) ,居然没有AK,感觉实力退步到小学了。


A. How Much Does Daytona Cost?

若只判断题,只要判断 \(\{ a_n \}\) 中是否存在 \(k\) 即可。


B. Aleksa and Stack

构造方法不唯一,我直接输出奇数列,显然正确。


C. Vasilije in Cacak

若只判断题,只要判断前 \(k\) 个数的和会不会超过 \(x\) ,以及后 \(k\) 个数的和会不会小于 \(x\) 就行了。


D. Reverse Madness

易知 \(\{ r_n \}\) 单调增, 故可以二分 \(x\) 的位置。至于调换操作直接用一颗平衡树解决就行了。

const int Maxn = 2e5 + 5;
int T, n, k, q, l[Maxn], r[Maxn], x[Maxn];
char str[Maxn];

struct FHQTreap {
	int lson[Maxn], rson[Maxn], data[Maxn], tag[Maxn];
	int rnd[Maxn], sze[Maxn], seed, root, tot;
	
	FHQTreap(void) {
		Ms(lson, 0), Ms(data, 0), Ms(tag, 0);
		Ms(sze, 0), Ms(rnd, 0), root = 0;
		Ms(rson, 0), tot = 0, seed = 1;
	}
	
	void clear(void) {
		root = 0, tot = 0, seed = 1;
	} 
	
	inline int _rand(void) { return seed *= 482711; }
	inline int newnode(int val) { tot++; data[tot] = val, rnd[tot] = _rand(), sze[tot] = 1, lson[tot] = rson[tot] = 0, tag[tot] = 0; return tot; }
	inline void pushup(int pos) { sze[pos] = sze[lson[pos]] + sze[rson[pos]] + 1; }
	inline void pushdown(int pos) {
		if (!pos || !tag[pos]) return;
		swap(lson[pos], rson[pos]);
		tag[lson[pos]] ^= 1, tag[rson[pos]] ^= 1;
		tag[pos] = 0; return;
	}
	
	inline void split(int pos, int val, int &x, int &y) {
		if (!pos) { x = y = 0; return; } pushdown(pos);
		if (sze[lson[pos]] + 1 <= val) x = pos, split(rson[pos], val - sze[lson[pos]] - 1, rson[pos], y);
		else y = pos, split(lson[pos], val, x, lson[pos]); pushup(pos);
	}
	
	inline int merge(int x, int y) {
		if (!x || !y) return x + y; pushdown(x), pushdown(y);
		if (rnd[x] < rnd[y]) return rson[x] = merge(rson[x], y), pushup(x), x;
		else return lson[y] = merge(x, lson[y]), pushup(y), y;
	}
	
	inline void insert(int val) {
		int x, y, pos = newnode(val);
		split(root, val, x, y);
		root = merge(merge(x, pos), y);
	}
	
	inline void remove(int val) {
		int x, y, z;
		split(root, val - 1, x, y);
		split(y, val, y, z); if (!y) return;
		y = merge(lson[y], rson[y]);
		root = merge(merge(x, y), z);
	}
	
	inline void reverse(int l, int r) {
		int x, y, z;
		split(root, r, x, y);
		split(x, l - 1, x, z);
		tag[z] ^= 1; root = merge(merge(x, z), y);
	}
	
	inline void search(int pos) {
		if (!pos) return;
		pushdown(pos);
		search(lson[pos]);
		putchar(str[data[pos]]);
		search(rson[pos]);
	}
} treap;

signed main(void) {
//	ios :: sync_with_stdio(false);
	read(T); while (T--) {
		read(n), read(k); readstr(str + 1);
		treap.clear(); for (int i = 1; i <= n; i++) treap.insert(i);
		for (int i = 1; i <= k; i++) read(l[i]);
		for (int i = 1; i <= k; i++) read(r[i]);
		read(q);
		for (int i = 1; i <= q; i++) {
			read(x[i]);
			int m = lower_bound(r + 1, r + k + 1, x[i]) - r;
			int L = min(x[i], l[m] + r[m] - x[i]),
				R = max(x[i], l[m] + r[m] - x[i]);
			treap.reverse(L, R);
//			reverse(str + L, str + R + 1);
		}
		treap.search(treap.root); putchar('\n');
	}
//	fwrite(pf, 1, o1 - pf, stdout);
	return 0;
}

当然更简单的方法是打交换标记,贴一段 \(jiangly\) 的代码:

void solve() {
    int n, k;
    std::cin >> n >> k;
    
    std::string s;
    std::cin >> s;
    
    std::vector<int> l(k), r(k);
    for (int i = 0; i < k; i++) {
        std::cin >> l[i];
        l[i]--;
    }
    for (int i = 0; i < k; i++) {
        std::cin >> r[i];
        r[i]--;
    }
    
    int q;
    std::cin >> q;
    
    std::vector<int> f(n);
    
    while (q--) {
        int x;
        std::cin >> x;
        x--;
        f[x] ^= 1;
    }
    
    for (int i = 0; i < k; i++) {
        int rev = 0;
        for (int j = l[i]; j <= l[i] + r[i] - j; j++) {
            rev ^= f[j] ^ f[l[i] + r[i] - j];
            if (rev) {
                std::swap(s[j], s[l[i] + r[i] - j]);
            }
        }
    }
    std::cout << s << "\n";
}

E. Iva & Pav

考试时候脑子坏了,写了两个log的做法。实际上用ST表维护区间按位与和就行。
贴一段脑残二分线段树做法:

const int Maxn = 2e5 + 5;
int T, n, a[Maxn], q, k;

struct SegmentTree {
	int t[Maxn << 2];
	SegmentTree(void) { Ms(t, 0); }
	void clear(void) { Ms(t, 0); }
	inline void pushup(int pos) { t[pos] = t[pos << 1] & t[pos << 1 | 1]; }
	
	inline void build(int pos, int l, int r) {
		if (l == r) return (void) (t[pos] = a[l]);
		int mid = l + r >> 1;
		build(pos << 1, l, mid);
		build(pos << 1 | 1, mid + 1, r);
		pushup(pos);
	}
	
	inline int query(int pos, int l, int r, int L, int R) {
		if (L <= l && R >= r) return t[pos];
		int mid = l + r >> 1, ret = INT_MAX;
		if (L <= mid) ret &= query(pos << 1, l, mid, L, R);
		if (R > mid) ret &= query(pos << 1 | 1, mid + 1, r, L, R);
		return ret;
	}
} sgt;

inline int check(int x, int y) {
	int l = x, r = y, ans = x;
	while (l <= r) {
		int mid = l + r >> 1;
		if (sgt.query(1, 1, n, x, mid) >= k) l = mid + 1, ans = mid;
		else r = mid - 1;
	} return ans;
}

signed main(void) {
	int l;
	for (read(T); T; T--) {
		read(n);
		for (int i = 1; i <= n; i++) read(a[i]);
		sgt.build(1, 1, n); read(q);
		for (int i = 1; i <= q; i++) {
			read(l), read(k);
			if (a[l] < k) {
				writeln(-1, i == q ? '\n' : ' ');
			} else {
				int r = check(l, n);
				writeln(r, i == q ? '\n' : ' ');
			}
		}
	}
//	fwrite(pf, 1, o1 - pf, stdout);
	return 0;
}

F. Vasilije Loves Number Theory

由题意知只要满足 \(n \equiv 0 \pmod{d(n)}\) 就存在满足条件的 \(a\) 可是累乘 \(x\) 会导致 \(n\) 爆炸,所以记录当前的唯一分解的指数,并时刻保持取余运算:

int T, q, n;

const int Maxn = 1e6 + 5; 
int prime[80000], cnt;
int vis[Maxn], d, sum[Maxn];

inline void doit(int x, int t = 1) {
	while (x > 1) {
		int p = vis[x];
		x /= p;
		d /= sum[p] + 1;
		sum[p] += t;
		d *= sum[p] + 1;
	}
}

vector <int> vec;

signed main(void) {
	vis[1] = 0; d = 1;
	for (int i = 2, upEdge = 1e6 + 1; i <= upEdge; i++) {
		if (!vis[i]) prime[++cnt] = i, vis[i] = i;
		for (int j = 1; j <= cnt; j++) {
			if (i > upEdge / prime[j]) break;
			vis[i * prime[j]] = prime[j];
			if (prime[j] == vis[i]) break;
		}
	}
	
	for (read(T); T; T--) {
		read(n), read(q); vec.push_back(n); doit(n);
		for (int opt, x; q; q--) {
			read(opt);
			if (opt == 1) {
				read(x); vec.push_back(x); doit(x);
				int ret = 1;
				for (auto v : vec) ret = 1ll * ret * v % d;
				if (ret != 0) {
					puts("NO");
				} else {
					puts("YES");
				}
			} else {
				while (vec.size() > 1) doit(vec.back(), -1), vec.pop_back();
				puts("");
			}
		}
		while (!vec.empty()) doit(vec.back(), -1), vec.pop_back();
	}
//	fwrite(pf, 1, o1 - pf, stdout);
	return 0;
}

G. wxhtzdy ORO Tree

赛时没来得及想出来,先鸽了,咕咕咕。

标签:900,int,void,pos,tot,Codeforces,Maxn,vec,Div
From: https://www.cnblogs.com/EternalEpic/p/18379185

相关文章

  • Codeforces Round 967 (Div. 2) - C
    题意概述这是一个交互题。有一棵有\(n\)个节点的树,节点编号从\(1\)到\(n\),并要求你使用以下类型的查询来猜测它:"?ab"会告诉你哪个节点\(x\)在点\(a\)和\(b\)之间(\(|d(a,x)-d(b,x)|\)的值最小),其中\(d(x,y)\)是节点\(x\)和\(y\)之间的距离。如果存在不......
  • CodeForces - 1353D Constructing the Array
    CodeForces-1353D这道题也可能比较简单,主要是要想到优先队列要怎么使用,这一点如果用递归会写不了但是因为对优先队列不太熟悉,只有被提示可以用优先队列才想到要怎么用,还是很重要的STL注意运算符的重构应该反着来写其他的思维很朴素,运算符的重构就是,先比较长度,优先用长度长......
  • CodeForces-431C k-Tree
    感觉这个题的dp还是有点思维的,可能就是我现在能做到的题目的天花板级别的了,dp还是要点灵感感觉,以下是代码,可能要写题解要过好久,先水着include<bits/stdc++.h>defineintlonglongdefineendl'\n'usingnamespacestd;constintmod=1000000007;intn,k,d;intdp[200][2]=......
  • CodeForces - 1336A Linova and Kingdom
    CodeForces-1336A就差一点点,很可惜,少发现个很显而易见的结论就是一个点的价值,实际上就是(这个点的深度-之后的点的数目)就是\(depth_i-size_i\)然后只要用dfs维护就好了然后把一个点的价值用STL优先队列放在一起,贪心完成。但是可能也算不上什么贪心,因为是很朴素的东西......
  • Codeforces Round 967 (Div. 2)
    A.MakeAllEqual签到题,先确定最终答案,然后把其他数删去,转化为统计众数点击查看代码#include<bits/stdc++.h>usingnamespacestd;#definelllonglong#defineullunsignedlonglongintread(){intx=0;boolf=false;charc=getchar();while(c<......
  • Codeforces Round 967(Div.2)之赛后总结
    CodeforcesRound967(Div.2)传送锚点A.MakeAllEqual1.题面分析废话这么多,说白了就是求总数减去最多出现数的个数的值。2.解法直接用桶装一下,然后扫一遍维护最大值。3.code#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintN=1e6+520;......
  • Autel DS900 vs DS808 vs MP808 vs MS906
    Whatisthedifferenceamong2024AutelnewMaxiDASDS900series,DS808andMP808series?Herearesomecomparisontablets.Tablet1:AutelMaxiDASDS900vsDS900BTvsDS900TSModelMaxiDASDS900TSMaxiDASDS900BT MaxiDASDS900ReadCodes√√√E......
  • Codeforces Round 967 (Div. 2) ABCD
    来源:CodeforcesRound967(Div.2)做题时间:2024_08_21A.MakeAllEqual使所有元素相等的最小操作次数,就是保留最大的数字所以操作次数就是总数减去数量最多得数B.GeneratePermutation题意构造一个序列\(p\),内部元素是\([1,2,\cdots,n]\)打乱使长度为\(n\)的初始......
  • Solution - Codeforces 1970G3 Min-Fund Prison (Hard)
    时间\(\mathcal{O}(\frac{n\sqrt{n}\logn}{\omega})\)空间\(\mathcal{O}(\frac{n\logn}{w})\)的爆标做法。首先无解当且仅当图联通且无割边。首先考虑加边的贡献。一个比较直观的感受就是只会尽可能少的加边,即加边到整个图连通。证明考虑删掉的边。如果加多了边导致删......
  • 2024年关于短信轰炸机原理研究并实现的流程 (290021243
    偶然看到gitHub上面有短信轰炸机源码,于是产生了研究的想法。经过研究源码发现是通过抓包进行第三方网站抓包并且收集,最终进行post/get请求。携带header和token进行第三方网站模拟请求。于是在mac上面下载了fiddler进行代理配置开放了本机ip下的8888商品,用手机同时访问本机ip的......