Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

记一个WA

Posted by jojo2333 at 2017-08-02 19:43:27 on Problem 3667
WA的原因
我原来的query的写法如下:
int query(int rt,int len)
{
    if(t[rt].slen<len)  return -1;
    if(len == t[rt].r - t[rt].l + 1 && t[rt].c == 0){	//这里使用了t[rc].c == 0判断是否为空
        return t[rt].l;
    }
    int mid = (t[rt].r + t[rt].l)/2;
    if(t[rt*2].slen >= len)
        return query(rt*2,len);
    else if(t[rt*2].rlen+t[rt*2+1].llen >= len)
        return mid-t[rt*2].rlen+1;
    else if(t[rt*2+1].slen >= len)
        return query(rt*2+1,len);
    else return -1;
}
上面使用t[rc].c来进行判断是错误的因为c是懒惰标记,无法保证使用c的时候c是正确的值
考虑如下数据
10 4
1 3
1 7
2 1 5
1 3
正确输出
1
4
1

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator