目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n 个点的无向图,标号从 1 到 n.一开始没有任何边存在. 请你完成以下两种操作: 1 x y(1 <= x, y <= n, x ≠ y),将 (x, y) 这一条边置反.也就是,存在变为不存在,不存在变为存在. 2 x y(1 <= x, y <= n, x ≠ y),询问 x, y 是否连通. 注意操作是加密的.记 last 表示…
题意 题目链接 动态图连通性,加密方式为 \((x+l-1)\bmod n +1\) (\(l=[上一次询问的两点连通]\)). 点数 \(n\),操作数 \(m\) \(\le 2\times 10^5\). Solution 容易发现这是一个假的强制在线-- \(l\) 的取值只有 \(0\) 和 \(1\) 两种,所以总共的操作种数不超过 \(2\times m\). 于是我们可以考虑采用离线解决本题的思路,我们考虑线段树分治+可撤销并查集. 与离线不同的是,我们需要动态在线段树上添加节点…
可以用并查集维护连通性,删除可以用按置合并并查集,但删掉一条边后无法再维护两点的联通性了(因为产生环的边是不加入的)暴力思路是, 考虑前i个操作后边的集合,暴力加入即可,但复杂度是$o(n^2)$的用分块,对于每一个块,先求出前面所有块操作后边的集合,去掉这个块内删掉的边,这个并查集一定是之后这个块内每一个点都有的并查集,即计算每一个点时都恢复到这个并查集(恢复时记录下修改的点,因此也不能路径压缩)之后用暴力的做法,这个集合大小是$o(\sqrt{n})$的,那么总复杂度就是$o(n\sqrt{…
CodeForces - 369E Valera and Queries 题目大意:给出n个线段(线段的左端点和右端点坐标)和m个查询,每个查询有cnt个点,要求给出有多少条线段包含至少其中一个点. 思路:如果按照题意正面去算有每个线段是否包含点,那么时间复杂度是不允许的:如果去算每个点被哪些线段包含,那么去重比较困难.正难则反,因此对于每个查询,选择去求有多少个线段没有覆盖任何一个点,那么答案则为n减所求.用树状数组来统计没有覆盖任何一个点的线段数,大致做法是将临界线段(如x1+1,x2-1)…
codeforces 1217E E. Sum Queries? (线段树 传送门:https://codeforces.com/contest/1217/problem/E 题意: n个数,m次询问 单点修改 询问区间内最小的unbalanced number balanced number定义是,区间内选取数字的和sum sum上的每一位都对应着选取的数上的一位 否则就是unbalanced number 题解: 根据题意 如果区间存在unbalance number,那么一定存在两个数就可…
题目链接:codeforces 797 E. Array Queries   题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为止,求每次询问要转换的次数. 题解:纯暴力会TLE,所以在k为根号100000范围内dp打表 dp[i][j]表示初始p为i, k为j,需要转换几次可以大于n. 状态转移方程:dp[i][j] = dp[i+a[i]+j] + 1 #include <cstdio> #include <al…
Description You are given an array a of size n, and q queries to it. There are queries of two types: 1 li ri — perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li ≤ x < ri new value of ax + 1 becomes equal t…
You are given an array a of size n, and q queries to it. There are queries of two types: 1 li ri — perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li ≤ x < ri new value of ax + 1 becomes equal to old value…
C. Sonya and Queries time limit per test:1 second memory limit per test: 256 megabytes input:standard input output: standard output Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty mul…
B. Queries about less or equal elements Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/problem/B Description You are given two arrays of integers a and b. For each element of the second array bj you should find the num…