YYHS-手机信号

题目描述

输入

输出

样例输入

11 10000
query 5
construct 5 500 100
query 500
query 1000
construct 10 90 5
query 44
destruct 44 66
query 55
construct 50 60 3
query 46
query 6000

样例输出

0
975
0
9999
9775
9984
0

提示

 

 

题解

这道题给你三种操作(这道题用set维护区间)

对于construct操作,我们可以发现加入的区间要么和所有的区间都不相交,要么就是区间的大小比某个区间的v还要小

construct操作读入的x,y我们可以可以把y改成x+(y-x)/v*v(最后一个信号站的位置)

对于destruct操作,我们判断一下左右端点是否把其他的区间截断了

对于query操作,我们只要找一下离这个点最近的一个区间就可以了

具体细节可以看一下代码

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 struct node{
 5     int x,y,v;
 6     bool operator <(const node &a) const{
 7         return x<a.x;
 8     }
 9 };
10 typedef multiset<node>::iterator It;
11 int m,l,r,v,x,y;
12 ll c;
13 char s[20];
14 multiset<node> q;
15 int calc(int x,int y,int v){ return x+(y-x)/v*v; }
16 void solve_c(){
17     scanf("%d%d%d",&x,&y,&v);
18     y=calc(x,y,v);
19     It point=q.upper_bound((node){x,0,0});
20     if (point!=q.begin()){
21         point--;
22         int st=point->x,ed=point->y;
23         if (st<x&&ed>y){
24             int stp=point->v;
25             q.erase(point);
26             q.insert((node){st,calc(st,x,stp),stp});
27             if (st!=ed)
28                 q.insert((node){calc(st,x,stp)+stp,ed,stp});
29         }
30     }
31     q.insert((node){x,y,v});
32 }
33 void solve_d(){
34     scanf("%d%d",&x,&y);
35     It point=q.lower_bound((node){x,0,0});
36     if (point!=q.begin()){
37         point--;
38         int st=point->x,ed=point->y;
39         if (st<x&&ed>=x){
40             int stp=point->v;
41             q.erase(point);
42              q.insert((node){st,calc(st,x-1,stp),stp});
43              if (ed>y)
44                  q.insert((node){calc(st,r,stp)+stp,ed,stp});
45         }
46     }
47     point=q.upper_bound((node){y,0,0});
48     if (point!=q.begin()){
49         point--;
50         int st=point->x,ed=point->y;
51         if (st<=y&&ed>y){
52             int stp=point->v;
53             q.erase(point);
54             q.insert((node){calc(st,y,stp)+stp,ed,stp});
55         }
56     }
57     q.erase(q.lower_bound((node){x,0,0}),q.upper_bound((node){y,0,0}));
58 }
59 void solve_q(){
60     scanf("%d",&x);
61     int d=1e9;
62     It point=q.lower_bound((node){x,0,0});
63     if (point!=q.end()) d=min(d,point->x-x);
64     if (point!=q.begin()){
65         point--;
66         int st=point->x,ed=point->y;
67         if (ed>=x){
68             int stp=point->v;
69             d=min(d,x-calc(st,x,stp));
70             if (st!=ed) d=min(d,calc(st,x,stp)+stp-x);
71         } else d=min(d,x-point->y);
72     }
73     if (d==1e9) puts("0");
74             else printf("%lld\n",max(0ll,c-(ll)d*d));
75 }
76 int main(){
77     scanf("%d%lld",&m,&c);
78     for (int i=1;i<=m;i++){
79         scanf("%s",s); 
80         if (s[0]=='q') solve_q(); else
81         if (s[0]=='c') solve_c(); else
82         if (s[0]=='d') solve_d();
83     }
84     return 0;
85 }
View Code

 

转载于:https://www.cnblogs.com/zhuchenrui/p/7678356.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值