考试的时候用了两个树状数组去优化,暴力修改,树状数组维护修改后区间差值还有最终求和,最后骗了40分.. 这道题有好多种做法,求和好说,最主要的是开方.这道题过的关键就是掌握一点:在数据范围内,最多开方五六次就会变成1,这样以后再修改就不用修改了. ① 线段树打标记 ② 分块打标记 ③ 树状数组+并查集 因为我考试的时候用的树状数组,所以直接打的第三种,相对来说代码量也少一些. 思路:开始时父亲都指向自己,如果变成1,就把父亲指向下一个位置即可.修改的时候相当于跳着修改.代码当中会有注解.…
Stability Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)Total Submission(s): 1347 Accepted Submission(s): 319 Problem Description Given an undirected connected graph G with n nodes and m edges, with possibly r…
Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 27704 Accepted: 7336 Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possible to align the sticks in a straight line suc…
这题搞了我一天啊...拍不出错原来是因为极限数据就RE了啊,竟然返回WA啊.我的线段树要开8倍才能过啊... 首先可以发现除了那个加边操作,其他的操作有点像线段树啊.如果我们把每次询问的联通块都放在一个区间的话,那么就可以用线段树维护了啊. 于是我们只需要用带权并查集把联通块串成一条链的形式.就可以用区间表示出来了啊.. # include <cstdio> # include <cstring> # include <cstdlib> # include <io…
湫湫系列故事——设计风景线 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 3930 Accepted Submission(s): 700 Problem Description 随着杭州西湖的知名度的进一步提升,园林规划专家湫湫希望设计出一条新的经典观光线路,根据老板马小腾的指示,新的风景线最好能建成环形,如果没有条件建成环形,…
传送门 The k-th Largest Group Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 8690 Accepted: 2847 Description Newman likes playing with cats. He possesses lots of cats in his home. Because the number of cats is really huge, Newman wants…