现在看到这种区间线段的题条件反射就想到了hash(似乎除了hash也想不出别的啥好办法)
不过这一题给的最大数是1000000,如果再用上2000,2000*1000000=2000000000(20亿次)也是生命不可承受之重了= =
不过一次就AC了~就不去想其他啦
话说回来,CCF的前两题感觉确实是送分题,争取都拿下(拿满分)才是最重要的~
代码:
#include <stdio.h>
#include <algorithm>
using namespace std;
bool hhashh[1000000] = {false};
bool hhashw[1000000] = {false};
bool ans[1000000] = {false};
int main(){
int n,a,b,c,d;
int cnt = 0;
scanf("%d",&n);
for(int i = 0;i <n;i++){
scanf("%d %d",&a,&b);
for(int j = a;j <b;j++){
hhashh[j] = true;
}
}
for(int i = 0;i <n;i++){
scanf("%d %d",&c,&d);
for(int j = c;j <d;j++){
hhashw[j] = true;
if(hhashh[j] == true){
ans[j] = true;
}
}
}
for(int i = 0;i <1000000;i++){
if(ans[i] == true){
cnt++;
}
}
printf("%d",cnt);
}