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的更多相关文章

  1. HDU 1532 最大流模板题

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1532 最近在学网络流,学的还不好,先不写理解了,先放模板... 我觉得写得不错的博客:http://blo ...

  2. csuoj 1511: 残缺的棋盘

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 1511: 残缺的棋盘 时间限制: 1 Sec  内存限制: 128 MB 题目描述 输入 ...

  3. JuQueen(线段树 lazy)

    JuQueen Time Limit: 5 Sec  Memory Limit: 512 MB Description Input Output Sample Input 10 10 5 state ...

  4. HDU 1532 (Dinic算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 题目大意: 就是由于下大雨的时候约翰的农场就会被雨水给淹没,无奈下约翰不得不修建水沟,而且是网络 ...

  5. 【BZOJ】【1532】【POI2005】Kos-Dicing

    网络流/二分法 最大值最小……直接做不太好做的时候就可以用二分+判定来搞. 这题我们就也可以二分最大胜场v,那么怎么来判定呢?首先我们发现:每场比赛要么A赢,要么B赢,这一点跟二分图匹配非常类似,那么 ...

  6. 九度OJ 1532 棋盘寻宝扩展 -- 动态规划【背包问题】

    题目地址:http://ac.jobdu.com/problem.php?pid=1532 题目描述: 现在有一个8*8的棋盘,上面放着64个不同价值的礼物,每个小的棋盘上面放置一个礼物(礼物的价值大 ...

  7. csuoj 1354: Distinct Subsequences

    这个题是计算不同子序列的和: spoj上的那个同名的题是计算不同子序列的个数: 其实都差不多: 计算不同子序列的个数使用dp的思想: 从头往后扫一遍 如果当前的元素在以前没有出现过,那么dp[i]=d ...

  8. HDU 1532 Drainage Ditches 最大流 (Edmonds_Karp)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1532 感觉题意不清楚,不知道是不是个人英语水平问题.本来还以为需要维护入度和出度来找源点和汇点呢,看 ...

  9. Bzoj 1532: [POI2005]Kos-Dicing 二分,网络流

    1532: [POI2005]Kos-Dicing Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1373  Solved: 444[Submit][St ...

随机推荐

  1. Cannot find the class file for javax.servlet.ServletContext.

    当eclipse中新导入的Java Project的时候.往往会碰到各种各样的问题,以下是个典型的问题: Cannot find the class file for javax.servlet.Se ...

  2. codeforces@281 B

    shui #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&g ...

  3. CAP定理在分布式系统设计中的最新应用

    本文翻译自国外InfoQ和计算机杂志上一篇2012年旧文,本文就有关数据同步进行了讨论,特别关注业务事务的不变性与一致性如何在分布式系统中巧妙保证,探讨了长时间运行的事务的补偿机制.这些对分布式系统设 ...

  4. Struts2国际化-getText()方法

    转自https://blog.csdn.net/qq_43560838/article/details/83747604 一:简单理解 国际化简称i18n,其来源是英文单词 international ...

  5. 131.lambda表达式小结

    C++ 11中的Lambda表达式用于定义并创建匿名的函数对象,以简化编程工作.Lambda的语法形式如下:[函数对象参数](操作符重载函数参数) mutable或exception声明->返回 ...

  6. Java基础学习(一) -- Java环境搭建、数据类型、分支循环等控制结构、简单一维数组详解

    一:java概述: 1982年,SUN公司诞生于美国斯坦福大学校园,并于1986年上市,在NASDAQ(纳斯达克:是全美证券商协会自动报价系统)的标识为SUNW,2007年改为JAVA. 2009年4 ...

  7. 常用模块(hashlib、suprocess、configparser)

    hashlib模块 hash是一种接受不了内容的算法,(3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法),该算 ...

  8. python web开发 框架 模板 MVC

    我是跟着廖雪峰老师学习的,对于我这样的纯小白来说,跟着他的网站学习,简直是被妈妈抱在怀里一样无忧无虑,这样的学习本来没有记录下来的必要,但是由于我的粗心大意,经常会出现一些错误,所以我决定把这些错误记 ...

  9. WHU 1548 Home 2-SAT

    ---恢复内容开始--- 题意: N个人想回家在至少一个时刻.至多两个时刻.并且,他们每个人都能独自回家. 定义:ai表示第i个人回家的时间, xij = abs(ai - aj) (i != j). ...

  10. Unity 编辑器学习(三)之 Light & Baked

    上一篇博客已经详细的介绍GI了,接下来我们讲点实际的,怎么烘焙场景及注意事项. 一.Light Property: Function: Type 当前灯光的类型.有四种类型:Directional,  ...