题意: 给你一段序列,并且有两种操作 操作①:将序列中从l-r每个元素加上x 操作②:在序列中找到ai=aj=y,j-i的最大值,如果找不到则输出-1 思路: 直接分块暴力即可 对于区间加,普通标记加暴力即可 对于找最大值,直接在每个块中二分找y,找不到即为-1 #include<iostream> #include<algorithm> #include<set> #include<cmath> #include<vector> using n…
题目链接 GukiZ and GukiZiana 题目大意:一个数列,支持两个操作.一种是对区间$[l, r]$中的数全部加上$k$,另一种是查询数列中值为$x$的下标的最大值减最小值. $n <= 500000, q <= 50000$ 我一开始的反应是线段树,然后发现自己完全想错了…… 这道题时限$10$秒,但也很容易超时.我后来是用分块过的. 把序列分成$\sqrt{n}$个块,每个块的大小为$\sqrt{n}$(最后一个块可能因为不能整除的关系可能会小一些) 每个块维护一个值$delt…
Problem E. GukiZ and GukiZiana Solution: 先分成N=sqrt(n)块,然后对这N块进行排序. 利用二分查找确定最前面和最后面的位置. #include <bits/stdc++.h> using namespace std; typedef long long ll; vector<]; ll add[], a[], pos[]; ll n, q, bk, N; bool cmp( int x, int y ) { if( a[x] == a[y]…
GukiZ and GukiZiana Time Limit: 10000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 551E64-bit integer IO format: %I64d      Java class name: (Any)   Professor GukiZ was playing with arrays again and accidentally di…
E. GukiZ and GukiZiana Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/problem/E Description Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called GukiZiana. For given a…
E. GukiZ and GukiZiana time limit per test 10 seconds memory limit per test 256 megabytes input standard input output standard output Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called GukiZiana. F…
GukiZ and GukiZiana 题意: 区间加 给出$y$查询$a_i=a_j=y$的$j-i$最大值 一开始以为和论文CC题一样...然后发现他带修改并且是给定了值 这样就更简单了.... 每个块维护排好序的结果 修改暴力重构+整块打标记 查询暴力查+整块二分找数量 复杂度$O(SlogS + \frac{N}{S} + S+\frac{N}{S}logS)$ woc求了一节课导数也没求出最值来又发现一开始式子列错了不管了我就开根号了..(我才不会说是因为乱搞了一下更慢了) 貌似是因为…
E - GukiZ and GukiZiana 思路:分块, 块内二分 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long long //#define mp m…
[codeforces551E]GukiZ and GukiZiana 试题描述 Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called GukiZiana. For given array a, indexed with integers from 1 to n, and number y, GukiZiana(a, y) represents…
time limit per test 10 seconds memory limit per test 256 megabytes input standard input output standard output Professor GukiZ was playing with arrays again and accidentally discovered new function, which he called GukiZiana. For given array a, index…
题目地址:http://codeforces.com/contest/551/problem/E 将n平均分成sqrt(n)块,对每一块从小到大排序,并设置一个总体偏移量. 改动操作:l~r区间内,对两端的块进行暴力处理,对中间的总体的块用总体偏移量标记添加了多少.时间复杂度: O(2*sqrt(n)+n/sqrt(n)). 查询操作:对每一块二分.查找y-总体偏移量.找到最左边的和最右边的.时间复杂度:O(sqrt(n)*log(sqrt(n))). 代码例如以下: #include <ios…
题目链接:http://codeforces.com/problemset/problem/551/E 题意:给定一个长度为N的序列. 有2个操作 1 l r v:序列第l项到第r项加v(区间加),  2 v:求整个序列中值为v的数的位置的差值最大是多少.不存在输出-1. 思路:分块. 每块维护该块序列排序后的序列. 对于区间修改,我们定义一个lazy标记.对于整块的修改我们只修改lazy, 其他情况暴力修改.然后情况该块后重新加入修改后的块然后排序. 对于查询操作.查询每块时v应该减去该块的l…
https://codeforces.com/contest/551/problem/E 分块真强. 题意就是1.区间加,2.询问整个区间中,最远的两个x的距离. 分块,然后,每次找位子用二分找即可. #include <algorithm> #include <iterator> #include <iostream> #include <cstring> #include <cstdlib> #include <iomanip>…
题目大意:一个长度为$n(n\leqslant5\times10^5)$的数组,有两个操作: $1\;l\;r\;x:$把区间$[l,r]$加上$x$ $2\;x:$询问$x$第一次出现和最后一次出现之间的距离,若没出现输出$-1$ 题解:分块,把每个块排个序(可以把数值为第一关键字,位置为第二关键字),整块的加就块上打$tag$,非整块的就暴力重构,查询就在每个块内求这个数出现位置,直接二分查找就行了.设块大小为$S$,修改复杂度$O(\dfrac n S+2S)$,查询复杂度$O(\dfra…
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取模. 因为取模后至少减半, 复杂度$O(nlognlogC)$ 2. CF 431E Chemistry Experiment 大意: n个试管, 第$i$个试管有$a_i$单位水银, m个操作: 1, 修改$a_x$改为$v$. 2, 将$v$单位水倒入试管, 求一种方案使得有水的试管水银与水总量的最大…
Professor GukiZ's Robot CodeForces - 620A 机器人很好玩 一开始在(x1,y1) 最后在(x2,y2) 每秒钟内横坐标最多变化1(也可以不变化)纵坐标也是 问最少几秒钟到 Inputx1 和 x2 绝对值在10^9以内Output最少几秒可以走到Examples Input 0 04 5 Output 5 Input 3 46 1 Output 3 sol:易知答案为max(abs(x1-x2),abs(y1-y2)) #include <bits/std…
题目链接:http://codeforces.com/problemset/problem/444/C 题意:给定一个长度为n的序列a[].起初a[i]=i,然后还有一个色度的序列b[],起初b[i]=0.现在有2种操作: 1 l r x:区间染色,a[l],a[l+1]...a[r]变成x.同时b[l],b[l+1]...b[r]加上对应的|x-a[i]|值. 2 l r:统计区间和,统计区间b[l],b[l+1]...b[r]的和. 思路:线段树是比较常见的做法.考虑分块.每块维护一个laz…
题目链接:http://codeforces.com/problemset/problem/455/D 题意:给定一个长度为n的序列a[]. m次操作.共有两种操作 1 l r:将序列的a[l].a[l+1]...a[r]变成a[r].a[l].a[l+1]...a[r-1]:2 l r k:求序列a[l].a[l+1]...a[r]中有多少个值为k. 输入的l,r,k都是加密过的.所以要解密一下.规则为 l=(l+ans-1)%n+1  r=(r+ans-1)%n+1 k=(k+ans-1)%…
题目链接:http://codeforces.com/problemset/problem/103/D 题意:给定一个长度为n的序列.然后q个询问.每个询问为(a,b),表示从序列第a项开始每b项的加和. 思路:2014集训队论文中的<<根号算法--不只是分块>>中提到这题. 传统的数据结构比较擅长处理连续区间的询问.但是不擅长处理间隔位置的询问.考虑到分块. 对于b>sqrt(n)的询问.我们暴力计算.可以发现b越大我们扫描的位置就会越小.最大扫描次数为O(n/sqrt(n…
题目链接: http://codeforces.com/contest/103/problem/D D. Time to Raid Cowavans time limit per test:4 secondsmemory limit per test:70 megabytes 问题描述 As you know, the most intelligent beings on the Earth are, of course, cows. This conclusion was reached lo…
D. Serega and Fun Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/455/problem/D Description Serega loves fun. However, everyone has fun in the unique manner. Serega has fun by solving query problems. One day Fedor came up w…
E. Holes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/13/problem/E Description Little Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for one person with following rules: There are…
C. GukiZ hates Boxes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/problem/C Description Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way. In total there…
A. GukiZ and Contest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/problem/A Description Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has de…
题目链接: http://codeforces.com/contest/677/problem/D 题意: 让你求最短的从start->...->1->...->2->...->3->...->...->p的最短路径. 题解: 这题dp的阶段性还是很明显的,相同的值得方格为同一个阶段,然后求从阶段1->2->3...->p的阶段图最短路. 初始化所有a[x][y]==1的格子为起始点到(x,y)坐标的距离. 方程式为dp[x1][y1…
C. Points on Plane Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/576/problem/C Description On a plane are n points (xi, yi) with integer coordinates between 0 and 106. The distance between the two points with numbers a and…
题目传送门 传送点I 传送点II 传送点III 题目大意 给定一个字母串,要求支持以下操作: 修改一个位置的字母 查询一段区间中,字符串$s$作为子串出现的次数 Solution 1 Bitset 每次匹配一段,可以看成,依次考虑每个位置,匹配的位置对应的起点取交集.例如: 大概就这个意思. bitset的count似乎很慢,可以用__builtin_popcount来数中间的位数,然后暴力数两端的位数会快很多.感觉手写倍增法数位数最快.但有人说前面那个内联函数比手写的$O(\log \log…
Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A", "T", "G", "C". A DNA strand is a sequence of nucleotides. Scientists decided to track evolution of a rare species, wh…
题目链接:http://codeforces.com/problemset/problem/551/C time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Professor GukiZ is concerned about making his way to school, because massive piles of bo…
C. DZY Loves Colors 题目连接: http://codeforces.com/contest/444/problem/C Description DZY loves colors, and he enjoys painting. On a colorful day, DZY gets a colorful ribbon, which consists of n units (they are numbered from 1 to n from left to right). T…