听说POJ内部测试数据有问题

我这份代码是WA的(UPD:第二份是AC代码),不过目前把discuss的数据试了一下没毛病

自己试了几组好像也没毛病?

感觉线段树部分的简单hash处理方法还是值得学习的,贴出来吧

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
const int maxn = 2e6+11;
bool Hash[30030];
int li[30030],ri[30030];
int arr[maxn],n;
struct ST{
int cover[maxn<<2];
#define lc o<<1
#define rc o<<1|1
void init(){memset(cover,0,sizeof cover);}
void build(int o,int l,int r){
cover[o]=0;
if(l==r) return;
int m=l+r>>1;
build(lc,l,m);
build(rc,m+1,r);
}
void pd(int o){
if(cover[o]){
cover[lc]=cover[rc]=cover[o];
cover[o]=0;
}
}
void update(int o,int l,int r,int L,int R,int v){
if(L<=l&&r<=R){
cover[o]=v;
return;
}
pd(o);
int m=l+r>>1;
if(L<=m) update(lc,l,m,L,R,v);
if(R>m) update(rc,m+1,r,L,R,v);
}
int query(int o,int l,int r,int L,int R){
if(cover[o]){
if(!Hash[cover[o]]){
Hash[cover[o]]=1;
return 1;
}
}
if(l==r) return 0;//base: not found
int m=l+r>>1;
int ans=0;
if(L<=m) ans+=query(lc,l,m,L,R);
if(R>m) ans+=query(rc,m+1,r,L,R);
return ans;
}
}st;
int C(int x){
if(x>=10000000) return 10000000;
else if(x<=1) return 1;
return x;
}
int main(){
int T; scanf("%d",&T);
while(T--){
scanf("%d",&n);
memset(Hash,0,sizeof Hash);
rep(i,1,n){
scanf("%d%d",&li[i],&ri[i]);
arr[i]=li[i];arr[i+n]=ri[i];
}
arr[2*n+1]=1;arr[2*n+2]=10000000;
int tot=2*n+2;
sort(arr+1,arr+1+tot);
int tmp=tot;
rep(i,1,tmp-1){
if(arr[i+1]-arr[i]>1){
arr[++tot]=C(arr[i+1]-1);
arr[++tot]=C(arr[i]+1);
}
}
sort(arr+1,arr+1+tot);
tot=unique(arr+1,arr+1+tot)-arr-1;
rep(i,1,n){
li[i]=lower_bound(arr+1,arr+1+tot,li[i])-arr;
ri[i]=lower_bound(arr+1,arr+1+tot,ri[i])-arr;
// cout<<i<<" "<<li[i]<<" "<<ri[i]<<endl;
}
st.init(); st.build(1,1,tot);
rep(i,1,n){
st.update(1,1,tot,li[i],ri[i],i);
}
printf("%d\n",st.query(1,1,tot,1,tot));
}
return 0;
}

两小时后的UPDATE:

AC代码(忘了pushdown ORZ)

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
const int maxn = 2e6+11;
bool Hash[30030];
int li[30030],ri[30030];
int arr[maxn],n;
struct ST{
int cover[maxn<<2];
#define lc o<<1
#define rc o<<1|1
void build(int o,int l,int r){
cover[o]=0;
if(l==r) return;
int m=l+r>>1;
build(lc,l,m);
build(rc,m+1,r);
}
void pd(int o){
if(cover[o]){
cover[lc]=cover[rc]=cover[o];
cover[o]=0;
}
}
void update(int o,int l,int r,int L,int R,int v){
if(L<=l&&r<=R){
cover[o]=v;
return;
}
pd(o);
int m=l+r>>1;
if(L<=m) update(lc,l,m,L,R,v);
if(R>m) update(rc,m+1,r,L,R,v);
}
int query(int o,int l,int r,int L,int R){
if(cover[o]){
if(!Hash[cover[o]]){
Hash[cover[o]]=1;
return 1;
}
else return 0;
}
pd(o);
if(l==r) return 0;//base: not found
int m=l+r>>1;
int ans=0;
if(L<=m) ans+=query(lc,l,m,L,R);
if(R>m) ans+=query(rc,m+1,r,L,R);
return ans;
}
}st;
int C(int x){
if(x>=10000000) return 10000000;
else if(x<=1) return 1;
return x;
}
int main(){
int T; scanf("%d",&T);
while(T--){
scanf("%d",&n);
memset(Hash,0,sizeof Hash);
rep(i,1,n){
scanf("%d%d",&li[i],&ri[i]);
arr[i]=li[i];arr[i+n]=ri[i];
}
arr[2*n+1]=1;arr[2*n+2]=10000000;
int tot=2*n+2;
sort(arr+1,arr+1+tot);
int tmp=tot;
rep(i,1,tmp-1){
if(arr[i+1]-arr[i]>1){
arr[++tot]=C(arr[i+1]-1);
arr[++tot]=C(arr[i]+1);
}
}
sort(arr+1,arr+1+tot);
tot=unique(arr+1,arr+1+tot)-arr-1;
rep(i,1,n){
li[i]=lower_bound(arr+1,arr+1+tot,li[i])-arr;
ri[i]=lower_bound(arr+1,arr+1+tot,ri[i])-arr;
}
st.build(1,1,tot);
rep(i,1,n){
st.update(1,1,tot,li[i],ri[i],i);
}
printf("%d\n",st.query(1,1,tot,1,tot));
}
return 0;
}

POJ - 2528 奇怪的测试数据的更多相关文章

  1. POJ 2528 Mayor's posters

    Mayor's posters Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  2. poj 2528 Mayor's posters(线段树+离散化)

    /* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...

  3. POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 59239   Accepted: 17157 ...

  4. poj 2528 Mayor's posters 线段树+离散化技巧

    poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...

  5. poj 2528 (线段树+离散化)

    poj 2528 For each input data set print the number of visible posters after all the posters are place ...

  6. POJ - 2528 Mayor's posters(dfs+分治)

    POJ - 2528 Mayor's posters 思路:分治思想. 代码: #include<iostream> #include<cstdio> #include< ...

  7. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  8. POJ 2528——Mayor's posters——————【线段树区间替换、找存在的不同区间】

    Mayor's posters Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  9. poj 2528 线段树区间修改+离散化

    Mayor's posters POJ 2528 传送门 线段树区间修改加离散化 #include <cstdio> #include <iostream> #include ...

随机推荐

  1. struts2 与 spring 整合

    1. 首先把所有jar包导入工程 2.在struts2的核心配置文件(在src文件目录下)中添加如下配置: <!-- 将Struts的对象交给Spring管理 所以需要导入Spring和Stru ...

  2. 18-拍卖叫价(hdu2149 巴什博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=2149 Public Sale Time Limit: 1000/1000 MS (Java/Others)    ...

  3. 面试题:jsp九大内置对象

    我们常说的JSP有九大内置对象分别为:request.response.session.out.pagecontext.page.exception.application.config. 我们知道, ...

  4. Luogu 4841 城市规划

    BZOJ 3456 权限题 太菜了推不出式子 我们设$f(n)$表示$n$个点的无向连通图的数量,那么有 $$f(n) = 2^{\binom{n}{2}} - \sum_{i = 1}^{n - 1 ...

  5. Mybaties核心配置文件

    <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configurationPUBLIC &q ...

  6. http请求和返回的head字段

    一,http请求分请求首部字段,通用首部字段,实体首部字段.http响应包含响应首部字段,通用首部字段,实体首部字段. 二,http1.1定义了47种首部字段.1,通用首部字段:cache-contr ...

  7. [GO]copy的使用

    package main import "fmt" func main() { srcslice := [],} dstslice := [],,,,,} copy(dstslic ...

  8. UIWebView分页显示

    問題:使用iOS UIWebView時,載入本地html檔案,但是該檔案太大,結果螢幕畫面形成一長條型顯示,雖然用滾動畫面可以看見整個html檔案,但是滑來滑去,不好用. 目標:用UIWebView載 ...

  9. Training Very Deep Networks

    Rupesh Kumar SrivastavaKlaus Greff ̈J urgenSchmidhuberThe Swiss AI Lab IDSIA / USI / SUPSI{rupesh, k ...

  10. 常用Linux命令:mount/umount/blkid

    一.mount:挂载命令 1.命令格式 mount [参数] [设备名称] [挂载点] 2.常用参数 -a     :安装在/etc/fstab文件中列出的所有文件系统 -f :伪装mount,做出检 ...