Test instructions
At the beginning of the skating club there are 1 to n skates each K-double, the X-foot person can wear X-to-x+d skates,;
There are m operations, each containing two number ri,xi, representing the person who came with the XI Ri number foot (xi may be negative);
For each operation, the output skates are sufficient;
n<=200000,m<=500000,k<=10^9;
Exercises
First of all, this is a two-figure matching problem, obviously there is no intersection between shoes and people;
Then there is a hall theorem:
The set of two vertices in the two section of Figure G is X, Y, respectively;
There is a set of edges with no common points in the edge set, and the sufficient and necessary conditions for all the points that make up the X are:
Any k points in X are at least adjacent to the k points in Y; (1≤k≤m)
Adjacent refers to the side of the link, in the X of the choice of K we use any of the optional interval instead;
So in a period of [l,r], the number of x feet is f (x);
∑f (i) <= (r-l+d+1) *k (L<=I<=R) was established;
Each f (i) is reduced by one k, and inequalities can be converted into;
∑ (F (i)-K) <=d*k (L<=I<=R);
This formula is chosen as a section of the set;
Then only ask the maximum interval and judge whether it is greater than d*k can be;
Segment tree maintenance, Complexity O (MLOGN);
Code:
#include <stdio.h> #include <string.h> #include <algorithm> #define N 210000#define Lson l,mid,no< <1#define Rson mid+1,r,no<<1|1using namespace Std;typedef long long ll;struct seg{ll l,r,ma,sum; Seg () {}seg (ll x) {l=r=ma=sum=x;} Friend Seg operator + (SEG l,seg r) {seg Ret;ret.sum=l.sum+r.sum;ret. L=max (L.L,L.SUM+R.L); ret. R=max (R.R,R.SUM+L.R); Ret.ma=max (L.r+r.l,max (l.ma,r.ma)); return ret;}} Tr[n<<2];void Pushup (ll No) {tr[no]=tr[no<<1]+tr[no<<1|1];} void Build (ll l,ll r,ll no,ll k) {if (l==r) tr[no]=seg (-K); Else{ll mid=l+r>>1; Build (LSON,K); Build (RSON,K); Pushup (No);}} void Update (LL l,ll r,ll no,ll x,ll val) {if (l==r) tr[no]=seg (tr[no].sum+val); Else{ll mid=l+r>>1;if (X<=mid) Update (lson,x,val); elseupdate (Rson,x,val); Pushup (No);}} int main () {ll n,m,d,i,j,k,x,r;scanf ("%lld%lld%lld%lld", &n,&m,&k,&d); Build (1,n,1,k), for (i=1;i<=m;i++) {scanf ("%lld%lld", &r,&x); update (1,n,1,r,x); if (tr[1].ma> (LL) d*k) Puts ("NIE"); Elseputs ("TAK"); REturn 0;}
bzoj-1135 Lyz