Atcoder Beginner Contest153F(模拟)

应该也可以用线段树/树状数组区间更新怪兽的生命值来做

 1 #define HAVE_STRUCT_TIMESPEC
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 long long pre[200007];
 5 int main(){
 6     ios::sync_with_stdio(false);
 7     cin.tie(NULL);
 8     cout.tie(NULL);
 9     long long n,d,a;
10     cin>>n>>d>>a;
11     vector<pair<long long,long long> >v;
12     for(int i=1;i<=n;++i){
13         long long x,y;
14         cin>>x>>y;
15         long long z=(y-1)/a+1;
16         v.push_back({x,z});
17     }
18     sort(v.begin(),v.end());
19     long long ans=0;
20     long long sum=0;
21     int r=1;//打不到的最近范围
22     for(int i=0;i<n;++i){
23         while(r<n&&v[r].first<=v[i].first+2*d)
24             ++r;
25         sum-=pre[i];//sum为当前位置已经预先承受的伤害总量
26         v[i].second-=sum;
27         if(v[i].second<=0)
28             continue;
29         sum+=v[i].second;//累计伤害
30         pre[r]+=v[i].second;//r位置以前承受的伤害总量
31         ans+=v[i].second;
32     }
33     cout<<ans;
34     return 0;
35 }

原文地址:https://www.cnblogs.com/ldudxy/p/12236129.html

时间: 2024-08-03 15:50:04

Atcoder Beginner Contest153F(模拟)的相关文章

【ATcoder】AtCoder Beginner Contest 161 题解

题目链接:AtCoder Beginner Contest 161 原版题解链接:传送门 A - ABC Swap 这题太水,直接模拟即可. 1 #include <iostream> 2 using namespace std; 3 int main() { 4 int a, b, c; 5 cin >> a >> b >> c; 6 swap(a, b); 7 swap(a, c); 8 cout << a << " &

AtCoder Beginner Contest 103 D(贪心)

AtCoder Beginner Contest 103 D 题目大意:n个点,除第n个点外第i与第i+1个点有一条边,给定m个a[i],b[i],求最少去掉几条边能使所有a[i],b[i]不相连. 按右端点从小到大排序,如果当前选的去掉的边在区间内,那么符合条件,否则ans++,并贪心地把去掉的边指向右端点,因为前面的区间都满足条件了,所以要去掉的边要尽量向右移使其满足更多的区间. 1 #include <iostream> 2 #include <cstdio> 3 #incl

AtCoder Beginner Contest 136

AtCoder Beginner Contest 136 Contest Duration : 2019-08-04(Sun) 20:00 ~ 2019-08-04(Sun) 21:40 Website: AtCoder BC-136 后面几题都挺考思考角度D. C - Build Stairs 题目描述: 有n座山从左到右排列,给定每一座山的高度\(Hi\),现在你可以对每座山进行如下操作至多一次:将这座山的高度降低1. 问是否有可能通过对一些山进行如上操作,使得最后从左至右,山的高度呈不下降

AtCoder Beginner Contest 154 题解

人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We have A balls with the string S written on each of them and B balls with the string T written on each of them. From these balls, Takahashi chooses one

AtCoder Beginner Contest 155 简要题解

AtCoder Beginner Contest 155 A:签到失败,WA一次. int main() { int a, b, c; cin >> a >> b >> c; if(a == b && b == c) cout << "No"; else if(a == b || a == c || b == c) cout << "Yes"; else cout << &quo

AtCoder Beginner Contest 152 - F - Tree and Constraints (容斥定理+树上路径的性质)

AtCoder Beginner Contest 152 - F - Tree and Constraints (容斥定理+树上路径的性质) We have a tree with NN vertices numbered 11 to NN. The ii-th edge in this tree connects Vertex aiai and Vertex bibi. Consider painting each of these edges white or black. There ar

AtCoder Beginner Contest 121 题解

题目链接:https://atcoder.jp/contests/abc121 A White Cells 分析:题目数据规模很小,直接暴力修改都可以.或者可以推出公式. 代码: 1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 6 int main() 7 { 8 int a[25][25] = {0}; 9 int H, W, h, w; 10 scanf("%d %d"

AtCoder Beginner Contest 106 ABCD

A - Garden Problem Statement There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents

比赛总结——atcoder beginner contest 109

第一次AK的ABC 虽然题非常简单 但是值得纪念一下 T1 一道很水的题 不存在做法 纯粹乱跑 但是我把Yes打成YES了,哭唧唧 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int main(){ int a,b; scanf("%d %d",&a,&b); if((1*a*b)%2==1||(2*a*b)%2==1||