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(模拟+线段树)的更多相关文章

  1. ACM-ICPC 2018 南京赛区网络预赛 G Lpl and Energy-saving Lamps(线段树)

    题目链接:https://nanti.jisuanke.com/t/30996 中文题目: 在喝茶的过程中,公主,除其他外,问为什么这样一个善良可爱的龙在城堡里被监禁Lpl?龙神秘地笑了笑,回答说这是 ...

  2. 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 ...

  3. ACM-ICPC 2018 南京赛区网络预赛 G. Lpl and Energy-saving Lamps (弱线段树)

    线段树节点维护区间最小值,查找时优先从左侧的区间寻找. 每一次循环都在树中不停寻找第一个小于等于当前持有数的值,然后抹去,直到找不到为止. #include<cstdio> #includ ...

  4. 计蒜客 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 ...

  5. ACM-ICPC 2018 南京赛区网络预赛 I Skr (马拉车+hash去重)或(回文树)

    https://nanti.jisuanke.com/t/30998 题意 给一串由0..9组成的数字字符串,求所有不同回文串的权值和.比如说“1121”这个串中有“1”,“2”,“11”,“121” ...

  6. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

  7. 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 ...

  8. ACM-ICPC 2018 南京赛区网络预赛 J.sum

    A square-free integer is an integer which is indivisible by any square number except 11. For example ...

  9. ACM-ICPC 2018 南京赛区网络预赛 E题

    ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...

随机推荐

  1. Chessboard POJ - 2446(最大流 || 匹配)

    there is a pair of integers (x, y) in each line, which represents a hole in the y-th row, the x-th c ...

  2. 全局最小割Stoer-Wagner算法

    借鉴:http://blog.kongfy.com/2015/02/kargermincut/ 提到无向图的最小割问题,首先想到的就是Ford-Fulkerson算法解s-t最小割,通过Edmonds ...

  3. MT【282】一道几何题

    2010浙江省数学竞赛,附加题. 设$D,E,F$分别为$\Delta ABC$的三边$BC,CA,AB$上的点,记$\alpha=\dfrac{BD}{BC},\beta=\dfrac{BD}{BC ...

  4. python的生成器与迭代器和可迭代对象

    来简单的说下python中的生成器和可迭代对象以及迭代器的问题.只是简单地记录一下并不涉及太深入的内容. 首先来说一下什么是生成器,先看下面的代码: #_*_ coding:utf-8 _*_ res ...

  5. python学习日记(数据结构习题)

    元素分类 有如下值li= [11,22,33,44,55,66,77,88,99,90],将所有大于 66 的值保存至字典的第一个key中,将小于 66 的值保存至第二个key的值中.即: {'k1' ...

  6. centos install redmine (项目管理工具)

    安装环境:Centos.mysql.Ruby.Apache.Redmineyum updateyum -y groupinstall "Development Tools"yum ...

  7. Hdoj 1548.A strange lift 题解

    Problem Description There is a strange lift.The lift can stop can at every floor as you want, and th ...

  8. 「浙大ACM」图森未来杯游记一篇以及简易口胡题解

    前言 蒟蒻有参加了ACM比赛,这一次有适合HY和慕容宝宝大佬一起比的,他们好巨啊,把我带飞了. 又是窝掌机,QAQ,他们仗着自己巨,就欺负窝... 我又打了\(4\)个小时的代码,而且那个键盘太恶心了 ...

  9. Educational Codeforces Round 46 C - Covered Points Count

    C - Covered Points Count emmm 好像是先离散化一下 注意 R需要+1 这样可以确定端点 emmm 扫描线?瞎搞一下? #include<bits/stdc++.h&g ...

  10. 搭建高可用的Redis服务,需要注意这些方面!

    搭建高可用的Redis服务,需要注意这些方面! HorstXu 占小狼的博客 今天 ◎作者 | HorstXu www.cnblogs.com/xuning/p/8464625.html 基于内存的R ...