题目链接: http://poj.org/problem?id=3468 题意: 输入 n, m表初始有 n 个数, 接下来 m 行输入, Q x y 表示询问区间 [x, y]的和: C x y z 表示区间 [x, y] 内所有数加上 z : 思路: 线段树区间更新&区间求和模板: 代码: #include <iostream> #include <stdio.h> #define ll long long #define lson l, mid, rt <<…
Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 24474    Accepted Submission(s): 12194 Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6070 题意: 给出一个题目提交序列, 从中选出一个正确率最小的子串. 选中的子串中每个题目当且仅当最后一次提交是正确的. 思路: 分数规划 二分答案, 然后在 check 函数中查找是否存在某个区j间 [l, r] 使得 sum(l, r) / (r - l + 1) <= mid, 即 sum(l, r) + l * mid <= (r + 1) * mid. 可以用个线段树来维护 sum(l…
题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但是我们处理一下就可以完美解决此问题.区间更新可以使用区间求和的方法,在更新的(x2,y2)记录+1,在更新的(x1-1,y1-1)-1(向前更新到最前方).单点求和就只需要与区间更新相反,向后求一个区间和.这样做的理由是:如果求和的点在某次更新范围内,我们+1但是不执行-1,否者要么都不执行,要么都…
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval. In…
区间更新求和 主要用来练习splay树区间更新问题 //splay树的题解 // File Name: 3468-splay.cpp // Author: Zlbing // Created Time: 2013年08月09日 星期五 16时30分32秒 #include<iostream> #include<string> #include<algorithm> #include<cstdlib> #include<cstdio> #inclu…
模板题目1:https://www.luogu.org/problemnew/show/P3372 懒惰标记讲解:https://www.cnblogs.com/wushengyang/p/11194456.html 这题目只需要用一个懒惰标记,不用考虑顺序. AC代码: #include <stdio.h> #include <iostream> #include <cstdlib> #include <cmath> #include <cctype…
POJ 3468 (Java,c++实现) Java import java.io.*; import java.util.*; public class Main { static int n, m; static final int N = 100005; static int ls[] = new int[N << 2]; static int rs[] = new int[N << 2]; static long M[] = new long[N << 2];…
Problem 1004: 蛤玮打扫教室 Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit interger IO format:  %lld   Java class name:  Main Description 现在知道一共有n个机房,算上蛤玮一共有m个队员,教练做了m个签,每个签上写着两个数L,R(L<=R),抽到的人要把[L,R]的教室全部打扫一遍.由于蛤玮是队长而且他很懒,他通过某种交易提前知道了所有m个签上面写的是什么,…
http://acm.hdu.edu.cn/showproblem.php?pid=5692 [思路] 每更新一个点,子树的所有结点都要更新,所以是区间更新 每查询一个点,子树的所有结点都要查询,所以是区间查询最值 线段树上结点的值是每个点到根这条链的权值和 [AC] #pragma comment(linker, "/STACK:1024000000,1024000000") #include<bits/stdc++.h> #define lson l,mid,rt<…