C 城市规划
ps:想复杂了,记录每个点靠的最近的左端点和枚举到这个点时,上次切割的位置。(每次切割都切右端点)
namespace fastIO { #define BUF_SIZE 100000 bool IOerror = 0; inline char nc() { static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE; if(p1 == pend) { p1 = buf; pend = buf + fread(buf, 1, BUF_SIZE, stdin); if(pend == p1) { IOerror = 1; return -1; } } return *p1++; } inline bool blank(char ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; } inline void read(int &x) { char ch; while(blank(ch = nc())); if(IOerror) return; for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0'); } #undef BUF_SIZE }; using namespace fastIO; const int N = 1000005; int n, m; int a[N]; int main() { read(n); read(m); int l, r; Rep(i, 1, m) { read(l); read(r); if (a[r] < l) a[r] = l; } int ans = 0, cut = a[1]; Rep(i, 1, n) if (a[i]) { if (a[i] >= cut) { ans++; cut = i; } } pr(ans); return 0; }
D XOR序列