CSUOJ 1532 JuQueen
Problem H
JuQueen
JuQueen is the super computer with the best performance allover Germany. It is on rank 8 in the famous top500 list with its 458752 cores. It draws a lot of energy (up to 2301 kW), so we want to reduce that by underclocking the unused cores.
The cluster scheduling algorithm which is in charge of distributing jobs over the nodes and cores of a cluster will issue the following speedstepping commands:
- change X S changes the frequency of core X by S steps
- groupchange A B S changes the frequency of every core in range [A,B] by S steps
- state X returns the current state of core X
To be safe for the future, your program should be able to handle 4587520 cores. The initial frequency for each core is 0.
Input
The input contains a single test case. It starts with a line containing three integers C, N, and O, where C is the number of cores (1 ≤ C ≤ 4587520) to manage, N is the number of frequency steps for each core (1 ≤ N ≤ 10000) and O is the number of operations in the test program (1 ≤ O ≤ 50000). Then follow O lines, each containing one command as described above. X, A and B are 0-based IDs of the cores (0 ≤ A,B,X < C; A ≤ B). S is an integer number of steps, possibly negative (−N ≤ S ≤ +N).
Both, the change and the groupchange command will increase (or decrease) in single steps and stop as soon as one core in the group reaches the minimal (0) or maximal frequency (N).
Output
Output one line for every operation in the input. For change and groupchange print the changed number of steps, for state print the current state.
Sample Input I |
Sample Output I |
10 10 5 state 0 groupchange 2 9 7 state 9 groupchange 0 2 10 change 0 -5 |
0 7 7 3 -3 |
Sample Input II |
Sample Output II |
4587520 10000 5 groupchange 0 4587010 9950 groupchange 23 4587000 42 groupchange 4710 4587001 -1000 state 1234560 groupchange 6666 3060660 10000 |
9950 42 -1000 8992 1008 |
解题:线段树,超大。。。注意内存控制
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct node {
int minv,maxv,lazy;
} tree[maxn<<];
void build(int lt,int rt,int v) {
tree[v].minv = tree[v].maxv = tree[v].lazy = ;
if(lt == rt) return;
int mid = (lt + rt)>>;
build(lt,mid,v<<);
build(mid+,rt,v<<|);
}
void pushup(int v) {
tree[v].minv = min(tree[v<<].minv+tree[v<<].lazy,tree[v<<|].minv+tree[v<<|].lazy);
tree[v].maxv = max(tree[v<<].maxv+tree[v<<].lazy,tree[v<<|].maxv+tree[v<<|].lazy);
}
void pushdown(int v) {
if(tree[v].lazy) {
tree[v<<].lazy += tree[v].lazy;
tree[v<<|].lazy += tree[v].lazy;
tree[v].lazy = ;
}
}
void update(int L,int R,int lt,int rt,int v,int value) {
if(L >= lt && R <= rt) {
tree[v].lazy += value;
tree[v].minv += tree[v].lazy;
tree[v].maxv += tree[v].lazy;
pushdown(v);
return;
}
pushdown(v);
int mid = (L + R)>>;
if(lt <= mid) update(L,mid,lt,rt,v<<,value);
if(rt > mid) update(mid+,R,lt,rt,v<<|,value);
pushup(v);
}
int getMin(int L,int R,int lt,int rt,int v) {
if(L >= lt && R <= rt)
return tree[v].minv + tree[v].lazy;
pushdown(v);
int ans = INF,mid = (L + R)>>;
if(lt <= mid) ans = min(ans,getMin(L,mid,lt,rt,v<<));
if(rt > mid) ans = min(ans,getMin(mid+,R,lt,rt,v<<|));
pushup(v);
return ans;
}
int getMax(int L,int R,int lt,int rt,int v) {
if(L >= lt && R <= rt)
return tree[v].maxv + tree[v].lazy;
pushdown(v);
int ans = -INF,mid = (L + R)>>;
if(lt <= mid) ans = max(ans,getMax(L,mid,lt,rt,v<<));
if(rt > mid) ans = max(ans,getMax(mid+,R,lt,rt,v<<|));
pushup(v);
return ans;
}
int query(int L,int R,int p,int v) {
if(L == R)
return tree[v].minv + tree[v].lazy;
pushdown(v);
int mid = (L + R)>>;
int ans = ;
if(p <= mid) ans = query(L,mid,p,v<<);
if(p > mid) ans = query(mid+,R,p,v<<|);
pushup(v);
return ans;
}
int main() {
int N,M,Q,x,y,v;
char s[];
while(~scanf("%d %d %d",&N,&M,&Q)) {
memset(tree,,sizeof(tree));
while(Q--) {
scanf("%s",s);
if(s[] == 's') {
scanf("%d",&x);
printf("%d\n",query(,N,x,));
} else {
if(s[] == 'c') {
scanf("%d %d",&x,&v);
y = x;
} else if(s[] == 'g') scanf("%d %d %d",&x,&y,&v);
int nv;
if(v < ) {
int minv = getMin(,N,x,y,);
nv = minv + v < ? -minv:v;
} else {
int maxv = getMax(,N,x,y,);
nv = maxv + v > M ? M-maxv:v;
}
update(,N,x,y,,nv);
printf("%d\n",nv);
}
}
}
return ;
}
CSUOJ 1532 JuQueen的更多相关文章
- HDU 1532 最大流模板题
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1532 最近在学网络流,学的还不好,先不写理解了,先放模板... 我觉得写得不错的博客:http://blo ...
- csuoj 1511: 残缺的棋盘
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 1511: 残缺的棋盘 时间限制: 1 Sec 内存限制: 128 MB 题目描述 输入 ...
- JuQueen(线段树 lazy)
JuQueen Time Limit: 5 Sec Memory Limit: 512 MB Description Input Output Sample Input 10 10 5 state ...
- HDU 1532 (Dinic算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 题目大意: 就是由于下大雨的时候约翰的农场就会被雨水给淹没,无奈下约翰不得不修建水沟,而且是网络 ...
- 【BZOJ】【1532】【POI2005】Kos-Dicing
网络流/二分法 最大值最小……直接做不太好做的时候就可以用二分+判定来搞. 这题我们就也可以二分最大胜场v,那么怎么来判定呢?首先我们发现:每场比赛要么A赢,要么B赢,这一点跟二分图匹配非常类似,那么 ...
- 九度OJ 1532 棋盘寻宝扩展 -- 动态规划【背包问题】
题目地址:http://ac.jobdu.com/problem.php?pid=1532 题目描述: 现在有一个8*8的棋盘,上面放着64个不同价值的礼物,每个小的棋盘上面放置一个礼物(礼物的价值大 ...
- csuoj 1354: Distinct Subsequences
这个题是计算不同子序列的和: spoj上的那个同名的题是计算不同子序列的个数: 其实都差不多: 计算不同子序列的个数使用dp的思想: 从头往后扫一遍 如果当前的元素在以前没有出现过,那么dp[i]=d ...
- HDU 1532 Drainage Ditches 最大流 (Edmonds_Karp)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1532 感觉题意不清楚,不知道是不是个人英语水平问题.本来还以为需要维护入度和出度来找源点和汇点呢,看 ...
- Bzoj 1532: [POI2005]Kos-Dicing 二分,网络流
1532: [POI2005]Kos-Dicing Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1373 Solved: 444[Submit][St ...
随机推荐
- [Android Studio 权威教程]配置出“NB”的Android Studio
前几篇博客我们已经安装好了As,并且创建了我们的第一个HelloWrod ,这片blog我们继续配置出一个NB的Android Studio 假设你是一个才開始接触到AS或者想从Eclipse转型到A ...
- mac鼠标滚动方向自然问题
mac使用鼠标的时候滚轮方向和Windows是相反的.假设不勾选滚动方向自然,那么触摸板使用不爽. 解决的方法: 1.打开http://pilotmoon.com/scrollreverser/,下载 ...
- 【试水CAS-4.0.3】第02节_CAS服务端登录页个性化
完整版见https://jadyer.github.io/2015/07/16/sso-cas-login-diy/ /** * @see ------------------------------ ...
- php冒泡排序函数
$arr=array(23,5,26,4,9,85,10,2,55,44,21,39,11,16,55,88,421,226,588); function maopao($arr,$value){// ...
- nyoj--108--士兵杀敌(一)(区间求和&&树状数组)
士兵杀敌(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 南将军手下有N个士兵,分别编号1到N,这些士兵的杀敌数都是已知的. 小工是南将军手下的军师,南将军现在想知 ...
- windows tensorflow 版本与升级
tensorflow 的版本在 1.1.0/1.2.0 之后 api 迎来重大变化,有必要将版本升级到最新的 1.1.0 以上. 1. 使用 upgrade CPU:pip3 install –upg ...
- Spring MVC登录注册以及转换json数据
项目结构; 代码如下: BookController package com.mstf.controller; import javax.servlet.http.HttpServletRespons ...
- 如何用Java实现反转排序
摘要:反转排序是将原先已经排序好了的重新排序,是原来的数组元素的顺序反转过来.假设原来的数组顺序是{6,5,4,3,2,1},反转之后的顺序就是{1,2,3,4,5,6}.这个排序的算法不是很难,代码 ...
- 关于 nginx 的配置的 location
精准匹配和普通匹配: server{ location =/index.htm{ ////精准匹 ...
- Https个人总结
花了一个星期终于搞懂了.. HTTPS个人总结: 一.RSA算法 公钥:可以分发给任意的钥匙 私钥:自己保留起来,不分发给别人的钥匙 RSA算法: 找出质数p.q n = p*q Φ(n)=(p-1) ...