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 ...
随机推荐
- 【XSY2787】Mythological VII 贪心
题目描述 有两个指针\(l,r\),初始时\(l=r=k\) 给你\(a_1,\ldots,a_n\),你要移动\(l,r\),\(l\)只能每次向左移一个数,\(r\)只能向右移一个数,要求任意时刻 ...
- 使用Disruptor实现生产者和消费者模型
生产者 package cn.lonecloud.procum.disruptor; import cn.lonecloud.procum.Data; import com.lmax.disrupto ...
- 牛客小白月赛12J(序列自动机)
题目链接:https://ac.nowcoder.com/acm/contest/392/J 题目大意:给一个字符串s,然后在给出n个其他的字符串,判断每个字符串是否为s的子序列. 例: 输入: no ...
- Python3 与 C# 基础语法对比(Function专栏)
Code:https://github.com/lotapp/BaseCode 多图旧版:https://www.cnblogs.com/dunitian/p/9186561.html 在线编程: ...
- 【CF1119D】Frets On Fire
题目大意:给定一个长度为 n 的序列,给定一个恒定的 w,求解 \[\sum\limits_{i=1}^{n}min\{d[i],w\}\] 题解:学会了对最小值和式的快速处理. 若在下标的角度考虑, ...
- python3安装pycurl
centos7安装pycurl 出现错误 FileNotFoundError: [Errno 2] No such file or directory: 'curl-config'ImportErro ...
- [bzoj3524][Couriers]
题目链接 思路 观察这个\((r - l + 1)/2\),很容易证明,如果一个数出现次数大于\((r - l + 1) / 2\),那么这个区间内第\((r - l + 1) / 2 + 1\)大一 ...
- Miniconda 虚拟环境安装及应用
首先要下载Miniconda安装包 下载地址 链接:https://pan.baidu.com/s/1rj-9exKBSHnCCxqq7JQSxA 提取码:ab53 下一步 打开下载好的M ...
- python基础面试常见题
1.为什么学习Python? Python是目前市面上,我个人认为是最简洁.最优雅.最有前途.最全能的编程语言,没有之一. 2.通过什么途径学习的Python? 通过自学,包括网上查看一些视频,购买一 ...
- TestNg 4.组测试中的方法分组测试
看以下代码: package com.course.testng.groups; import org.testng.annotations.AfterGroups; import org.testn ...