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

这神题(像LS所说)只有写错了才能A。。。。。。无语 一整天搭进去了

Posted by moretimes at 2012-05-18 22:40:28 on Problem 2528
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define lson l, mid, idx << 1
#define rson mid + 1, r, idx << 1 | 1

const int N = 21000;
int tmp[N], h[10001000], T, tcnt, cnt, n, w, l[N], r[N], ans;
int col[N << 4];
bool vis[N];

inline void PushDown(int idx){
	if(col[idx] != 0)
		col[idx << 1] = col[idx << 1 | 1] = col[idx];
	col[idx] = 0;
}

inline void updata(int L, int R, int l, int r, int idx){
	if(L <= l && r <= R){
		col[idx] = w;
		return ;
	}
	int mid = (l + r) >> 1;
	PushDown(idx);
	if(L <= mid) updata(L, R, lson);
	if(R > mid) updata(L, R, rson);
}

inline void query(int l, int r, int idx){
	if(l == r){
		if(!vis[col[idx]])
			ans ++, vis[col[idx]] = true;
		return ;
	}
	int mid = (l + r) >> 1;
	PushDown(idx);
	query(lson);
	query(rson);
}

int main()
{
	scanf("%d", &T);
	while(T --){
		tcnt = 0;
		cnt = 0;
		w = 0;
		memset(col, 0, sizeof col);
		memset(vis, 0, sizeof vis);
		scanf("%d", &n);
		for(int i = 1; i <= n; i ++){
			scanf("%d", &l[i]);
			scanf("%d", &r[i]);
			tmp[++ tcnt] = l[i];
			tmp[++ tcnt] = r[i];
		}
		sort(tmp + 1, tmp + 1 + tcnt);
		for(int i = 1; i <= tcnt; i ++){
			if(tmp[i] == tmp[i - 1])
				h[tmp[i]] = h[tmp[i - 1]];
		//	else if(tmp[i] - tmp[i - 1] > 1)
		//		h[tmp[i]] = h[tmp[i - 1]] + 2;   //有木有 有木有 这样映射才是对的 但删了这句话才能A啊!!!!!!!
			else
				h[tmp[i]] = h[tmp[i - 1]] + 1;
		}
		cnt = h[tmp[tcnt]];
		for(int i = 1; i <= n; i ++){
			w ++;
			updata(l[i], r[i], 1, cnt, 1);
		}
		ans = 0;
		query(1, cnt, 1);
		printf("%d\n", ans);
	}
	while(1);
	return 0;
}

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