query 2019徐州网络赛(树状数组)】的更多相关文章

query \[ Time Limit: 2000 ms \quad Memory Limit: 262144 kB \] 题意 补题才发现比赛的时候读了一个假题意.... 给出长度为 \(n\) 的排列,在给出 \(m\) 次询问,每次询问有一对 \(l.r\),问满足 \(min(ai, aj) = gcd(ai, aj)\) 的 \(pair(i, j)\) 对数. 思路 考虑离线做 先把每个数出现的位置记录下来,然后预处理出所有的 \(pair\). 对于一个数字 \(x\),其满足条件…
Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That means, if he reads books from ll to rr, he will get a…
ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才反应过来没看完全部题, J题树形dp没写太亏了... // 几何旋律AK了,太强了Orz // 虽然我们队A了8题,但如果时间分配好,认真读题避免看错题的话,应该至少多A一题 A. Who is better? 题意 两个人玩游戏,谁先消灭完敌人就赢.两条规则:1. 第一个人不能全部消灭完: 2.…
(2)首先成倍数对的数量是nlogn级别的,考虑每一对[xL,xR](下标的位置,xL < xR)会对那些询问做出贡献,如果qL <= xL && qR >= xR,那么这一对就会对询问[qL,qR]贡献1:现在把它们看成平面上的点,那么对于每一个询问[qL,qR],就相当于计算这个点右下角有多少个点,这个就可以通过排序+树状数组解决————————————————大致就是,我们可以先处理出区间内每一对(i,j)倍数对,然后按i从大到小排序排序介绍:按i排序,从大到小,再…
这题挺有意思哈!!!看别人写的博客,感觉瞬间就懂了. 这道题大概题意就是,给一串序列,我们要查找到l-r区间内,满足min(a[ i ],a[ j ]) = gcd(a[ i ],a[ j ]) 其实我们把这个东西看成一个二元组,<i,j> 二元组满足 min(a[ i ],a[ j ]) = gcd(a[ i ],a[ j ]) 为了保证唯一性,<i,j>二元组满足i<j ,min(a[ i ],a[ j ]) = gcd(a[ i ],a[ j ]) 由于是排列,我们可以…
int find_kth(int k) { , cnt = , i; ; i >= ; i--)/ { ans += ( << i); if (ans >= maxn|| cnt + c[ans] >= k) ans -= ( << i); else cnt += c[ans]; } ; } 题意: 口袋里可以放进不同大小的糖果,也可以拿出不同大小的糖果.查询过程中第k小的糖果体积是多少 输入T,有T组,接下来是输入m次操作 m行输入op和x 当op等于1的时候,…
题目链接:https://nanti.jisuanke.com/t/41389 The value of a string sss is equal to the number of different letters which appear in this string. Your task is to calculate the total value of all the palindrome substring. Input The input consists of a single…
I. query 比赛时候没有预处理因子疯狂t,其实预处理出来因子是\(O(nlog(n))\)级别的 每个数和他的因子是一对偏序关系,因此询问转化为(l,r)区间每个数的因子在区间(l,r)的个数 预处理出来每个位置上的数所有因子的位置,用可持久化线段树维护,区间询问 #include<bits/stdc++.h> #define ll long long #define mk make_pair #define ft first #define se second #define pii…
对于答案来说,一定是 前 i-1 个字符和 t的前 i 个一样,然后第 i 个字符比 t的 大 \(i\in [1,m]\) 前缀为t,然后长度比t长 对于第一种情况,枚举这个 i ,然后找最小的 p 可以使得从\(s[1\sim p]\) 中产生\(t_1t_2\cdots t_{i-1}\) ,然后在\(s[p+1,n]\)中找最左边的比\(t[i]\) 大的字符,假如 找到了\(s[pos]\),那么后面的\(s[pos+1,n]\) 都可以加到答案后面(因为\(s[pos] > t[i]…
题意: 先有\(n=p_1^{k_1}p_2^{k_2}\cdots p_m^{k_m}\),定义\(f(n)=k_1+k_2+\cdots+k_m\). 现在计算 \[ \sum_{i=1}^nf(i!)\% 998244353 \] 思路: 首先注意到\(f\)函数有这样一个性质:\(f(ab)=f(a)+f(b)\). 那么我们化简所求式子有: \[ \begin{aligned} &\sum_{i=1}^nf(i!)\\ =&\sum_{i=1}^n\sum_{j=1}^if(j)…
题意:f(i)=i的幂次之和. 求(N+1-i)*f(i)之和. 思路:可以推论得对于一个素数p^k,其贡献是ans=(N+1)[N/(P^k)]+P^k(1+2+3...N/(P^k)); 我们分两部分统计答案即可,在p<=sqrt(N)时,可以暴力(阶乘那样一直除)统计答案. p>sqrt(N)时,我们可以利用min25的消息得到. 因为p>sqrt(N),这个时候k=1,所以贡献为(N+1)*(N/p)+p*(1+2+...N/p):我们把N/p相同的拉出来即可,而这个东西正好就是…
题目链接 大致题意:从根节点出发,在节点x有son[x]次等概率进入儿子节点,求到达最深深度的概率.son[x]为x节点的儿子节点个数. 又又又又没做出来,心态崩了. 下来看了官方题解后发觉自己大体思路是没错的,但是细节太弱了Orz. 大体思路:设dp[x]为以x为根节点,求到达最深深度的概率.先跑一遍dfs,求出每个点的子节点数,每个点的深度以及最深深度. 我们可以求得从x点一次不能到达最深深度的概率为$cnt =1-(\tfrac{\sum_{y\epsilon x } dp[y]}{son…
题意:n个点,求最小加上几个点让所有点关于一个点(不需要是点集里面的点)中心对称 题解:双重循环枚举,把中点记录一下,结果是n-最大的中点 #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define mem(s) memset(s, 0, sizeof(s)) const int INF = 0x3f3f3f3f; ; +; ; pair&…
You are given a point set with nn points on the 2D-plane, your task is to find the smallest number of points you need to add to the point set, so that all the points in the set are center symmetric. All the points are center symmetric means that you…
XKC , the captain of the basketball team , is directing a train of nn team members. He makes all members stand in a row , and numbers them 1 \cdots n1⋯n from left to right. The ability of the ii-th person is w_iwi​ , and if there is a guy whose abili…
Carneginon was a chic bard. But when he was young, he was frivolous and had joined many gangs. Recently, Caneginon was to be crowned, because the king was shocked by his poems and decided to award him the gold medal lecturer. Therefore, Most of peopl…
The hot summer came so quickly that Xiaoming and Xiaohong decided to buy a big and sweet watermelon. But they are two very strange people. They are even-numbered enthusiasts. They want to cut the watermelon in two parts, and each part weighs two time…
题目链接:https://nanti.jisuanke.com/t/41384 这题暴力能过,我用的是并查集的思想,这个题的数据是为暴力设置的,所以暴力挺快的,但是当他转移的点多了之后,我觉得还是我这种方法更好一点.注意这里一定要用内部是hash的unordered_map 做,因为查询为o(1) #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #in…
A After Asgard was destroyed, tanker brought his soldiers to earth, and at the same time took on the important task of protecting the peace of the earth. The best two solders were lb and zgx, were very capable, but they always disliked each other. Ho…
query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be represented as a pair (l ,r )(l,r), you need to find the number of pair(i ,j)(i,j) such that l \le i < j \le rl≤i<j≤r and \min(p_i,p_j) = \gcd(p_i,p_j )…
U41571 Agent2 题目背景 炎炎夏日还没有过去,Agent们没有一个想出去外面搞事情的.每当ENLIGHTENED总部组织活动时,人人都说有空,结果到了活动日,却一个接着一个咕咕咕了.只有不咕鸟Lyn_king一个人冒着太阳等了半个多小时,然后居然看到连ENLIGHTENED行动参谋都咕咕咕了,果然咕咕咕是人类的本性啊. 题目描述 作为一个ENLIGHTENED行动指挥,自然不想看到这一点,于是他偷取到了那些经常咕咕咕的Agent的在下来N天的活动安排表,并且叫上了你来整理.在整理过程…
题意:给出n个车辆进出校园的记录,以及k个时间点,让你回答每个时间点校园内的车辆数,最后输出在校园内停留的总时间最长的车牌号和停留时间,如果不止一个,车牌号按字典序输出. 几个注意点: 1.如果一个车连续多次进入,只取最后一个 2.如果一个车连续多次出去,只取第一个 3.一个车可能出入校园内好几次,停留时间取总和 实际上题目就是让我们求某个时间段内的车辆总和,时间段其实就相当于一个区间,区间求和的话,很快就联想到树状数组和线段树.然而怎么将时间段和区间联系起来呢,那就存储出现在记录和询问里的所有…
Trace There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xxx , yyy ) means the wave is a rectangle whose vertexes are ( 000 , 000 ), ( xxx , 000 ), ( 000 , yyy ), ( xxx , yyy ). Every time the wave will wash o…
题意:询问区间有多少个连续的段,而且这段的颜色在[L,R]才算贡献,每段贡献是1. 有单点修改和区间查询. 思路:46min交了第一发树套树,T了. 稍加优化多交几次就过了. 不难想到,除了L这个点,其他的点都可以只统计这一段的段首.把位置看成x,颜色看成y,就成了二维平面就矩形内点的个数,这就是裸的树套树或者CDQ了. 树套树:34**ms. /* 2019南昌网络赛I. 询问区间有多少个连续的段,而且这段的颜色在[L,R]才算贡献,每段贡献是1. 有单点修改和区间查询. 也可以CDQ来做,常…
I. Yukino With Subinterval 题目链接: Problem Descripe Yukino has an array \(a_1, a_2 \cdots a_n\). As a tsundere girl, Yukino is fond of studying subinterval. Today, she gives you four integers $l, r, x, y $, and she is looking for how many different sub…
还是想不到,真的觉得难,思路太巧妙 题意:给你一串数和一些区间,对于每个区间求出区间内每段连续值的不同gcd个数(该区间任一点可做起点,此点及之后的点都可做终点) 首先我们可以知道每次添加一个值时gcd要么不变要么减小,并且减小的幅度很大,就是说固定右端点时最多只能有(log2 a)个不同的gcd,而且我们知道gcd(gcd(a,b),c)=gcd(a,gcd(b,c)),所以我们可以使用n*(log2 n)的时间预处理出每个固定右端点的不同gcd的值和位置.解法就是从左到右,每次只需要使用上一…
2019-ACM-ICPC-徐州站网络赛- I. query-二维偏序+树状数组 [Problem Description] ​ 给你一个\([1,n]\)的排列,查询\([l,r]\)区间内有多少对\((i,j)\)满足\(l\le i<j\le r\),且\(min(p_i,p_j)=gcd(p_i,p_j)\). [Solution] ​ 将所有询问按区间右端点从小到大排序,对于排序后的每一个询问,将\([1,r]\)中所有满足条件的插入到树状数组中,然后查询区间大小即可.(\([1,r]…
Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero point. Then, you need to handle QQ operations. There're two types: 1\ L\ X1 L X: Increase points by XX of all nodes whose depth equals LL ( the depth of the root i…
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5869 Problem Description This is a simple problem. The teacher gives Bob a list of problems about GCD (Greatest Common Divisor). After studying some of them, Bob thinks that GCD is so interesting.…
https://nanti.jisuanke.com/t/31460 题意 两个操作.1:查询区间[l,r]的和,设长度为L=r-l+1, sum=a[l]*L+a[l+1]*(L-1)+...+a[r].2:将第a个位置修改为b. 分析 变形一下,sum=a[l]*(r-l+1)+a[l+1]*(r-(l+1)-1)+...+a[r](r-r+1)=(r+1)*a[l]-a[l]*l.因此,可维护两个树状数组计算.至于更新操作,实质就是看变化前后的差值,变大就相当与加上差值,否则就是减.注意用…