Click to open link
Build by line tree [0, N]
Known [L, r] nodes to find n
If you build a line tree [0, 2*r] This is the singular of the total number of points (left subtree!). = Right Sub-tree
[0, R] in Shari n Max is 2*r
If a line segment tree [0, 2*r+1] is built (left subtree = = right subtree)
[0, R] in the left subtree then [0, R] can build
So when the search is over 2*r, return directly.
#include <cstdio> #include <cstring> #include <cstdlib> #include <string> #include <iostream > #include <algorithm> #include <sstream> #include <cmath>using namespace std; #include <queue > #include <stack> #include <vector> #include <deque> #define Cler (arr, Val) memset (arr, Val, sizeof ( ARR)) #define for (I,A,B) for (int. i=a;i<=b;i++) #define IN Freopen ("In.txt", "R", stdin), and #define out freopen ("out". TXT "," w ", stdout); typedef long LONG ll;const int MAXN = 101000;const int MAXM = 200000;const int INF = 0x3f3f3f3f;cons t int mod = 1000000007;const double eps= 1e-8; #define Lson l,m,rt<<1#define Rson m+1,r,rt<<1|1ll ans,flag,l,r; void Dfs (LL l,ll r) {if (r>2*r| | Flag&&r>=ans) return; if (l==0) {flag=1; Ans=r; return; } LL len=r-l+1; if (l-len-1>=0) DFS (L-LEN-1,R); if (l-len>=0) DFS (L-LEN,R); DFS (L,R+LEN-1); DFS (L,r+len);} int main () {while (scanf ("%i64d%i64d", &l,&r)!=eof) {ans=inf;flag=0; DFS (L,R); if (Ans==inf) puts ("-1"); else printf ("%i64d\n", ans); } return 0;} /**/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Search" HDU 5323 Solve This interesting problem