hdu 4339 不错的线段树
来源:互联网 发布:软件开发保密制度 编辑:程序博客网 时间:2024/04/20 01:27
Query
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1857 Accepted Submission(s): 595
Problem Description
You are given two strings s1[0..l1], s2[0..l2] and Q - number of queries.
Your task is to answer next queries:
1) 1 a i c - you should set i-th character in a-th string to c;
2) 2 i - you should output the greatest j such that for all k (i<=k and k<i+j) s1[k] equals s2[k].
Your task is to answer next queries:
1) 1 a i c - you should set i-th character in a-th string to c;
2) 2 i - you should output the greatest j such that for all k (i<=k and k<i+j) s1[k] equals s2[k].
Input
The first line contains T - number of test cases (T<=25).
Next T blocks contain each test.
The first line of test contains s1.
The second line of test contains s2.
The third line of test contains Q.
Next Q lines of test contain each query:
1) 1 a i c (a is 1 or 2, 0<=i, i<length of a-th string, 'a'<=c, c<='z')
2) 2 i (0<=i, i<l1, i<l2)
All characters in strings are from 'a'..'z' (lowercase latin letters).
Q <= 100000.
l1, l2 <= 1000000.
Next T blocks contain each test.
The first line of test contains s1.
The second line of test contains s2.
The third line of test contains Q.
Next Q lines of test contain each query:
1) 1 a i c (a is 1 or 2, 0<=i, i<length of a-th string, 'a'<=c, c<='z')
2) 2 i (0<=i, i<l1, i<l2)
All characters in strings are from 'a'..'z' (lowercase latin letters).
Q <= 100000.
l1, l2 <= 1000000.
Output
For each test output "Case t:" in a single line, where t is number of test (numbered from 1 to T).
Then for each query "2 i" output in single line one integer j.
Then for each query "2 i" output in single line one integer j.
Sample Input
1aaabbaaabbaa72 02 12 22 31 1 2 b2 02 3
Sample Output
Case 1:210141
Source
2012 Multi-University Training Contest 4
Recommend
zhoujiaqi2010
题意:
题意: 有两个字符串,给出 Q 个询问,每个询问有两种体式格式:
1 p i c 把第 p 个字符串的第i 个字符换成 字符 c,
2i
思路
一开始自己不知道如何实现查询函数
参考了大牛的才过了
#include<stdio.h>#include<string.h>struct haha{ int left; int right; int r_len; int l_len;}node[1000011*4];char s1[1000011],s2[1000011];int a[1000011];void pushup(int nd){ int rl=node[nd*2+1].right-node[nd*2+1].left+1; int ll=node[nd*2].right-node[nd*2].left+1; node[nd].l_len=node[nd*2].l_len; node[nd].r_len=node[nd*2+1].r_len; if(node[nd].l_len==ll) node[nd].l_len+=node[nd*2+1].l_len; if(node[nd].r_len==rl) node[nd].r_len+=node[nd*2].r_len;}void build(int left,int right,int nd){ int mid; mid=(left+right)/2; node[nd].left=left; node[nd].right=right; if(left==right) { if(s1[left]==s2[left]) {a[left]=1;node[nd].r_len=node[nd].l_len=1;} else {a[left]=0;node[nd].r_len=node[nd].l_len=0;} return ; } build(left,mid,nd*2); build(mid+1,right,nd*2+1); pushup(nd);}void update(int pos,int val,int nd){ if(node[nd].left==node[nd].right) {a[pos]=val;node[nd].l_len=node[nd].r_len=val;return;} else { int mid=(node[nd].left+node[nd].right)/2; if(pos<=mid) update(pos,val,nd*2); else update(pos,val,nd*2+1); } pushup(nd);}int query(int pos,int nd)//主要是这个函数 我一开始没有思路{ if(pos==node[nd].left) return node[nd].l_len; if(node[nd].left==node[nd].right) return node[nd].l_len; if(pos>node[2*nd].right) return query(pos,nd*2+1);//进入右分支 else { int len=node[nd*2].right-pos+1; if(node[nd*2].r_len<len) return query(pos,nd*2); else return len+query(node[nd*2+1].left,nd*2+1); }}int main(){ int cas,k,d2,d1,ccas=0; scanf("%d",&cas); while(cas--) { printf("Case %d:\n",++ccas); scanf("%s %s",s1+1,s2+1); d1=strlen(s1+1); d2=strlen(s2+1); if(d1>d2) d1=d2; build(1,d1,1); scanf("%d",&k); while(k--) { int flag; scanf("%d",&flag); if(flag==1) { int kk,pos,val; char ch; scanf("%d %d %c",&kk,&pos,&ch); pos++; if(pos>d1) continue;//注意题目范围 这句很阴啊 if(kk==1) { if(ch==s2[pos]) val=1; else val=0; s1[pos]=ch; } else { if(ch==s1[pos]) val=1; else val=0; s2[pos]=ch; } update(pos,val,1); } else { int left; scanf("%d",&left); left++; printf("%d\n",query(left,1)); } } } return 0;}
- hdu 4339 不错的线段树
- poj 2892 hdu 1540 不错的线段树题
- hdu4046 不错的线段树单点更新
- UVA11992不错的线段树段更新
- hdu 4339 线段树
- hdu简单的线段树
- hdu 4339 query#线段树
- hdu 4339 线段树+二分
- 线段树 HDU 4339 Query
- 线段树-hdu-4339-Query
- hdu 4339 Query(线段树)
- hdu 4339 Query ---线段树
- hdu 4339 线段树+二分
- HDU 4339 Query(线段树)
- 线段树 HDU 1754 最简单的线段树
- hdu 1754 简单的线段树
- HDU 1255 覆盖的面积 线段树
- HDU 1166模仿大牛写的线段树
- java中代码检查checkStyle结果分析 .
- static和extern修饰连接属性
- static的作用
- C库文件说明
- Lustre I/O性能特点
- hdu 4339 不错的线段树
- 雅可比算法求方阵的全部特征值和特征向量
- 黑马程序员---入学考试分析(金额转换)
- 开发的第一个iphone应用--HandPhoto
- android sax dom pull 解析 xml
- 类在内存中的分配问题
- #pragma pack 设置内存对齐方式
- 编译linux内核模块时Makefile的写法
- spring3.0 MVC笔记2--从spring2.0转向spring3.0