Description given n building, the initial height of 0, each time can change the height of a building, for each change in height from the origin can be seen several buildings solution 11 more obvious is a block, assuming that the size of the block is S, divided into L block, Maintain the slope of each block in a monotonically rising sequence each time the violence modifies the complexity to O(S) For each query, the first two points in each sequence are greater than the previous slope position, the complexity O(L?Log N ) Obviously S =N /S ?Log N thatS =< Span class= "Mrow" id= "mathjax-span-414" > n l o g n ? ? ? ? ? ? √ Solution 2 In fact, we can also use line tree to do, modify a value is actually in front of it has no effect on the building, we can use the line segment tree to maintain a maximum value and can see the number of buildings are normal monotonous modification, while maintaining the answer, Each maintenance is actually the left side of the answer plus the right side is greater than the left side of the maximum value of the part of the complexity O(N Lo g 2 N ) Code1 (sub-block)
#include <bits/stdc++.h>using namespace STD;typedef Long LongLL;Const intN =100005;Const DoubleEPS =1e-10;intcnt[ the];DoubleA[n], b[ the][1300];inline intReadint&t) {intf =1;CharC while(c = GetChar (), C <' 0 '|| C >' 9 ')if(c = ='-') F =-1; T = C-' 0 '; while(c = GetChar (), C >=' 0 '&& C <=' 9 ') T = T *Ten+ C-' 0 '; T *= F;}intMain () {intN, m, x, y; Read (n), read (m);intS = (int)sqrt(n *Log(n)/Log(2) +0.5), L = N/S + (n% S?)1:0); while(m--) {Read (x), read (y); A[x-1] = (Double) y/x;intBL = (--x)/S; CNT[BL] =0;Doublenow =0.0; for(inti = bl * S; I < (BL +1) * S && i < n; ++i)if(A[i] > now + EPS) b[bl][cnt[bl]++] = A[i], now = a[i]; now =0.0;intAns =0; for(inti =0; i < L; ++i) {intL =0, r = Cnt[i]-1;intT while(L <= R) {intMID = L + R >>1;if(B[i][mid] > now + EPS) T = Mid, R = mid-1;ElseL = mid +1; }if(B[i][cnt[i]-1] > Now + eps) ans + = cnt[i]-T; now = Max (now, B[i][cnt[i]-1]); }printf("%d\n", ans); }return 0;}
Code2 (segment tree)
#include <bits/stdc++.h>using namespace STD;#define LS (rt << 1)#define RS (rt << 1 | 1)Const intN =100005;intCnt[n <<2];DoubleMx[n <<2];inline intReadint&t) {intf =1;CharC while(c = GetChar (), C <' 0 '|| C >' 9 ')if(c = ='-') F =-1; T = C-' 0 '; while(c = GetChar (), C >=' 0 '&& C <=' 9 ') T = T *Ten+ C-' 0 '; T *= F;}intCalcintRtintLintRDoublex) {if(L = = r)returnMX[RT] > x;intMID = L + R >>1;if(Mx[ls] <= x)returnCalc (RS, Mid +1, R, X);Else returnCNT[RT]-Cnt[ls] + calc (LS, l, Mid, X);}voidChangeintRtintLintRintPDoublex) {if(L = = r) {MX[RT] = x; CNT[RT] =1;return; }intMID = L + R >>1;if(P <= mid) change (LS, L, Mid, p, X);ElseChange (RS, Mid +1, R, p, x); MX[RT] = max (Mx[ls], mx[rs]); CNT[RT] = Cnt[ls] + calc (RS, Mid +1, R, Mx[ls]);}intMain () {intN, m, x, y; Read (n), read (m); while(m--) {Read (x), read (y); Change1,1, N, X, (Double) y/x);printf("%d\n", cnt[1]); }return 0;}
Bzoj 2957 Building reconstruction