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. 图像切割—基于图的图像切割(Graph-Based Image Segmentation)

     图像切割-基于图的图像切割(Graph-Based Image Segmentation) Reference: Efficient Graph-Based Image Segmentation ...

  2. Linux系统编程——进程间通信:共享内存

    概述 url=MdyPihmS_tWLwgWL5CMzaTrwDFHu6euAJJUAjKvlzbJmRw7RfhmkBWwAloo7Y65hLY-kQdHsbqWYP2wc2fk8yq"& ...

  3. 拥抱PBO(基于项目的组织)聚焦核心价值创造

    近年来.PBO(Project-Based Organizations)作为一种新兴的整合各类专业智力资源和专业知识的组织结构,受到越来越多的关注,第五版PMBOK出现的新词汇.三种组织(职能型.矩阵 ...

  4. 怎样在Ubuntu手机平台中开发Cordova HTML5应用

    我们知道Cordova HTML5应用具有夸平台的特性,同一时候也具有訪问本地一些资源的能力.在今天的这篇文章中.我们将介绍一下怎样创建并执行一个Cordova HTML5的应用到我们的Ubuntu手 ...

  5. Getting Started with MongoDB (MongoDB Shell Edition)

    https://docs.mongodb.com/getting-started/shell/ Overview Welcome to the Getting Started with MongoDB ...

  6. 安卓开发--ListView

    package com.zx.listview01; import java.util.ArrayList; import java.util.HashMap; import java.util.Li ...

  7. ubuntu14.04下snort的安装(官方文档安装)(图文详解)

    不多说,直接上干货! 最近为了科研,需要安装和使用Snort. snort的官网 https://www.snort.org/ Snort作为一款优秀的开源主机入侵检测系统,在windows和Linu ...

  8. html页面全屏化显示

    <html><head><script>// toggle full screen function toggleFullScreen() { if (!docum ...

  9. Spring MVC登录注册以及转换json数据

    项目结构; 代码如下: BookController package com.mstf.controller; import javax.servlet.http.HttpServletRespons ...

  10. vue中使用滚动效果

    new Vue({ el: '#app', data: function data() { return { bottom: false, beers: [] }; }, watch: { botto ...