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. CCEditBox/CCEditBoxImplAndroid

    #ifndef __CCEDITBOXIMPLANDROID_H__ #define __CCEDITBOXIMPLANDROID_H__ #include "cocos2d.h" ...

  2. 聊聊高并发(四十四)解析java.util.concurrent各个组件(二十) Executors工厂类

    Executor框架为了更方便使用,提供了Executors这个工厂类.通过一系列的静态工厂方法.能够高速地创建对应的Executor实例. 仅仅有一个nThreads參数的newFixedThrea ...

  3. HNU13377:Book Club(DFS)

    Problem description Porto's book club is buzzing with excitement for the annual book exchange event! ...

  4. java学习记录笔记--继承,super,Object类

    继承: Java中的继承是单继承的. 1.子类拥有父类的全部属性和方法. 可是属性和方法的修饰符不能使private. 2.能够复用父类的代码. 方法的重写须要满足的条件: a.返回值类型 b.方法名 ...

  5. laravel中的数据迁移和数据填充

    laravel中的数据迁移和数据填充 标签(空格分隔): php 生成迁移文件两种方式: 1 新建一个表的迁移文件 php artisan make:migration create_students ...

  6. 防雪崩利器:熔断器 Hystrix 的原理与使用--转

    原文地址:https://segmentfault.com/a/1190000005988895 前言 分布式系统中经常会出现某个基础服务不可用造成整个系统不可用的情况, 这种现象被称为服务雪崩效应. ...

  7. Bootstrap-FileInput组件的简单Demo

    官网: https://github.com/kartik-v/bootstrap-fileinput/ http://plugins.krajee.com/file-input   HTML页面: ...

  8. Rain and Umbrellas(dp)

    题目链接 http://codeforces.com/problemset/problem/988/F 令dp[i][j]为走到目标为i处,手里拿着第j把伞,同时注意,在某处可能存在不止一把伞 #in ...

  9. Systemd曝3漏洞,大部分Linux将受到攻击

    Linux 系统与服务管理工具 Systemd 被曝存在 3 大漏洞,影响几乎所有 Linux 发行版. Systemd 是 Linux 系统的基本构建块,它提供了对系统和服务的管理功能,以 PID ...

  10. Android Studio的Signature Versions选择,分别是什么意思

    转自原文 Android Studio的Signature Versions选择,分别是什么意思 打包一个文件的签名版本, 选V1打包出来的app是jar的(一般这种就是当做第三方导入项目来用的), ...