10pts 悬赏关注

P4198 楼房重建

```cpp #include <cstdio> #ifdef ONLINE_JUDGE #define freopen(a, b, c) #define printtime() #else #include <ctime> #define printtime() printf("Times used = %ld ms\n", clock()) #endif #define ci const int #define cl const long long typedef long long int ll; namespace IPT { const int L = 1000000; char buf[L], *front=buf, *end=buf; char GetChar() { if (front == end) { end = buf + fread(front = buf, 1, L, stdin); if (front == end) return -1; } return *(front++); } } template <typename T> inline void qr(T &x) { char ch = IPT::GetChar(), lst = ' '; while ((ch > '9') || (ch < '0')) lst = ch, ch=IPT::GetChar(); while ((ch >= '0') && (ch <= '9')) x = (x << 1) + (x << 3) + (ch ^ 48), ch = IPT::GetChar(); if (lst == '-') x = -x; } template <typename T> inline void ReadDb(T &x) { char ch = IPT::GetChar(), lst = ' '; while ((ch > '9') || (ch < '0')) lst = ch, ch = IPT::GetChar(); while ((ch >= '0') && (ch <= '9')) x = x * 10 + (ch ^ 48), ch = IPT::GetChar(); if (ch == '.') { ch = IPT::GetChar(); double base = 1; while ((ch >= '0') && (ch <= '9')) x += (ch ^ 48) * ((base *= 0.1)), ch = IPT::GetChar(); } if (lst == '-') x = -x; } namespace OPT { char buf[120]; } template <typename T> inline void qw(T x, const char aft, const bool pt) { if (x < 0) {x = -x, putchar('-');} int top=0; do {OPT::buf[++top] = static_cast<char>(x % 10 + '0');} while (x /= 10); while (top) putchar(OPT::buf[top--]); if (pt) putchar(aft); } const int maxn = 100010; struct Info { int v; double mh; Info() {v = mh = 0;} }; struct Tree { Tree *ls, *rs; int l, r; Info v; Tree() {ls = rs = NULL;} int calc(double _v) { if (this->v.mh <= _v) return 0; if (!this->ls) return 1; if (this->ls->v.mh <= _v) return this->rs->calc(_v); else return this->ls->calc(_v) + this->v.v - this->ls->v.v; } void pushup() { if (this->ls->v.mh >= this->rs->v.mh) { this->v = this->ls->v; return; } else { this->v.mh = this->rs->v.mh; this->v.v = this->ls->v.v + this->rs->calc(this->ls->v.mh); } } }; Tree *rot; int n, m; void build(Tree*, ci, ci); void update(Tree*, ci, const double); int main() { freopen("1.in", "r", stdin); qr(n); qr(m); rot = new Tree; build(rot, 0, n); int a, b; while (m--) { a = b = 0; qr(a); qr(b); update(rot, a, 1.0 * b / a); qw(rot->v.v - 1, '\n', true); } printtime(); } void build(Tree *u, ci l, ci r) { u->l = l; u->r = r; if (l == r) {u->v.v = 1; return;} int mid = (l + r) >> 1; build(u->ls = new Tree, l, mid); build(u->rs = new Tree, mid + 1, r); u->pushup(); } void update(Tree *u, ci p, const double v) { if ((u->l > p) || (u->r < p)) return; if (u->l == u->r) { u->v.mh = v; return; } update(u->ls, p, v); update(u->rs, p, v); u->pushup(); } ```
by EARS_TURE @ 2023-11-19 15:14:13


@[koobee](/user/365296) 代码给你了
by EARS_TURE @ 2023-11-19 15:17:44


谢谢,已经A了
by koobee @ 2023-11-19 15:34:01


|