Do Not Try This Problem(分块思想)
题意:https://codeforces.com/group/ikIh7rsWAl/contest/259944/problem/D
给你q个操作,4个数n,a,k,c,从n好位置开始每次加a的位置变成字符c,加到k次停止。
思路:
首先肯定是从下往上修改,改完就可以不再考虑该位置了。
1.对于a公差大于根号n的我们直接更新。
2.对于a公差小于根号n的,我们存根号n个数组,长度为n,对每个a公差分别用并查集维护下一个要的数,每个数最多使用一次。

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\Input.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr strcat
#include <string>
#include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
#include <cassert>
#include <iomanip>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
//******************
clock_t __STRAT,__END;
double __TOTALTIME;
void _MS(){__STRAT=clock();}
void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
//***********************
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
const double E=2.718281828;
const double PI=acos(-1.0);
const ll INF=(1LL<<);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e5+;
int l[][N],r[][N],n;bool f[*N];
void Init(int n)
{
for(int i=;i<=;++i)
{
for(int j=;j<=N-;++j)
{
r[i][j]=j;
}
}
}
int findr(int pos,int x)
{
if(r[x][pos]==pos)
return pos;
else
return r[x][pos]=findr(r[x][pos],x);
}
void del(int pos)
{
for(int i=;i<=;++i)
{
r[i][pos]=findr(min(pos+i,n+),i);
}
}
char s[N];
struct node
{
int a,b,c;
char d[];
}op[N];
/*
xaaaaaaaaaaaaaaaaaaa
3
4 2 8 b
6 3 4 c
10 5 2 d
*/
int main()
{
sc("%s",s+);
n=strlen(s+);
Init(n);
int q;
sc("%d",&q); for(int i=;i<=q;++i)
sc("%d%d%d%1s",&op[i].a,&op[i].b,&op[i].c,&op[i].d[]);
int x=;
for(int i=q;i>=;--i)
{
if(op[i].b>x)
{
for(int j=op[i].a,k=;j<=n&&k<=op[i].c;j+=op[i].b,++k)
{
if(f[j])continue;
s[j]=op[i].d[];
f[j]=;
del(j);
}
}
else
{
int j=op[i].a;
while(j<=op[i].a+op[i].b*op[i].c)
{
if(!f[j])
{
f[j]=;
s[j]=op[i].d[];
del(j);
}
j=findr(j,op[i].b);
}
}
}
pr("%s\n",s+);
return ;
} /**************************************************************************************/
Do Not Try This Problem(分块思想)的更多相关文章
- Codeforces Round #319 (Div. 1)C. Points on Plane 分块思想
C. Points on Plane On a pl ...
- hdu_5085_Counting problem(莫队分块思想)
题目连接:hdu_5085_Counting problem 题意:给你一个计算公式,然后给你一个区间,问这个区间内满足条件的数有多少个 题解:由于这个公式比较特殊,具有可加性,我们考虑讲一个数分为两 ...
- 莫队算法 sqrt(n)分块思想
在此说一下本渣对莫队算法思想的一些浅薄理解 莫队算法的思想就是对真个区间的分块,然后按照每块来分别进行计算,这样最终的复杂度可以达到n*sqrt(n) 小Z的袜子是一道非常经典的题目.:题目链接htt ...
- [BZOJ 2957]楼房重建(THU2013集训)(分块思想)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2957 分析: 首先明确问题,对于每栋楼房的斜率K=H/X,问题就是问有多少个楼房的K比前面所有 ...
- ZOJ 1654 Place the Robots建图思维(分块思想)+二分匹配
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=654 AC一百道水题,不如AC一道难题来的舒服. 题意:一个n*m地图 ...
- 构造+分块思想 Codeforces Round #319 (Div. 1) C
http://codeforces.com/contest/576/problem/C 题目大意: 给你一个曼哈顿距离的图,然后要求你找到一个链,链穿了所有的点 然后要求这链的长度<=25*10 ...
- PAT1057 stack(分块思想)
1057 Stack (30分) Stack is one of the most fundamental data structures, which is based on the princ ...
- HDOJ 4858 项目管理 ( 只是有点 莫队的分块思想在里面而已啦 )
题目: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 题意: 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的! ...
- cf666 C. Codeword 组合数学 离线分块思想
time limit per test 6 seconds memory limit per test 256 megabytes input standard i ...
随机推荐
- Win内核原理与实现学习笔记2-现代操作系统的基本结构
1.操作系统本属于软件的范畴,但它需要紧密的跟硬件打交道,它为上层应用软件或应用系统提供了一层抽象,专门负责硬件资源的管理和分配.(应用程序不需要跟硬件打交道,它们利用操作系统提供的功能来实现各种任务 ...
- Selenium结合BeautifulSoup4编写简单爬虫
在学会了抓包,接口请求(如requests库)和Selenium的一些操作方法后,基本上就可以编写爬虫,爬取绝大多数网站的内容. 在爬虫领域,Selenium永远是最后一道防线.从本质上来说,访问网页 ...
- 百度翻译api初使用(很久没写python了,写几行玩玩)
调用free api做做简易的翻译 这个是百度翻译api文档 http://api.fanyi.baidu.com/api/trans/product/apidoc 照着百度api给的文档向web服务 ...
- 菜单栏伸缩(附jquery-1.12.1.js)
Css: <style type="text/css"> .leftMenu { min-width:220px; width:268px; margin:40px a ...
- layer 漂亮的弹窗
layer.confirm('<font color="red">请认真核对账目信息,提交后将不可撤回!!</font>', { icon:3, title ...
- selenium安装与更新
1.通过pip show selenium 查看是否已经安装过selenium,如果已经安装selenium会显示安装的selenium的版本信息. 如果在使用pip 查看命令报Unknown or ...
- Yarn 安装 node-sass 依赖导致 Build Fresh Packages 太慢的问题
解决办法: 1. 在 项目目录下新建 .yarnrc 文件 添加以下代码 registry "https://registry.npm.taobao.org" sass_binar ...
- jinja2-模版继承
一 简要 简单的来说模板继承包含基本模板和子模板.其中基本模板里包含了你这个网站里的基本元素的基本骨架,但是里面有一些空的或者是不完善的块(block)需要用子模板来填充. 二 基本模版样例 这个模板 ...
- Python实现进度条的效果
from itertools import cycle from time import sleep for frame in cycle(r'-\|/-\|/'): print('\r', fram ...
- Node.js中npm常用命令大全
npm是什么 NPM的全称是Node Package Manager,是随同NodeJS一起安装的包管理和分发工具,它很方便让JavaScript开发者下载.安装.上传以及管理已经安装的包. npm ...