Title Description
Input
Output
Sample input10000 Query 5 construct 5 query construct 5 query destruct-up query + construct 3 Query 6000Sample output0 975 0 9999 9775 9984 0Tips
Exercises
This problem gives you three kinds of operation (this problem with set maintenance interval)
For the construct operation, we can find that the join interval does not intersect all the intervals, or that the interval is smaller than the V in a certain interval.
Construct operation read X, y we can change Y to x+ (y-x)/v*v (the position of the last signal station)
For the destruct operation, we determine whether the left and right endpoints have truncated the other intervals.
For the query operation, we just need to find the nearest interval from this point.
See the code for specific details
1#include <bits/stdc++.h>2 #definell Long Long3 using namespacestd;4 structnode{5 intx,y,v;6 BOOL operator< (ConstNode &a)Const{7 returnx<a.x;8 }9 };Tentypedef multiset<node>:: iterator It; One intm,l,r,v,x,y; A ll C; - Chars[ -]; -Multiset<node>Q; the intCalcintXintYintV) {returnx+ (y-x)/v*v;} - voidSolve_c () { -scanf"%d%d%d",&x,&y,&v); -y=Calc (x,y,v); +It point=q.upper_bound (node) {x,0,0}); - if(point!=Q.begin ()) { +point--; A intSt=point->x,ed=point->y; at if(st<x&&ed>y) { - intStp=point->v; - q.erase (point); - Q.insert (node) {St,calc (ST,X,STP), STP}); - if(st!=ed) -Q.insert (node) {calc (ST,X,STP) +STP,ED,STP}); in } - } to Q.insert (node) {x,y,v}); + } - voidsolve_d () { thescanf"%d%d",&x,&y); *It point=q.lower_bound (node) {x,0,0}); $ if(point!=Q.begin ()) {Panax Notoginsengpoint--; - intSt=point->x,ed=point->y; the if(st<x&&ed>=x) { + intStp=point->v; A q.erase (point); theQ.insert (node) {St,calc (st,x-1, STP), STP}); + if(ed>y) -Q.insert (node) {calc (ST,R,STP) +STP,ED,STP}); $ } $ } -Point=q.upper_bound (node) {y,0,0}); - if(point!=Q.begin ()) { thepoint--; - intSt=point->x,ed=point->y;Wuyi if(st<=y&&ed>y) { the intStp=point->v; - q.erase (point); WuQ.insert (node) {calc (ST,Y,STP) +STP,ED,STP}); - } About } $Q.erase (Q.lower_bound (node) {x,0,0}), Q.upper_bound ((node) {y,0,0})); - } - voidsolve_q () { -scanf"%d",&x); A intD=1e9; +It point=q.lower_bound (node) {x,0,0}); the if(Point!=q.end ()) D=min (d,point->x-x); - if(point!=Q.begin ()) { $point--; the intSt=point->x,ed=point->y; the if(ed>=x) { the intStp=point->v; theD=min (d,x-Calc (ST,X,STP)); - if(st!=ed) D=min (D,calc (ST,X,STP) +stp-x); in}ElseD=min (d,x-point->y); the } the if(D==1E9) puts ("0"); About Elseprintf"%lld\n", Max (0ll,c-(LL) d*d)); the } the intMain () { thescanf"%d%lld",&m,&c); + for(intI=1; i<=m;i++){ -scanf"%s", s); the if(s[0]=='Q') Solve_q ();ElseBayi if(s[0]=='C') Solve_c ();Else the if(s[0]=='D') solve_d (); the } - return 0; -}View Code
yyhs-Cell Phone Signal