1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #include<bits/stdc++.h> #define RG register #define clear(x, y) memset(x, y, sizeof(x)); using namespace std;
inline int read() { int data=0, w=1; char ch=getchar(); while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar(); if(ch=='-') w=-1, ch=getchar(); while(ch>='0'&&ch<='9') data=(data<<3)+(data<<1)+(ch^48), ch=getchar(); return data*w; }
const int maxn(100010); int n, m, tree[maxn << 2]; double val[maxn << 2];
#define son(i) (root << 1 | i) inline int calc(double v, int root, int l, int r) { if(l == r) return val[root] > v; int mid(l + r >> 1); if(val[son(0)] <= v) return calc(v, son(1), mid + 1, r); return tree[root] - tree[son(0)] + calc(v, son(0), l, mid); }
inline void modify(int pos, double v, int root = 1, int l = 1, int r = n) { if(l == r) { tree[root] = 1, val[root] = v; return; } int mid(l + r >> 1); if(pos <= mid) modify(pos, v, son(0), l, mid); else modify(pos, v, son(1), mid + 1, r); val[root] = max(val[son(0)], val[son(1)]); tree[root] = tree[son(0)] + calc(val[son(0)], son(1), mid + 1, r); }
int main() { n = read(); m = read(); while(m--) { int x = read(), y = read(); modify(x, (double)y / x); printf("%d\n", tree[1]); } return 0; }
|