ACM-ICPC 2018 南京赛区网络预赛 G Lpl and Energy-saving Lamps(模拟+线段树)
https://nanti.jisuanke.com/t/30996
题意
每天增加m个灯泡,n个房间,能一次性换就换,模拟换灯泡过程。询问第几天的状态
分析
离线做,按题意模拟。比赛时线段树写挫了。。导致不断超时,我太弱了。每次询问符合要求的最左边的点。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
//#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define random(a, b) rand()*rand()%(b-a+1)+a
#define pi acos(-1)
//const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + ;
const int maxm = +;
const int mod = ;
struct ND{
int minn,l,r;
}tree[maxn<<]; int n,m,k[maxn],d[maxn],q;
void pushup(int rt){
tree[rt].minn=min(tree[rt<<].minn,tree[rt<<|].minn);
}
void build(int rt,int l,int r){
tree[rt].l=l,tree[rt].r=r;
if(l==r){
tree[rt].minn=k[l];
return;
}
int mid=(l+r)>>;
build(rt<<,l,mid);
build(rt<<|,mid+,r);
pushup(rt);
} void update(int rt,int pos,int val){
if(tree[rt].l==tree[rt].r){
tree[rt].minn=val;
return;
}
int mid=(tree[rt].l+tree[rt].r)>>;
if(pos<=mid) update(rt<<,pos,val);
else update(rt<<|,pos,val);
pushup(rt);
} int query(int rt,int L,int R,ll val){
if(tree[rt].minn>val) return inf;
if(tree[rt].l==tree[rt].r){
return tree[rt].l;
}
int mid=(tree[rt].l+tree[rt].r)>>;
if(tree[rt<<].minn<=val&&L<=mid) return query(rt<<,L,R,val);
if(tree[rt<<|].minn<=val&&R>mid) return query(rt<<|,L,R,val);
} pair<int,ll> ans[maxn];
bool vis[maxn];
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("input.txt", "w", stdout);
#endif
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&k[i]);
scanf("%d",&q);
for(int i=;i<=q;i++) scanf("%d",&d[i]);
build(,,n);
memset(vis,false,sizeof(vis));
// cout<<query(1,n,n,7);
ll sum=m;
int cnt=,i;
for(i=;i<=1e5+;i++){
int x=;
while(x<=n){
if(vis[x]){
x++;
continue;
}
int tmp=query(,x,n,sum);
if(tmp!=inf){
x=tmp+;
sum-=k[tmp];
vis[tmp]=;
cnt++;
update(,tmp,inf);
}else break;
}
ans[i]=make_pair(cnt,sum);
sum+=m;
if(cnt>=n) break;
}
for(int j=;j<=q;j++){
if(d[j]>=i){
printf("%d %lld\n",ans[i].first,ans[i].second);
}else{
printf("%d %lld\n",ans[d[j]].first,ans[d[j]].second);
}
}
return ;
}
ACM-ICPC 2018 南京赛区网络预赛 G Lpl and Energy-saving Lamps(模拟+线段树)的更多相关文章
- ACM-ICPC 2018 南京赛区网络预赛 G Lpl and Energy-saving Lamps(线段树)
题目链接:https://nanti.jisuanke.com/t/30996 中文题目: 在喝茶的过程中,公主,除其他外,问为什么这样一个善良可爱的龙在城堡里被监禁Lpl?龙神秘地笑了笑,回答说这是 ...
- ACM-ICPC 2018 南京赛区网络预赛 G. Lpl and Energy-saving Lamps(二分+线段树区间最小)
During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Drag ...
- ACM-ICPC 2018 南京赛区网络预赛 G. Lpl and Energy-saving Lamps (弱线段树)
线段树节点维护区间最小值,查找时优先从左侧的区间寻找. 每一次循环都在树中不停寻找第一个小于等于当前持有数的值,然后抹去,直到找不到为止. #include<cstdio> #includ ...
- 计蒜客 30996.Lpl and Energy-saving Lamps-线段树(区间满足条件最靠左的值) (ACM-ICPC 2018 南京赛区网络预赛 G)
G. Lpl and Energy-saving Lamps 42.07% 1000ms 65536K During tea-drinking, princess, amongst other t ...
- ACM-ICPC 2018 南京赛区网络预赛 I Skr (马拉车+hash去重)或(回文树)
https://nanti.jisuanke.com/t/30998 题意 给一串由0..9组成的数字字符串,求所有不同回文串的权值和.比如说“1121”这个串中有“1”,“2”,“11”,“121” ...
- ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)
ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...
- ACM-ICPC 2018 南京赛区网络预赛(12/12)
ACM-ICPC 2018 南京赛区网络预赛 A. An Olympian Math Problem 计算\(\sum_{i=1}^{n-1}i\cdot i!(MOD\ n)\) \(\sum_{i ...
- ACM-ICPC 2018 南京赛区网络预赛 J.sum
A square-free integer is an integer which is indivisible by any square number except 11. For example ...
- ACM-ICPC 2018 南京赛区网络预赛 E题
ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...
随机推荐
- prufer序列
介绍 其实是\(pr\ddot{u}fer\)序列 什么是prufer序列? 我们认为度数为\(1\)的点是叶子节点 有一颗无根树,每次选出编号最小的叶子节点,加到当前prufer序列的后面,然后删掉 ...
- Hdoj 2199.Can you solve this equation? 题解
Problem Description Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solutio ...
- 【BZOJ2940】条纹(博弈论)
[BZOJ2940]条纹(博弈论) 题面 BZOJ 神TM权限题. 题解 我们把题目看成取石子的话,题目就变成了这样: 有一堆\(m\)个石头,每次可以取走\(c,z,n\)个,每次取完之后可以把当前 ...
- 【BZOJ5317】[JSOI2018]部落战争(凸包,闵可夫斯基和)
[BZOJ5317][JSOI2018]部落战争(凸包,闵可夫斯基和) 题面 BZOJ 洛谷 题解 很明显我们只需要两个凸包\(A,B\). 假设询问给定的方向向量是\(v\). 那么现在就是判断\( ...
- js中的arguments用法
//arguments对象并不是一个数组,但是访问单个参数的方式与访问数组元素的方式相同 function show(){ console.log(arguments); //arguments.pu ...
- 「SCOI2015」小凸想跑步 解题报告
「SCOI2015」小凸想跑步 最开始以为和多边形的重心有关,后来发现多边形的重心没啥好玩的性质 实际上你把面积小于的不等式列出来,发现是一次的,那么就可以半平面交了 Code: #include & ...
- hdu 2516(Fibonacci博弈博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2516 Problem Description 1堆石子有n个,两人轮流取.先取者第1次可以取任意多个, ...
- Gym - 100989F
You must have heard about Agent Mahone! Dr. Ibrahim hired him to catch the cheaters in the Algorithm ...
- A1138. Postorder Traversal
Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and in ...
- YSLOW(一款实用的网站性能检测工具)
概述 YSlow是Yahoo发布的一款基于FireFox的插件,这个插件可以分析网站的页面,并告诉你为了提高网站性能,如何基于某些规则而进行优化. 安装 官网:http://yslow.org/ ...