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 ...
随机推荐
- css文本设置
常用的应用文本的css样式: color 设置文字的颜色,如: color:red; font-size 设置文字的大小,如:font-size:12px; font-family 设置文字的字体,如 ...
- 【bfs】献给阿尔吉侬的花束
[题目描述] 阿尔吉侬是一只聪明又慵懒的小白鼠,它最擅长的就是走各种各样的迷宫.今天它要挑战一个非常大的迷宫,研究员们为了鼓励阿尔吉侬尽快到达终点,就在终点放了一块阿尔吉侬最喜欢的奶酪.现在研究员们想 ...
- Python3 与 C# 基础语法对比(Function专栏)
Code:https://github.com/lotapp/BaseCode 多图旧版:https://www.cnblogs.com/dunitian/p/9186561.html 在线编程: ...
- CodeFroces-- 514.div2.C-Sequence Transformation
题目链接 :514.div2.C-Sequence Transformation #include<bits/stdc++.h> using namespace std; #define ...
- 把 android 手机变成 web server (golang)
配置 golang 开发环境 略 安装并初始化 gomobile go get golang.org/x/mobile/cmd/gomobile gomobile init 创建 beego 项目, ...
- JS监听滚动条进度
HTML部分: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <s ...
- A1014. Waiting in Line
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...
- 【CF1141F1】Same Sum Blocks
题目大意:给定一个 N 个值组成的序列,求序列中区间和相同的不相交区间段数量的最大值. 题解:设 \(dp[i][j]\) 表示到区间 [i,j] 时,与区间 [i,j] 的区间和相同的不相交区间数量 ...
- python描述器
描述器定义 python中,一个类实现了__get__,__set__,__delete__,三个方法中的任何一个方法就是描述器,仅实现__get__方法就是非数据描述器,同时实现__get__,__ ...
- java开发JDBC连接数据库代码
JDBC连接数据库,创建一个以JDBC连接数据库的程序,包含7个步骤: 1.加载JDBC驱动程序: 这通过java.lang.Class类的静态方法forName(String className)实 ...