Color the Ball
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3529 Accepted Submission(s): 874
Problem Description
There are infinite balls in a line (numbered 1 2 3 ....), and initially all of them are paint black. Now Jim use a brush paint the balls, every time give two integers a b and follow by a char 'w' or 'b', 'w' denotes the ball from a to b are painted white, 'b' denotes that be painted black. You are ask to find the longest white ball sequence.
Input
First line is an integer N (<=2000), the times Jim paint, next N line contain a b c, c can be 'w' and 'b'.
There are multiple cases, process to the end of file.
Output
Two integers the left end of the longest white ball sequence and the right end of longest white ball sequence (If more than one output the small number one). All the input are less than 2^31-1. If no such sequence exists, output "Oh, my god".
Sample Input
3
1 4 w
8 11 w
3 5 b
Sample Output
8 11
//好事恶习啊,我都快要吐了,第一次做离散化的线段树
#include
#include
#include
#include
using namespace std;
#define N 4040
int a[N],r[N],p[N],c[N],f[N];//r[i]排名i的原位置,p[i]原位置i的排名
int cmp(int i,int j){
return a[i]=r)return;
t[k].init(l,r);
if(l+1>=r)return;
int md=(l+r)/2;
build(l,md,k*2);
build(md,r,k*2+1);//不是md+1(因为md被覆盖)
}
void down(int k){
if(t[k].l+1==t[k].r)return;
if(t[k].lz==-1)return;
t[k*2].lz=t[k*2+1].lz=t[k].lz;
t[k].lz=-1;
}
void DownAll(int k){
if(t[k].lz!=-1){
for(int i=t[k].l;i=t[k].r)return;
if(l==t[k].l&&r==t[k].r){
t[k].lz=cr;//标记
return;
}
down(k);
if(t[k].l+1>=t[k].r)return;
int md=(t[k].l+t[k].r)/2;
if(md>=r)update(l,r,cr,k*2);
else if(l>md)update(l,r,cr,k*2+1);
else{
update(l,md,cr,k*2);
update(md,r,cr,k*2+1);
}
}
int main(){
int i,j,k,n;
int x,y;
char ch;
while(~scanf("%d",&n)){
for(i=j=0;iy-x){x=tx;y=ty;}
}
if(x==y) puts("Oh, my god");
else printf("%d %d\n",x, y-1);
}
return 0;
}