The 36th ACM/ICPC Asia Regional Beijing Sitehttp://acm.hdu.edu.cn/showproblem.php?pid=4046

2024-01-10 07:38

本文主要是介绍The 36th ACM/ICPC Asia Regional Beijing Sitehttp://acm.hdu.edu.cn/showproblem.php?pid=4046,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

比较难的线段树题,,,

#include<iostream>
#include<cstdio>
#include<string.h>
#define N 50005
using namespace std;
typedef struct NODE
{int l;int r;int key;
}Node;
Node node[N<<2];
char str[N];
void build(int t,int l,int r)
{node[t].l=l;node[t].r=r;if(r==l){if(l<=2) {node[t].key=0;return;}if(str[l]=='w'&&str[l-1]=='b'&&str[l-2]=='w') node[t].key=1;else  node[t].key=0;return;}int mid=(l+r)>>1;build(t<<1,l,mid);build(t<<1|1,mid+1,r);node[t].key=node[t<<1].key+node[t<<1|1].key;
}
void update(int t,int l,int r,char ch)
{if(node[t].l==l&&node[t].r==r){ str[l]=ch;if(l<=2) return;if(str[l]=='w'&&str[l-1]=='b'&&str[l-2]=='w') node[t].key=1;else  node[t].key=0;return ;}if(l>=node[t<<1|1].l)  update(t<<1|1,l,r,ch);else if(r<=node[t<<1].r) update(t<<1,l,r,ch);else{ update(t<<1,l,node[t<<1].r,ch);update(t<<1|1,node[t<<1|1].l,r,ch);}node[t].key=node[t<<1].key+node[t<<1|1].key;
}
int Quary(int t,int l,int r)
{if(node[t].l==l&&node[t].r==r) return node[t].key;if(l>=node[t<<1|1].l) return Quary(t<<1|1,l,r);else if(r<=node[t<<1].r) return Quary(t<<1,l,r);else  return Quary(t<<1,l,node[t<<1].r)+Quary(t<<1|1,node[t<<1|1].l,r);
}
int main()
{int T;scanf("%d",&T);for(int k=1;k<=T;++k){printf("Case %d:\n",k);int n,m;scanf("%d%d",&n,&m);str[0]=0;scanf("%s",str+1);build(1,1,n);for(int i=0;i!=m;++i){int x;scanf("%d",&x);if(x==0)  {  int y,z;scanf("%d%d",&y,&z);if(z-y+1<3) printf("0\n");else  printf("%d\n",Quary(1,y+3,z+1));}else{int y;char z;scanf("%d",&y);getchar();scanf("%c",&z);update(1,y+1,y+1,z);if(y+1<n) update(1,y+2,y+2,str[y+2]);if(y+2<n) update(1,y+3,y+3,str[y+3]);}}}return 0;
}


这篇关于The 36th ACM/ICPC Asia Regional Beijing Sitehttp://acm.hdu.edu.cn/showproblem.php?pid=4046的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/590046

相关文章

PHP轻松处理千万行数据的方法详解

《PHP轻松处理千万行数据的方法详解》说到处理大数据集,PHP通常不是第一个想到的语言,但如果你曾经需要处理数百万行数据而不让服务器崩溃或内存耗尽,你就会知道PHP用对了工具有多强大,下面小编就... 目录问题的本质php 中的数据流处理:为什么必不可少生成器:内存高效的迭代方式流量控制:避免系统过载一次性

PHP应用中处理限流和API节流的最佳实践

《PHP应用中处理限流和API节流的最佳实践》限流和API节流对于确保Web应用程序的可靠性、安全性和可扩展性至关重要,本文将详细介绍PHP应用中处理限流和API节流的最佳实践,下面就来和小编一起学习... 目录限流的重要性在 php 中实施限流的最佳实践使用集中式存储进行状态管理(如 Redis)采用滑动

PHP执行php.exe -v命令报错的解决方案

《PHP执行php.exe-v命令报错的解决方案》:本文主要介绍PHP执行php.exe-v命令报错的解决方案,文中通过图文讲解的非常详细,对大家的学习或工作有一定的帮助,需要的朋友可以参考下... 目录执行phpandroid.exe -v命令报错解决方案执行php.exe -v命令报错-PHP War

认识、理解、分类——acm之搜索

普通搜索方法有两种:1、广度优先搜索;2、深度优先搜索; 更多搜索方法: 3、双向广度优先搜索; 4、启发式搜索(包括A*算法等); 搜索通常会用到的知识点:状态压缩(位压缩,利用hash思想压缩)。

usaco 1.3 Mixing Milk (结构体排序 qsort) and hdu 2020(sort)

到了这题学会了结构体排序 于是回去修改了 1.2 milking cows 的算法~ 结构体排序核心: 1.结构体定义 struct Milk{int price;int milks;}milk[5000]; 2.自定义的比较函数,若返回值为正,qsort 函数判定a>b ;为负,a<b;为0,a==b; int milkcmp(const void *va,c

poj 3974 and hdu 3068 最长回文串的O(n)解法(Manacher算法)

求一段字符串中的最长回文串。 因为数据量比较大,用原来的O(n^2)会爆。 小白上的O(n^2)解法代码:TLE啦~ #include<stdio.h>#include<string.h>const int Maxn = 1000000;char s[Maxn];int main(){char e[] = {"END"};while(scanf("%s", s) != EO

hdu 2093 考试排名(sscanf)

模拟题。 直接从教程里拉解析。 因为表格里的数据格式不统一。有时候有"()",有时候又没有。而它也不会给我们提示。 这种情况下,就只能它它们统一看作字符串来处理了。现在就请出我们的主角sscanf()! sscanf 语法: #include int sscanf( const char *buffer, const char *format, ... ); 函数sscanf()和

hdu 2602 and poj 3624(01背包)

01背包的模板题。 hdu2602代码: #include<stdio.h>#include<string.h>const int MaxN = 1001;int max(int a, int b){return a > b ? a : b;}int w[MaxN];int v[MaxN];int dp[MaxN];int main(){int T;int N, V;s

hdu 1754 I Hate It(线段树,单点更新,区间最值)

题意是求一个线段中的最大数。 线段树的模板题,试用了一下交大的模板。效率有点略低。 代码: #include <stdio.h>#include <string.h>#define TREE_SIZE (1 << (20))//const int TREE_SIZE = 200000 + 10;int max(int a, int b){return a > b ? a :

hdu 1166 敌兵布阵(树状数组 or 线段树)

题意是求一个线段的和,在线段上可以进行加减的修改。 树状数组的模板题。 代码: #include <stdio.h>#include <string.h>const int maxn = 50000 + 1;int c[maxn];int n;int lowbit(int x){return x & -x;}void add(int x, int num){while