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. mysql-数据库维护

    一.备份数据 1.使用mysqldump命令备份:前提:musql的版本必须一致. mysqldump -u username -p  --default -character-set=gbk dbn ...

  2. UVa 10069 Distinct Subsequences(大数 DP)

     题意 求母串中子串出现的次数(长度不超过1后面100个0  显然要用大数了) 令a为子串 b为母串 d[i][j]表示子串前i个字母在母串前j个字母中出现的次数   当a[i]==b[j]&am ...

  3. 基于IBM Bluemix的数据缓存应用实例

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:IBM® Data Cache for Bluemix 是快速缓存服务.支持 Web 和 ...

  4. less14 颜色函数2

    less div{ // hue()色相值 z-index: hue(hsl(90,100%,50%)); //90 ////saturation()饱和度 z-index: saturation(h ...

  5. Flume 启动

    Configuration是Flume项目的入口程序了,当我们输入 bin/flume-ng agent --conf conf --conf-file conf/kafka1.properties ...

  6. WebView的坑[持续更新]

    返回错误的 innerHeight,如 240(WebView returns bad window.innerHeight) http://stackoverflow.com/questions/1 ...

  7. 用fcntl锁一个文件来保护操作

    int testfd; /* fd for test*/ if((testfd = open("/usr/local/pgsql/bin/test_fd",O_RDWR|O_CRE ...

  8. Linux系统启动U盘制作工具

    1.UNetbootin UNetbootin 让你创建 Ubuntu 或者其他 Linux 发行版的可引导 Live U 盘,而无需烧录 CD. 你既能让 UNetbootin 为你下载众多开箱即用 ...

  9. Javascript中继承

    Javascript中继承 构造函数继承 原型继承 call和apply继承 组合继承

  10. 运行npm start vue.js项目 出现 npm ERR! missing script: start 错误

    npm ERR! missing script: start 错误 有可能缺少依赖包,运行nmp install安装依赖(一般都依赖很多包,过程有点慢),安装完后发现多一个 node_modules文 ...