记录编号 |
152552 |
评测结果 |
AAAAAAAAAAAAAAAAAAAAA |
题目名称 |
[HAOI 2014]贴海报 |
最终得分 |
100 |
用户昵称 |
Asm.Def |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.007 s |
提交时间 |
2015-03-14 23:15:17 |
内存使用 |
0.33 MiB |
显示代码纯文本
#include <cctype>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <set>
using namespace std;
#ifdef DEBUG
FILE *in = fopen("test.txt", "r");
//#define in stdin
#define out stdout
#else
FILE *in = fopen("ha14d.in", "r");
FILE *out = fopen("ha14d.out", "w");
#endif
#define getc() fgetc(in)
template<class T>inline void getd(T &x){
char ch = getc();bool neg = false;
while(ch != '-' && !isdigit(ch))ch = getc();
if(ch == '-')neg = true, ch = getc();
x = ch - '0';
while(isdigit(ch = getc()))x = x * 10 - '0' + ch;
if(neg)x = -x;
}
/******************************************************************/
const int maxn = 1002;
bool vis[maxn];
struct Eve{
int loc, id;
bool beg;
inline bool operator < (const Eve &b)const{return loc < b.loc;}
}E[maxn<<1], *End = E;
int N, M;
inline void init(){
getd(N), getd(M);
int i, A, B;
for(i = 0;i < M;++i){
getd(A), getd(B);
End->loc = A, End->id = i, End->beg = true;++End;
End->loc = B + 1, End->id = i, End->beg = false;++End;
}
sort(E, End);
}
#include <functional>
set<int, greater<int> > S;
inline void work(){
int Ans = 0, loc = E->loc;
Eve *it = E;
while(it < End){
while(it < End && it->loc == loc){
if(it->beg)S.insert(it->id);
else S.erase(S.find(it->id));
++it;
}
if(!S.empty())vis[*S.begin()] = true;
loc = it->loc;
}
for(int i = 0;i < M;++i)if(vis[i]) ++Ans;
fprintf(out, "%d\n", Ans);
}
int main(){
init();
work();
#ifdef DEBUG
//printf("\n%.2lfsec\n", (double)clock() / CLOCKS_PER_SEC);
#endif
return 0;
}