Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Plz help me WA :(I used my RedBlack tree to solve it, but WA T.T There is any critical input data for my source? (assume my RBTree class is right.. I tested it several times...) int n, m; int a[100000]; struct query { int num; int l, r, rank; }; bool operator < (const query& a, const query& b) { if (a.l == b.l) { return (a.r < b.r); } return (a.l < b.l); } query q[50000]; int answer[50000]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < m; i++) { scanf("%d%d%d", &q[i].l, &q[i].r, &q[i].rank); if (q[i].l > q[i].r) { int temp = q[i].l; q[i].l = q[i].r; q[i].r = temp; } q[i].l--, q[i].r--; q[i].num = i; //printf("%d %d %d\n", q[i].l, q[i].r, q[i].rank); } sort(q, q + m); RedBlack rb; for (int i = q[0].l; i <= q[0].r; i++) { rb.insert(a[i]); } answer[q[0].num] = rb.rank(q[0].rank); for (int i = 1; i < m; i++) { if (q[i - 1].r >= q[i].r) { (* (int *)0) = 0; } if (q[i - 1].r < q[i].l) { for (int j = q[i - 1].l; j <= q[i - 1].r; j++) rb.erase(a[j]); for (int j = q[i].l; j <= q[i].r; j++) rb.insert(a[j]); } else { for (int j = q[i - 1].l; j < q[i].l; j++) rb.erase(a[j]); for (int j = q[i - 1].r + 1; j <= q[i].r; j++) rb.insert(a[j]); } answer[q[i].num] = rb.rank(q[i].rank); } for (int i = 0; i < m; i++) { printf("%d\n", answer[i]); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator