[题解]CF718C Sasha and Array 对于我这种喜欢写结构体封装起来的选手这道题真是太对胃了\(hhh\) 一句话题解:直接开一颗线段树的矩阵然后暴力维护还要卡卡常数 我们来把\(2 \times 2\)看做之后时间复杂度就是\(O(nlogn)\). 写了一点点这种线段树维护除了数字之外的东西的题目,一个最大的感受就是递归用\(void\),传答案什么的一个全局变量,这样比较快. 需要注意的点是\(lazy \ \ tag\)要随着\(seg\)一起初始化一下. #includ…
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 题目描述 Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target…
https://leetcode.com/problems/remove-duplicates-from-sorted-array/ Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this…
原题传送门 裸的莫队啊,我博客里有对莫队较详细的介绍 这道题很简单,可以说是裸的模板 但是如何在已有的值上进行操作? 小学生应该都知道 那么转移就超级简单了qaq inline void add(register int c) { sum+=(num[c]+num[c]+1)*c; ++num[c]; } inline void del(register int c) { --num[c]; sum-=(num[c]+num[c]+1)*c; } 要开long long(虽说我没试过int,但我…
本蒟蒻又双叒叕被爆踩辣! 这就是道大水题 首先,题目意思: 给你n个数,要你找这些数字中找到一个能够被这些所有数字整除的数,若有多个,可任意输出其中一个,其实答案只有一个,因为在大于等于自己的数中能被自己整除的数只有它自己. 一句话题意(虽然好像本来就是一句话: 要你找到一个数\(a[x]\),使: \(gcd(a_1,a_2,a_3-a_n)\) \(== a[x]\) 是不是只要推出了这一步就没有任何问题了,是吧. 接下来,来证明一下(伪证: 窝们一样例为例 10 2 4 14 6 10 1…
原题链接在这里:https://leetcode.com/problems/reverse-words-in-a-string-ii/ 题目: Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters. The input string does not contain leading or trailing spaces and…
题目: Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation. For example: Given "aacecaaa", return "aaacecaa…
原题链接在这里:https://leetcode.com/problems/find-permutation/description/ 题目: By now, you are given a secret signature consisting of character 'D' and 'I'. 'D' represents a decreasing relationship between two numbers, 'I' represents an increasing relations…
原题链接在这里:https://leetcode.com/problems/random-pick-with-weight/ 题目: Given an array w of positive integers, where w[i] describes the weight of index i, write a function pickIndex which randomly picks an index in proportion to its weight. Note: 1 <= w.l…
原题链接在这里:https://leetcode.com/problems/lonely-pixel-i/ 题目: Given a picture consisting of black and white pixels, find the number of black lonely pixels. The picture is represented by a 2D char array consisting of 'B' and 'W', which means black and whi…