HTTP://WWW.LYDSY.COM/JUDGEONLINE/PROBLEM.PHP?ID=3110 (Topic link)
Test instructions
There are n positions, m operations. There are two kinds of operations, each operation if it is 1 a B C in the form of a position in the first place to the B position, each position to add a number C, if it is a 2 a B c form, the query from the first position to the B position, the number of C large is how much.
Solution
Integral two-part entry question.
For an operation, we have a two-part answer, Mid, which adds a number C greater than or equal to mid in the modification operation (maintains a tree array to maintain the number of numbers greater than or equal to mid in an interval). Then for the query to determine whether C is greater than or equal to the number of the greater than or equal to mid, and then continue to recursively.
Details
The second-largest two-point write I flustered, the whole is reversed.
Code
bzoj3110#include<algorithm> #include <iostream> #include <cstdlib> #include <cstring># include<cstdio> #include <cmath> #define LL long long#define MOD 100000000#define inf 2147483640#define Pi ACOs ( -1.0) #define FREE (a) freopen (a ".", "R", stdin), Freopen (a ". Out", "w", stdout); using namespace Std;const int maxn= 50010;struct data {int t,l,r,k,id;} A[MAXN],TR[MAXN],TL[MAXN]; LL c1[maxn],c2[maxn];int ans[maxn],n,m;int lowbit (int x) {return x&-x;} ll query (int x) {LL res=0;for (int i=x;i;i-=lowbit (i)) res+= (x+1) *c1[i]-c2[i];return Res;} void Add (int x,int val) {for (int i=x;i<=n;i+=lowbit (i)) c1[i]+=val,c2[i]+= (LL) X*val;} void Solve (int l,int r,int l,int R) {if (l>r) return;if (l==r) {for (int i=l;i<=r;i++) Ans[a[i].id]=l;return;} int mid= (l+r+1) >>1,ll=0,rr=0,fl=0,fr=0;for (int i=l;i<=r;i++) {if (a[i].t==1) {if (A[i].k>=mid) Add (a[i].l , 1), add (a[i].r+1,-1), Tr[++rr]=a[i];else tl[++ll]=a[i];} else {LL x=query (A[I].R)-query (A[I].L-1); if (X>=A[I].K) Tr[++rr]=a[i],fr=1;else a[i].k-=x,tl[++ll]=a[i],fl=1;}} for (int i=l;i<=r;i++) if (a[i].t==1 && a[i].k>=mid) Add (a[i].l,-1), add (a[i].r+1,1), and for (int i=1;i<=ll ; i++) a[l+i-1]=tl[i];for (int i=1;i<=rr;i++) a[l+ll+i-1]=tr[i];if (fl) solve (l,l+ll-1,l,mid-1); if (FR) Solve (l+ll,r , mid,r);} int main () {scanf ("%d%d", &n,&m), int tot=0;for (int i=1;i<=m;i++) {scanf ("%d%d%d%d", &a[i].t,&a[i]. L,&A[I].R,&A[I].K); if (a[i].t==2) A[i].id=++tot;} Solve (1,m,1,n); for (int i=1;i<=tot;i++) printf ("%d\n", Ans[i]); return 0;}
"bzoj3110" zjoi2013-k large number of queries