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 |
调了3小时,测试各种数据,终于过了。一把辛酸泪啊。。。附拙劣代码#include<stdio.h> #include<string.h> #define N 100005 struct node { int l,r; int color; node() { color = 0; } } tree[4*N]; int add[4*N]; int vis[50]; void build(int rt, int l, int r) { tree[rt].l = l; tree[rt].r = r; if(l == r) return ; int mid = (l + r) >> 1; build(rt<<1, l, mid); build(rt<<1|1, mid+1, r); } void update(int rt, int l, int r, int v) { if(l <= tree[rt].l && tree[rt].r <= r) { add[rt] = v; tree[rt].color = v; return ; } if(add[rt]) { tree[rt].color = 0; add[rt<<1] = add[rt]; add[rt<<1|1] = add[rt]; tree[rt<<1].color = add[rt]; tree[rt<<1|1].color = add[rt]; add[rt] = 0; } int mid = (tree[rt].l + tree[rt].r) >> 1; if(r <= mid) update(rt<<1, l, r, v); else if(l > mid) update(rt<<1|1, l, r, v); else { update(rt<<1, l, mid, v); update(rt<<1|1, mid+1, r, v); } } void query(int rt, int l, int r) { if(r < tree[rt].l || tree[rt].r < l) return ; if(tree[rt].l <= l && tree[rt].r >= r&&tree[rt].color!=0) { vis[tree[rt].color]++; return ; } int mid = (tree[rt].l + tree[rt].r) >> 1; if(r <= mid) query(rt<<1, l, r); else if(l > mid) query(rt<<1|1, l, r); else { query(rt<<1, l, mid); query(rt<<1|1, mid+1, r); } } int main() { int L,T,O; char q; int a,b,c; while(~scanf("%d%d%d", &L,&T,&O)) { memset(add, 0, sizeof(add)); build(1, 1, L); add[1] = 1; update(1, 1, L, 1); while(O--) { getchar(); scanf("%c", &q); if(q=='C') { scanf("%d%d%d", &a,&b,&c); if(a > b) update(1, b, a, c); else update(1, a, b, c); } else { memset(vis, 0, sizeof(vis)); scanf("%d%d", &a,&b); if(b > a) query(1, a, b); else query(1, b, a); int sum = 0; for(int i = 1; i <= T; ++i) if(vis[i])sum++; printf("%d\n", sum); } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator