没写完,还有五题,好像是乱七八糟建模乱七八糟维护什么的,在家里真的没心思写题目,先发博客吧以后再补换个代码量少的专题写写。
A - 敌兵布阵
HDU - 1166
C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。 中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:"你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:"我知错了。。。"但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的.
Input
第一行一个整数T,表示有T组数据。 每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工兵营地里开始时有ai个人(1<=ai<=50)。 接下来每行有一条命令,命令有4种形式: (1) Add i j,i和j为正整数,表示第i个营地增加j个人(j不超过30) (2)Sub i j ,i和j为正整数,表示第i个营地减少j个人(j不超过30); (3)Query i j ,i和j为正整数,i<=j,表示询问第i到第j个营地的总人数; (4)End 表示结束,这条命令在每组数据最后出现; 每组数据最多有40000条命令
Output
对第i组数据,首先输出“Case i:”和回车, 对于每个Query询问,输出一个整数并回车,表示询问的段中的总人数,这个数保持在int以内。
Sample Input
1
10
1 2 3 4 5 6 7 8 9 10
Query 1 3
Add 3 6
Query 2 7
Sub 10 2
Add 6 3
Query 3 10
End
Sample Output
Case 1:
6
33
59
单点更新,区间维护和值。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef pair P;
typedef long long ll;
#define N 200010
#define M 3645
const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const double PI = acos(-1);
#define fi first
#define se second
#define L o<<1
#define R o<<1|1
#define tl tree[o].l
#define tr tree[o].r
#define tw tree[o].w
#define rep(i, lll, nnn) for(int i = (lll); i <= (nnn); i++)
struct Node {
int l, r, w;
}tree[N];
void build(int o, int l, int r)
{
tl = l; tr = r;
if(l == r) {
scanf("%d", &tw);
return;
}
int mid = (l + r) >> 1;
build(L, l, mid);
build(R, 1 + mid, r);
tw = tree[L].w + tree[R].w;
}
void add(int o, int i, int w)
{
if(tl == tr) {
tw += w;
return;
}
tw += w;
int mid = (tl + tr) >> 1;
if(i <= mid) add(L, i, w);
else add(R, i, w);
}
int query(int o, int l, int r)
{
//cout << l << ' ' << r<> 1;
if(r <= mid) return query(L, l, r);
else if(l > mid) return query(R, l, r);
else {
return query(L, l, mid) + query(R, 1 + mid, r);
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt", "r", stdin);
#endif
int t, n, a, b, c;
char s[6];
scanf("%d", &t);
rep(Case, 1, t) {
scanf("%d", &n);
build(1, 1, n);
printf("Case %d:\n", Case);
while(true) {
scanf("%s", s);
if(strcmp(s, "End") == 0)
break;
if(strcmp(s, "Add") == 0) {
scanf("%d%d", &a, &b);
add(1, a, b);
}
else if(strcmp(s, "Sub") == 0) {
scanf("%d%d", &a, &b);
add(1, a, -b);
}
else {
scanf("%d%d", &a, &b);
printf("%d\n", query(1, a, b));
}
}
}
return 0;
}
B - I Hate It
HDU - 1754
很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。 这让很多学生很反感。 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。
Input
本题目包含多组测试,请处理到文件结束。 在每个测试的第一行,有两个正整数 N 和 M ( 0 学生ID编号分别从1编到N。 第二行包含N个整数,代表这N个学生的初始成绩,其中第i个数代表ID为i的学生的成绩。 接下来有M行。每一行有一个字符 C (只取'Q'或'U') ,和两个正整数A,B。 当C为'Q'的时候,表示这是一条询问操作,它询问ID从A到B(包括A,B)的学生当中,成绩最高的是多少。 当C为'U'的时候,表示这是一条更新操作,要求把ID为A的学生的成绩更改为B。
Output
对于每一次询问操作,在一行里面输出最高成绩。
Sample Input
5 6
1 2 3 4 5
Q 1 5
U 3 6
Q 3 4
Q 4 5
U 2 9
Q 1 5
Sample Output
5
6
5
9
Hint
Huge input,the C function scanf() will work better than cin
单点更新,区间维护最值。
#include
#include
#include
using namespace std;
#define tl tree[o].l
#define tr tree[o].r
#define ts tree[o].high
#define L o<<1
#define R o<<1|1
#define N 800010
typedef long long ll;
int n, m, a, b, c;
char ch;
struct node{
int l, r;
ll high;
}tree[N];
void build(int o, int l, int r)
{
tl = l; tr = r; ts = 0;
if(l == r) {
scanf("%lld", &ts);
return;
}
build(L, l, (l + r)>>1);
build(R, 1 + ((l + r)>>1), r);
ts = max(tree[L].high, tree[R].high);
}
void add(int o, int i, ll v)
{
if(tl == tr) {
ts = v;
return;
}
ts = max(ts, v);
int mid = (tl + tr) >> 1;
if(i <= mid) add(L, i, v);
else if(i > mid) add(R, i, v);
}
ll query(int o, int l, int r)
{//cout << o <<' '<> 1;
if(r <= mid) return query(L, l, r);
else if(l > mid) return query(R, l, r);
else {
return max(query(L, l, mid), query(R, mid + 1, r));
}
}
int main()
{
freopen("data.txt", "r", stdin);
while(~scanf("%d%d", &n, &m)) {
build(1, 1, n);
while(m--) {
cin >> ch;
if(ch == 'Q'){
scanf("%d%d", &a, &b);
printf("%lld\n", query(1, a, b));
}
else if(ch == 'U'){
scanf("%d%d", &a, &b);
add(1, a, b);
}
}
}
return 0;
}
C - A Simple Problem with Integers
POJ - 3468
You have N integers, A 1, A 2, ... , 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.
Input
The first line contains two numbers N and Q . 1 ≤ N ,Q ≤ 100000. The second line contains N numbers, the initial values of A 1, A 2, ... , AN . -1000000000 ≤ Ai ≤ 1000000000. Each of the next Q lines represents an operation. "C a b c " means adding c to each of Aa , Aa +1, ... , Ab . -10000 ≤ c ≤ 10000. "Q a b " means querying the sum of Aa , Aa +1, ... , Ab .
Output
You need to answer all Q commands in order. One answer in a line.
Sample Input
10 5
1 2 3 4 5 6 7 8 9 10
Q 4 4
Q 1 10
Q 2 4
C 3 6 3
Q 2 4
Sample Output
4
55
9
15
Hint
The sums may exceed the range of 32-bit integers.
区间更新,区间求和,加懒惰标记。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef pair P;
typedef long long ll;
#define N 400010
#define M 3645
const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const double PI = acos(-1);
#define fi first
#define se second
#define L o<<1
#define R o<<1|1
#define tl tree[o].l
#define tr tree[o].r
#define tw tree[o].w
#define rep(i, lll, nnn) for(int i = (lll); i <= (nnn); i++)
struct Node {
int l, r, length;
ll lazy, w;
}tree[N];
void up(int o) {
tw = tree[L].w + tree[R].w;
}
void down(int o)
{
if(!tree[o].lazy) return;
tree[L].w += tree[o].lazy * tree[L].length;
tree[R].w += tree[o].lazy * tree[R].length;
tree[L].lazy += tree[o].lazy;
tree[R].lazy += tree[o].lazy;
tree[o].lazy = 0;
}
void build(int o, int l, int r)
{
tl = l; tr = r;
tree[o].length = r - l + 1;
tree[o].lazy = 0;
if(l == r) {
scanf("%lld", &tw);
return;
}
int mid = (l + r) >> 1;
build(L, l, mid);
build(R, 1 + mid, r);
up(o);
}
ll query(int o, int l, int r)
{
if(tl == l && tr == r) return tw;
down(o);
int mid = (tl + tr) >> 1;
if(r <= mid) return query(L, l, r);
else if(l > mid) return query(R, l, r);
else {
return query(L, l, mid) + query(R, 1 + mid, r);
}
}
void add(int o, int l, int r, ll w)
{
if(tl == l && tr == r) {
tw += w * tree[o].length;
tree[o].lazy += w;
return;
}
down(o);
int mid = (tl + tr) >> 1;
if(r <= mid) add(L, l, r, w);
else if(l > mid) add(R, l, r, w);
else {
add(L, l, mid, w);
add(R, 1 + mid, r, w);
}
up(o);
}
int n, q, a, b, c;
char s[3];
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt", "r", stdin);
#endif
while(~scanf("%d%d", &n, &q)) {
build(1, 1, n);
while(q--) {
scanf("%s", s);
if(s[0] == 'Q') {
scanf("%d%d", &a, &b);
printf("%lld\n", query(1, a, b));
}
else {
scanf("%d%d%d", &a, &b, &c);
add(1, a, b, c);
}
}
}
return 0;
}
D - Mayor's posters
POJ - 2528
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral wall for placing the posters and introduce the following rules:
Every candidate can place exactly one poster on the wall.
All posters are of the same height equal to the height of the wall; the width of a poster can be any integer number of bytes (byte is the unit of length in Bytetown).
The wall is divided into segments and the width of each segment is one byte.
Each poster must completely cover a contiguous number of wall segments.
They have built a wall 10000000 bytes long (such that there is enough place for all candidates). When the electoral campaign was restarted, the candidates were placing their posters on the wall and their posters differed widely in width. Moreover, the candidates started placing their posters on wall segments already occupied by other posters. Everyone in Bytetown was curious whose posters will be visible (entirely or in part) on the last day before elections. Your task is to find the number of visible posters when all the posters are placed given the information about posters' size, their place and order of placement on the electoral wall.
Input
The first line of input contains a number c giving the number of cases that follow. The first line of data for a single case contains number 1 <= n <= 10000. The subsequent n lines describe the posters in the order in which they were placed. The i-th line among the n lines contains two integer numbers l i and ri which are the number of the wall segment occupied by the left end and the right end of the i-th poster, respectively. We know that for each 1 <= i <= n, 1 <= l i <= ri <= 10000000. After the i-th poster is placed, it entirely covers all wall segments numbered l i, l i+1 ,... , ri.
Output
For each input data set print the number of visible posters after all the posters are placed. The picture below illustrates the case of the sample input.
Sample Input
1
5
1 4
2 6
8 10
3 4
7 10
Sample Output
4
离散化+逆向思维,这个离散化直接开数组就行了。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef pair P;
typedef long long ll;
#define N 10010
#define M 3645
const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const double PI = acos(-1);
#define fi first
#define se second
#define L o<<1
#define R o<<1|1
#define tl tree[o].l
#define tr tree[o].r
#define tc tree[o].cover
#define rep(i, lll, nnn) for(int i = (lll); i <= (nnn); i++)
int hash[10000001], num[N * 2];
int t, n, cnt, ans;
struct Post {
int l, r;
}p[N];
struct Node {
int l, r;
bool cover;
}tree[N * 8];
void build(int o, int l, int r)
{
tl = l; tr = r; tc = false;
if(l == r) return;
int mid = (l + r) >> 1;
build(L, l, mid);
build(R, 1 + mid, r);
}
bool add(int o, int l, int r)
{
if(tc) return false;
if(tl == l && tr == r) return tc = true;
int mid = (tl + tr) >> 1;
bool flag = false;
if(r <= mid) flag = add(L, l, r);
else if(l > mid) flag = add(R, l, r);
else {
bool f1 = add(L, l, mid);
bool f2 = add(R, 1 + mid, r);
flag = f1 || f2;
}
if(tree[L].cover && tree[R].cover) tc = true;
return flag;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt", "r", stdin);
#endif
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
ans = cnt = 0;
rep(i, 0, n - 1) scanf("%d%d", &p[i].l, &p[i].r);
rep(i, 0, n - 1) {
num[cnt++] = p[i].l;
num[cnt++] = p[i].r;
}
sort(num, num + cnt);
cnt = unique(num, num + cnt) - num;
rep(i, 0, cnt - 1) {
hash[num[i]] = i + 1;
}
build(1, 1, cnt);
for(int i = n - 1; i >= 0; i--) {
if(add(1, hash[p[i].l], hash[p[i].r])) ans++;
}
printf("%d\n", ans);
}
return 0;
}
E - Just a Hook
HDU - 1698
In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length.
Now Pudge wants to do some operations on the hook. Let us number the consecutive metallic sticks of the hook from 1 to N. For each operation, Pudge can change the consecutive metallic sticks, numbered from X to Y, into cupreous sticks, silver sticks or golden sticks. The total value of the hook is calculated as the sum of values of N metallic sticks. More precisely, the value for each kind of stick is calculated as follows: For each cupreous stick, the value is 1. For each silver stick, the value is 2. For each golden stick, the value is 3. Pudge wants to know the total value of the hook after performing the operations. You may consider the original hook is made up of cupreous sticks.
Input
The input consists of several test cases. The first line of the input is the number of the cases. There are no more than 10 cases. For each case, the first line contains an integer N, 1<=N<=100,000, which is the number of the sticks of Pudge’s meat hook and the second line contains an integer Q, 0<=Q<=100,000, which is the number of the operations. Next Q lines, each line contains three integers X, Y, 1<=X<=Y<=N, Z, 1<=Z<=3, which defines an operation: change the sticks numbered from X to Y into the metal kind Z, where Z=1 represents the cupreous kind, Z=2 represents the silver kind and Z=3 represents the golden kind.
Output
For each case, print a number in a line representing the total value of the hook after the operations. Use the format in the example.
Sample Input
1
10
2
1 5 2
5 9 3
Sample Output
Case 1: The total value of the hook is 24.
区间更新+懒惰标记
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef pair P;
typedef long long ll;
#define N 400010
#define M 3645
const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const double PI = acos(-1);
#define fi first
#define se second
#define L o<<1
#define R o<<1|1
#define tl tree[o].l
#define tr tree[o].r
#define tw tree[o].w
#define rep(i, lll, nnn) for(int i = (lll); i <= (nnn); i++)
int t, n, q, a, b, c;
struct Node {
int l, r, lazy;
ll w;
}tree[N];
void up(int o) {
tw = tree[L].w + tree[R].w;
}
void down(int o)
{
if(!tree[o].lazy) return;
tree[L].w = (tree[L].r - tree[L].l + 1) * tree[o].lazy;
tree[R].w = (tree[R].r - tree[R].l + 1) * tree[o].lazy;
tree[L].lazy = tree[o].lazy;
tree[R].lazy = tree[o].lazy;
tree[o].lazy = 0;
}
void build(int o, int l, int r)
{
tl = l; tr = r; tree[o].lazy = 0;
if(l == r) {
tw = 1; return;
}
int mid = (l + r) >> 1;
build(L, l, mid);
build(R, 1 + mid, r);
up(o);
}
void change(int o, int l, int r, ll w)
{
if(tl == l && tr == r) {
tw = (r - l + 1) * w;
tree[o].lazy = w;
return;
}
down(o);
int mid = (tl + tr) >> 1;
if(r <= mid) change(L, l, r, w);
else if(l > mid) change(R, l, r, w);
else {
change(L, l, mid, w);
change(R, 1 + mid, r, w);
}
up(o);
}
ll query(int o, int l, int r)
{
if(tl == l && tr == r) return tw;
down(o);
int mid = (tl + tr) >> 1;
if(r <= mid) return query(L, l, r);
else if(l > mid) return query(R, l, r);
else {
return query(L, l, mid) + query(R, 1 + mid, r);
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt", "r", stdin);
#endif
scanf("%d", &t);
rep(Case, 1, t) {
scanf("%d%d", &n, &q);
build(1, 1, n);
while(q--) {
scanf("%d%d%d", &a, &b, &c);
change(1, a, b, c);
}
printf("Case %d: The total value of the hook is %lld.\n", Case, query(1, 1, n));
}
return 0;
}
F - Count the Colors
ZOJ - 1610
Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones.
Your task is counting the segments of different colors you can see at last.
Input
The first line of each data set contains exactly one integer n, 1 <= n <= 8000, equal to the number of colored segments.
Each of the following n lines consists of exactly 3 nonnegative integers separated by single spaces: x1 x2 c x1 and x2 indicate the left endpoint and right endpoint of the segment, c indicates the color of the segment.
All the numbers are in the range [0, 8000], and they are all integers.
Input may contain several data set, process to the end of file.
Output
Each line of the output should contain a color index that can be seen from the top, following the count of the segments of this color, they should be printed according to the color index.
If some color can't be seen, you shouldn't print it.
Print a blank line after every dataset.
Sample Input
5 0 4 4 0 3 1 3 4 2 0 2 2 0 2 3 4 0 1 1 3 4 1 1 3 2 1 3 1 6 0 1 0 1 2 1 2 3 1 1 2 0 2 3 0 1 2 1
Sample Output
1 1 2 1 3 1
1 1
0 2 1 1
看了看代码发现我是把大区间的值赋值为-1,现在写肯定是加ok标记和up操作,count的时候就不用pre来搞了。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef pair P;
typedef long long ll;
#define N 8010
#define M 3645
const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const double PI = acos(-1);
#define fi first
#define se second
#define L o<<1
#define R o<<1|1
#define tl tree[o].l
#define tr tree[o].r
#define tw tree[o].w
#define rep(i, lll, nnn) for(int i = (lll); i <= (nnn); i++)
int n, a, b, c;
int cnt[N];
struct Node {
int l, r, w;
}tree[N * 4];
void build(int o, int l, int r)
{
tl = l; tr = r; tw = 0;
if(l == r) return;
int mid = (l + r) >> 1;
build(L, l, mid);
build(R, 1 + mid, r);
}
void change(int o, int l, int r, int w)
{
// if(w == 2) cout < 0) {
tree[L].w = tree[R].w = tw;
tw = -1;
}
int mid = (tl + tr) >> 1;
if(r <= mid) change(L, l, r, w);
else if(l > mid) change(R, l, r, w);
else {
change(L, l, mid, w);
change(R, 1 + mid, r, w);
}
tw = -1;
}
int pre;
void count(int o)
{
//if(tr < 100)cout << tl <<' ' < 0) {
if(tw != pre) {
pre = tw;
cnt[tw]++;
}
return;
}
if(tl != tr) {
count(L);
count(R);
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt", "r", stdin);
#endif
while(~scanf("%d", &n)) {
memset(cnt, 0, sizeof cnt);
build(1, 1, 8001);
rep(i, 1, n) {
scanf("%d%d%d", &a, &b, &c);
change(1, a + 1, b, c + 1);
}
pre = 0;
count(1);
rep(i, 1, 8001) if(cnt[i]) {
printf("%d %d\n", i - 1, cnt[i]);
}
putchar('\n');
}
return 0;
}
G - Balanced Lineup
POJ - 3264
For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things simple, he will take a contiguous range of cows from the milking lineup to play the game. However, for all the cows to have fun they should not differ too much in height.
Farmer John has made a list of Q (1 ≤ Q ≤ 200,000) potential groups of cows and their heights (1 ≤ height ≤ 1,000,000). For each group, he wants your help to determine the difference in height between the shortest and the tallest cow in the group.
Input
Line 1: Two space-separated integers, N and Q . Lines 2.. N +1: Line i +1 contains a single integer that is the height of cow i Lines N +2.. N + Q +1: Two integers A and B (1 ≤ A ≤ B ≤ N ), representing the range of cows from A to B inclusive.
Output
Lines 1.. Q : Each line contains a single integer that is a response to a reply and indicates the difference in height between the tallest and shortest cow in the range.
Sample Input
6 3
1
7
3
4
2
5
1 5
4 6
2 2
Sample Output
6
3
0
差值需要维护区间最值。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef pair P;
typedef long long ll;
#define N 200010
#define M 3645
const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const double PI = acos(-1);
#define fi first
#define se second
#define L o<<1
#define R o<<1|1
#define tl tree[o].l
#define tr tree[o].r
#define ta tree[o].a
#define tb tree[o].b
#define rep(i, lll, nnn) for(int i = (lll); i <= (nnn); i++)
struct Node {
int l, r;
int a, b;
}tree[N];
int n, q, maxh, minh;
void build(int o, int l, int r)
{
tl = l; tr = r;
if(l == r) {
scanf("%d", &ta);
tb = ta;
return;
}
int mid = (l + r) >> 1;
build(L, l, mid);
build(R, 1 + mid, r);
ta = min(tree[L].a, tree[R].a);
tb = max(tree[L].b, tree[R].b);
}
void query(int o, int l, int r)
{
if(tl == l && tr == r) {
minh = min(minh, ta);
maxh = max(maxh, tb);
return;
}
int mid = (tl + tr) >> 1;
if(r <= mid) query(L, l, r);
else if(l > mid) query(R, l, r);
else {
query(L, l, mid);
query(R, 1 + mid, r);
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt", "r", stdin);
#endif
while(~scanf("%d%d", &n, &q)) {
build(1, 1, n);
while(q--) {
int a, b;
scanf("%d%d", &a, &b);
maxh = 0; minh = INF;
query(1, a, b);
printf("%d\n", maxh - minh);
}
}
return 0;
}
H - Can you answer these queries?
HDU - 4027
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the battleships. Each of the battleships can be marked a value of endurance. For every attack of our secret weapon, it could decrease the endurance of a consecutive part of battleships by make their endurance to the square root of it original value of endurance. During the series of attack of our secret weapon, the commander wants to evaluate the effect of the weapon, so he asks you for help. You are asked to answer the queries that the sum of the endurance of a consecutive part of the battleship line. Notice that the square root operation should be rounded down to integer.
Input
The input contains several test cases, terminated by EOF. For each test case, the first line contains a single integer N, denoting there are N battleships of evil in a line. (1 <= N <= 100000) The second line contains N integers Ei, indicating the endurance value of each battleship from the beginning of the line to the end. You can assume that the sum of all endurance value is less than 2 63. The next line contains an integer M, denoting the number of actions and queries. (1 <= M <= 100000) For the following M lines, each line contains three integers T, X and Y. The T=0 denoting the action of the secret weapon, which will decrease the endurance value of the battleships between the X-th and Y-th battleship, inclusive. The T=1 denoting the query of the commander which ask for the sum of the endurance value of the battleship between X-th and Y-th, inclusive.
Output
For each test case, print the case number at the first line. Then print one line for each query. And remember follow a blank line after each test case.
Sample Input
10
1 2 3 4 5 6 7 8 9 10
5
0 1 10
1 1 10
1 1 5
0 5 8
1 4 8
Sample Output
Case #1:
19
7
6
区间更新而且区间只能单点更新,但是每个点更新的次数是有限的,最多七八次,所以加个标记记录下这个区间是否能更新就行,
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef pair P;
typedef long long ll;
#define N 400010
#define M 3645
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1);
#define fi first
#define se second
#define L o<<1
#define R o<<1|1
#define tl tree[o].l
#define tr tree[o].r
#define tw tree[o].w
#define to tree[o].ok
#define rep(i, lll, nnn) for(int i = (lll); i <= (nnn); i++)
int n, m, type, a, b;
struct Node {
int l, r;
ll w;
bool ok;
}tree[N];
void up(int o){
tw = tree[L].w + tree[R].w;
to = tree[L].ok || tree[R].ok;
}
void build(int o, int l, int r)
{
tl = l; tr = r;
if(l == r) {
scanf("%lld", &tw);
if(tw == 1) to = false;
else to = true;
return;
}
int mid = (l + r) >> 1;
build(L, l, mid);
build(R, 1 + mid, r);
up(o);
}
void change(int o, int l, int r)
{
if(!to) return;
if(tl == tr) {
tw = sqrt((double)tw);
if(tw <= 1) to = false;
return;
}
// int mid = (tl + tr) >> 1;
// if(r <= mid) {
// if(tree[L].ok) change(L, l, r);
// }
// else if(l > mid) {
// if(tree[R].ok) change(R, l, r);
// }
// else {
// if(tree[L].ok) change(L, l, mid);
// if(tree[R].ok) change(R, 1 + mid, r);
// }
int mid = (tl + tr) >> 1;
if(l <= mid && tree[L].ok) change(L, l, r);
if(r > mid && tree[R].ok) change(R, l, r);
up(o);
}
ll query(int o, int l, int r)
{
if(tl == l && tr == r) return tw;
int mid = (tl + tr) >> 1;
if(r <= mid) return query(L, l, r);
else if(l > mid) return query(R, l, r);
else {
return query(L, l, mid) + query(R, 1 + mid, r);
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt", "r", stdin);
#endif
int Case = 1;
while(~scanf("%d", &n)) {
build(1, 1, n);
scanf("%d", &m);
printf("Case #%d:\n", Case++);
while(m--) {
scanf("%d%d%d", &type, &a, &b);
if(a > b) swap(a, b);
if(type) {
printf("%lld\n", query(1, a, b));
}
else {
change(1, a, b);
}
// printf(" %lld\n", query(1, a, b));
}
puts("");
}
return 0;
}
I - Tunnel Warfare
HDU - 1540
During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a line. Except the two at the ends, every village was directly connected with two neighboring ones. Frequently the invaders launched attack on some of the villages and destroyed the parts of tunnels in them. The Eighth Route Army commanders requested the latest connection state of the tunnels and villages. If some villages are severely isolated, restoration of connection must be done immediately!
Input
The first line of the input contains two positive integers n and m (n, m ≤ 50,000) indicating the number of villages and events. Each of the next m lines describes an event. There are three different events described in different format shown below: D x: The x-th village was destroyed. Q x: The Army commands requested the number of villages that x-th village was directly or indirectly connected with including itself. R: The village destroyed last was rebuilt.
Output
Output the answer to each of the Army commanders’ request in order on a separate line.
Sample Input
7 9
D 3
D 6
D 5
Q 4
Q 5
R
Q 4
R
Q 4
Sample Output
1
0
2
4
第一眼这不是个set吗,然后set真过了。
区间合并的题,第一次写区间合并。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef pair P;
typedef long long ll;
#define N 500100
#define M 3645
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1);
#define fi first
#define se second
#define L o<<1
#define R o<<1|1
#define tl tree[o].l
#define tr tree[o].r
#define tlw tree[o].lw
#define trw tree[o].rw
#define rep(i, lll, nnn) for(int i = (lll); i <= (nnn); i++)
int n, m;
struct Node {
int l, r;
int lw, rw;
}tree[N * 4];
bool vis[N];
int a[N], l;
void up(int o)
{
tlw = tree[L].lw;
trw = tree[R].rw;
int mid = (tl + tr) >> 1;
if(tree[L].lw == tree[L].r - tree[L].l + 1) {
tlw += tree[R].lw;
}
if(tree[R].rw == tree[R].r - tree[R].l + 1) {
trw += tree[L].rw;
}
}
void build(int o, int l, int r)
{
tl = l; tr = r;
if(l == r) {
tlw = trw = 1;
return;
}
int mid = (l + r) >> 1;
build(L, l, mid);
build(R, 1 + mid, r);
up(o);
}
void change(int o, int i, bool v)
{
if(tl == tr) {
if(v == true) tlw = trw = 1;
else tlw = trw = 0;
return;
}
int mid = (tl + tr) >> 1;
if(i <= mid) change(L, i, v);
else change(R, i, v);
up(o);
}
int query(int o, int i)
{
//cout << tl << ' ' << tr << ' ' << i << endl;
if(tl == tr || tlw == tr - tl + 1) return tlw;
int mid = (tl + tr) >> 1;
if(i <= mid) {
if(i >= mid - tree[L].rw + 1) return query(L, i) + query(R, mid + 1);
return query(L, i);
}
if(i <= mid + tree[R].lw)return query(L, mid) + query(R, i);
return query(R, i);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt", "r", stdin);
#endif
int x;
char s[3];
while(~scanf("%d%d", &n, &m)) {
memset(vis, false, sizeof vis);
l = 0;
build(1, 1, n);
while(m--) {
scanf("%s", s);
if(s[0] == 'D') {
scanf("%d", &x);
vis[x] = true;
a[l++] = x;
change(1, x, false);
}
else if(s[0] == 'Q') {
scanf("%d", &x);
if(vis[x]) {
puts("0");
continue;
}
printf("%d\n", query(1, x));
}
else {
if(l == 0) continue;
change(1, a[l - 1], true);
vis[a[l - 1]] = false;
l--;
}
}
}
return 0;
}
//set st;
//int a[N], l;
//int n, m, x;
//char s[5];
//
//int main()
//{
// #ifndef ONLINE_JUDGE
// freopen("data.txt", "r", stdin);
// #endif
//
// set::iterator it1, it2;
// while(~scanf("%d%d", &n, &m)) {
// st.clear();
// st.insert(0);
// st.insert(n + 1);
// l = 0;
// while(m--) {
// scanf("%s", &s);
// if(s[0] == 'D') {
// scanf("%d", &x);
// a[l++] = x;
// st.insert(x);
// }
// else if(s[0] == 'Q') {
// scanf("%d", &x);
// if(st.find(x) != st.end()) {
// puts("0"); continue;
// }
// it1 = it2 = st.lower_bound(x);
// int r, l;
// r = *it2;
// l = *(--it1);
// printf("%d\n", r - l - 1);
// }
// else {
// if(l == 0) continue;
// st.erase(a[--l]);
// }
// }
// }
//
// return 0;
//}
J - Assign the task
HDU - 3974
There is a company that has N employees(numbered from 1 to N),every employee in the company has a immediate boss (except for the leader of whole company).If you are the immediate boss of someone,that person is your subordinate, and all his subordinates are your subordinates as well. If you are nobody's boss, then you have no subordinates,the employee who has no immediate boss is the leader of whole company.So it means the N employees form a tree. The company usually assigns some tasks to some employees to finish.When a task is assigned to someone,He/She will assigned it to all his/her subordinates.In other words,the person and all his/her subordinates received a task in the same time. Furthermore,whenever a employee received a task,he/she will stop the current task(if he/she has) and start the new one. Write a program that will help in figuring out some employee’s current task after the company assign some tasks to some employee.
Input
The first line contains a single positive integer T( T <= 10 ), indicates the number of test cases. For each test case: The first line contains an integer N (N ≤ 50,000) , which is the number of the employees. The following N - 1 lines each contain two integers u and v, which means the employee v is the immediate boss of employee u(1<=u,v<=N). The next line contains an integer M (M ≤ 50,000). The following M lines each contain a message which is either "C x" which means an inquiry for the current task of employee x or "T x y"which means the company assign task y to employee x. (1<=x<=N,0<=y<=10^9)
Output
For each test case, print the test case number (beginning with 1) in the first line and then for every inquiry, output the correspond answer per line.
Sample Input
1
5
4 3
3 2
1 3
5 2
5
C 3
T 2 1
C 3
T 3 2
C 3
Sample Output
Case #1:
-1
1
2
emmmmmm百度下来叫线段树维护dfs序,,先dfs出每个节点的子孙有多少个以及该节点在dfs树上和线段树的位置,再对线段操作。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef pair P;
typedef long long ll;
#define N 50010
#define M 3645
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1);
#define fi first
#define se second
#define L o<<1
#define R o<<1|1
#define tl tree[o].l
#define tr tree[o].r
#define tw tree[o].w
#define tz tree[o].lazy
#define rep(i, lll, nnn) for(int i = (lll); i <= (nnn); i++)
vector G[N];
int root, deg[N];
int pos[N], cnt[N], cntu;
int dfs(int fa)
{
int res = 1;
pos[fa] = cntu++;
for(int i = 0; i < G[fa].size(); i++) {
res += dfs(G[fa][i]);
}
return cnt[fa] = res;
}
int n, m, x, y;
char s[3];
struct Node {
int l, r, lazy, w;
}tree[N * 4];
void down(int o)
{
if(tz == -1) return;
tree[L].w = tree[L].lazy = tz;
tree[R].w = tree[R].lazy = tz;
tz = -1;
}
void build(int o, int l, int r)
{
tl = l; tr = r; tz = tw = -1;
if(l == r) return;
int mid = (l + r) >> 1;
build(L, l, mid);
build(R, 1 + mid, r);
}
void change(int o, int l, int r, int v)
{
if(tl == tr) {
tw = tz = v;
return;
}
down(o);
int mid = (tl + tr) >> 1;
if(r <= mid) change(L, l, r, v);
else if(l > mid) change(R, l, r, v);
else {
change(L, l, mid, v);
change(R, 1 + mid, r, v);
}
}
int query(int o, int i)
{
if(tl == tr) return tw;
down(o);
int mid = (tl + tr) >> 1;
if(i <= mid) return query(L, i);
else return query(R, i);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt", "r", stdin);
#endif
int t;
scanf("%d", &t);
rep(Case, 1, t) {
scanf("%d", &n);
rep(i, 1, n) G[i].clear();
memset(deg, 0, sizeof deg);
rep(i, 1, n - 1) {
int u, v;
scanf("%d%d", &u, &v);
G[v].push_back(u);
deg[u]++;
}
rep(i, 1, n) if(deg[i] == 0) {
root = i; break;
}
cntu = 1;
dfs(root);
build(1, 1, n);
printf("Case #%d:\n", Case);
scanf("%d", &m);
while(m--) {
scanf("%s", s);
if(s[0] == 'C') {
scanf("%d", &x);
printf("%d\n", query(1, pos[x]));
}
else {
scanf("%d%d", &x, &y);
change(1, pos[x], pos[x] + cnt[x] - 1, y);
}
}
}
return 0;
}
K - Transformation
HDU - 4578
Yuanfang is puzzled with the question below: There are n integers, a 1, a 2, …, a n. The initial values of them are 0. There are four kinds of operations. Operation 1: Add c to each number between a x and a y inclusive. In other words, do transformation a k<---a k+c, k = x,x+1,…,y. Operation 2: Multiply c to each number between a x and a y inclusive. In other words, do transformation a k<---a k×c, k = x,x+1,…,y. Operation 3: Change the numbers between a x and a y to c, inclusive. In other words, do transformation a k<---c, k = x,x+1,…,y. Operation 4: Get the sum of p power among the numbers between a x and a y inclusive. In other words, get the result of a x p+a x+1 p+…+a y p. Yuanfang has no idea of how to do it. So he wants to ask you to help him.
Input
There are no more than 10 test cases. For each case, the first line contains two numbers n and m, meaning that there are n integers and m operations. 1 <= n, m <= 100,000. Each the following m lines contains an operation. Operation 1 to 3 is in this format: "1 x y c" or "2 x y c" or "3 x y c". Operation 4 is in this format: "4 x y p". (1 <= x <= y <= n, 1 <= c <= 10,000, 1 <= p <= 3) The input ends with 0 0.
Output
For each operation 4, output a single integer in one line representing the result. The answer may be quite large. You just need to calculate the remainder of the answer when divided by 10007.
Sample Input
5 5
3 3 5 7
1 2 4 4
4 1 5 2
2 2 5 8
4 3 5 3
0 0
Sample Output
307
7489
三种区间更新,区间只要维护该区间每个点的值就行了。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef pair P;
typedef long long ll;
#define N 100010
#define M 3645
const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const double PI = acos(-1);
const int mod = 10007;
#define fi first
#define se second
#define L o<<1
#define R o<<1|1
#define tl tree[o].l
#define tr tree[o].r
#define tw tree[o].w
#define to tree[o].ok
#define rep(i, lll, nnn) for(int i = (lll); i <= (nnn); i++)
int n, m;
struct Node {
int l, r, w;
bool ok;
}tree[N * 4];
int power(int a, int b)
{
int res = 1;
while(b) {
if(b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
void build(int o, int l, int r)
{
tl = l; tr = r; to = true; tw = 0;
if(l == r) return;
int mid = (l + r) >> 1;
build(L, l, mid);
build(R, 1 + mid, r);
}
void up(int o)
{
if(!tree[L].ok || !tree[R].ok) {
to = false; return;
}
if(tree[L].w != tree[R].w) {
to = false; return;
}
tw = tree[L].w;
to = true;
}
void down(int o)
{
if(!to) return;
tree[L].w = tree[R].w = tw;
tree[L].ok = tree[R].ok = true;
}
void change(int o, int p, int l, int r, int v)
{
if(tl == l && tr == r && to) {
if(p == 1) tw = (tw + v) % mod;
else if(p == 2) tw = (tw * v) % mod;
else tw = v % mod;
return;
}
down(o);
int mid = (tl + tr) >> 1;
if(r <= mid) change(L, p, l, r, v);
else if(l > mid) change(R, p, l, r, v);
else {
change(L, p, l, mid, v);
change(R, p, 1 + mid, r, v);
}
up(o);
}
int query(int o, int l, int r, int p)
{
if(tl == l && tr == r && to) {
int res = power(tw, p);
res = (res * (r - l + 1)) % mod;
return res;
}
down(o);
int mid = (tl + tr) >> 1;
if(r <= mid) return query(L, l, r, p);
else if(l > mid) return query(R, l, r, p);
else {
return (query(L, l, mid, p) + query(R, 1 + mid, r, p)) % mod;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt", "r", stdin);
#endif
int a, b, c, d;
while(~scanf("%d%d", &n, &m) && n + m) {
build(1, 1, n);
while(m--) {
scanf("%d%d%d%d", &a, &b, &c, &d);
if(a == 4) {
printf("%d\n", query(1, b, c, d));
}
else {
change(1, a, b, c, d);
}
}
}
return 0;
}
L - Vases and Flowers
HDU - 4614
Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to N-1. When she receive some flowers, she will try to put them in the vases, one flower in one vase. She randomly choose the vase A and try to put a flower in the vase. If the there is no flower in the vase, she will put a flower in it, otherwise she skip this vase. And then she will try put in the vase A+1, A+2, ..., N-1, until there is no flower left or she has tried the vase N-1. The left flowers will be discarded. Of course, sometimes she will clean the vases. Because there are too many vases, she randomly choose to clean the vases numbered from A to B(A <= B). The flowers in the cleaned vases will be discarded.
Input
The first line contains an integer T, indicating the number of test cases. For each test case, the first line contains two integers N(1 < N < 50001) and M(1 < M < 50001). N is the number of vases, and M is the operations of Alice. Each of the next M lines contains three integers. The first integer of one line is K(1 or 2). If K is 1, then two integers A and F follow. It means Alice receive F flowers and try to put a flower in the vase A first. If K is 2, then two integers A and B follow. It means the owner would like to clean the vases numbered from A to B(A <= B).
Output
For each operation of which K is 1, output the position of the vase in which Alice put the first flower and last one, separated by a blank. If she can not put any one, then output 'Can not put any one.'. For each operation of which K is 2, output the number of discarded flowers. Output one blank line after each test case.
Sample Input
2
10 5
1 3 5
2 4 5
1 1 8
2 3 6
1 8 8
10 6
1 2 5
2 3 4
1 0 8
2 2 5
1 4 4
1 2 3
Sample Output
[pre]3 7
2
1 9
4
Can not put any one.
2 6
2
0 9
4
4 5
2 3
[/pre]
区间单点更新,ok标记该区间是否一样,w记录区间里花的数量。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef pair P;
typedef long long ll;
#define N 50010
#define M 3645
const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const double PI = acos(-1);
const int mod = 10007;
#define fi first
#define se second
#define L o<<1
#define R o<<1|1
#define tl tree[o].l
#define tr tree[o].r
#define tw tree[o].w
#define to tree[o].ok
#define rep(i, lll, nnn) for(int i = (lll); i <= (nnn); i++)
int remain, a, b, cnt;
struct Node {
int l, r, w;
bool ok;
}tree[N * 4];
void build(int o, int l, int r)
{
tl = l; tr = r; tw = 0; to = true;
if(l == r) return;
int mid = (tl + tr) >> 1;
build(L, l, mid);
build(R, 1 + mid, r);
}
void up(int o)
{
if(!tree[L].ok || !tree[R].ok) {
to = false; return;
}
if(tree[L].w > 0 && tree[R].w == 0) {
to = false; return;
}
if(tree[R].w > 0 && tree[L].w == 0) {
to = false; return;
}
to = true;
tw = tree[L].w + tree[R].w;
}
void down(int o)
{
if(to) {
if(tw == 0) tree[L].w = tree[R].w = 0;
else {
tree[L].w = tree[L].r - tree[L].l + 1;
tree[R].w = tree[R].r - tree[R].l + 1;
}
tree[L].ok = tree[R].ok = to;
}
}
void change(int o, int l, int r, bool v)
{
if(remain <= 0) return;
//cout << tl << ' ' << tr << ' ' << l << ' ' <= tr - tl + 1) {
tw = tr - tl + 1;
remain -= tr - tl + 1;
if(a == -1) a = tl;
b = max(b, tr);
return;
}
}
else {
return;
}
}
else {
cnt += tw;
tw = 0;
to = true;
return;
}
}
down(o);
int mid = (tl + tr) >> 1;
if(r <= mid) change(L, l, r, v);
else if(l > mid) change(R, l, r, v);
else {
change(L, l, mid, v);
change(R, 1 + mid, r, v);
}
up(o);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt", "r", stdin);
#endif
int t, k, x, y, n, m;
scanf("%d", &t);
while(t--) {
scanf("%d%d", &n, &m);
build(1, 1, n);
//cout << "a\n";
while(m--) {
scanf("%d%d%d", &k, &x, &y);
if(k == 1) {
remain = y;
a = b = -1;
change(1, x + 1, n, true);
if(a == -1) puts("Can not put any one.");
else printf("%d %d\n", a - 1, b - 1);
}
else {
cnt = 0;
remain = 1;
change(1, x + 1, y + 1, false);
printf("%d\n", cnt);
}
}
putchar('\n');
}
return 0;
}
你可能感兴趣的:(Kuangbin,线段树)
线段树懒标记详解
xwztdas
线段树/平衡树 线段树 数据结构 算法
引入在上一篇题解。我们详细讲解了单点修改,区间查询的线段树。在这篇题解我们将要讲解区间修改,区间查询的线段树。懒标记背景我们发现虽然我们可以做到在O(logn)O(log_{n})O(logn)的时间内做到单点修改,但我们如果将一个区间修改,我们发现时间复杂度为O(nlogn)O(nlog_{n})O(nlogn),比暴力还慢。那我们只能想一些其他方法了。结构分析我们先从线段树的结构入手:还是这张
蓝桥杯刷题 Day5 线段树(树状数组)
雁于飞
蓝桥杯 职场和发展 学习 笔记 数据结构 算法 java
蓝桥杯刷题Day5线段树文章目录蓝桥杯刷题Day5线段树前言完整代码一、树状数组1.解题思路1.1问题抽象1.2核心思想1.2适用条件:1.3典型应用:2.拆解代码2.1主函数2.1.1输入以及初始化2.1.2处理查询2.2SegmentTree类2.2.1初始化数组以及最低有效位2.2.2单点更新与集区间求和二、题后收获3.1知识点前言今天写牛客网模板题中数据结构的线段树完整代码一、树状数组原题
P3740 [HAOI2014] 贴海报 题解
lhschris
题解
P3740[HAOI2014]贴海报题解思路我们模拟一下贴海报的过程,先把x∼yx\simyx∼y的数字全部变成kkk。后面的数字可以覆盖前面的数字。如果for循环枚举的话是会超时的,我们考虑用线段树维护区间数字。那么所有操作结束后如果当前区间还有当前数字,ans++ans++ans++。那么这么判断呢?也就是pushup怎么做?求最小值最好了。因为每个区间的最小值只能是当前数字,因为当前区间已经
小木的算法日记-线段树
木旭林晖
算法
线段树(SegmentTree):玩转区间作的终极利器你好,未来的算法大师!想象一下,你正在处理一个巨大的数据集,比如某个电商网站一整天的用户点击流。老板突然问你:“下午2点到3点之间,我们的总点击量是多少?”几分钟后,他又问:“把10点到11点之间的数据,因为系统故障,全部乘以0.5,然后再告诉我下午的总点击量。”如果用普通的数组,每次查询都需要遍历,每次修改更是灾难。面对这种需求,我们该怎么办
【贪心、DP、线段树优化】Leetcode 376. 摆动序列
Wendy_robot
leetcode 算法
贪心算法:选“关键转折点”初始状态:把数组第一个元素当作起点,此时前一个差值符号设为平坡(即差值为0)。遍历数组:从第二个元素开始,依次计算当前元素和前一个元素的差值。差值符号判断:差值大于0:要是之前的差值是小于等于0(平坡或者下降状态),那就说明找到了一个从下降到上升的摆动点,更新最大摆动点数,同时把前一个差值符号标记为上升(大于0)。差值小于0:若之前的差值是大于等于0(平坡或者上升状态),
Codeforces Round 974 (Div. 3) A-F
swan416
题解 图论 算法 c++ 数据结构 算法竞赛 Codeforces 信息学竞赛
封面原图画师礼島れいあ下午的ICPC网络赛的难受一晚上全都给我打没了手速拉满再加上秒杀线段树这场简直了啊唯一可惜的是最后还是掉出了1000名一把上蓝应该没啥希望了吧A-RobinHelps题意侠盗罗宾因劫富济贫而闻名于世罗宾遇到的nnn人,从1st1_{st}1st开始,到nthn_{th}nth结束。iii第三个人有aia_iai金子。如果是ai≥ka_i\gekai≥k,罗宾会拿走所有的aia
【Algorithm】Segment Tree 简单介绍
CodeWithMe
C/C++ c++ 算法 python
文章目录SegmentTree1基本概念2基本思想3适用场景4代码示例(区间求和)5使用示例6使用注意事项7进阶拓展SegmentTree线段树(SegmentTree)是一种高级数据结构,主要用于在区间范围内高效地进行查询与修改操作。它是一个二叉树结构,每个节点代表一个区间的信息,通常用于解决如下问题:1基本概念线段树是对一个区间[l,r]上的数列进行划分,并在每个子区间上维护某种信息(如最值、
【算法笔记】树套树
PXM的算法星球
算法笔记 算法 笔记
一、前言在面对二维区间统计问题时,比如:查询某个一维区间中,大于某个值的数的个数对一个序列同时支持区间查询+单点修改我们常用的一维数据结构(如线段树、树状数组)往往显得力不从心。此时,我们可以考虑一种高效的数据结构组合:树套树。二、什么是树套树?“树套树”顾名思义,就是一棵树中的每个节点再套一棵树。最常见的树套树结构是:外层:线段树/树状数组,按照下标维护区间内层:平衡树(如STLmultiset
Python·算法分类题库
欢迎关注【Python·算法分类题库】,持续更新中……知识点A字符串(AC自动机、拓展KMP、后缀数组、后缀自动机、回文自动机)图论(网络流、一般图匹配)数学(生成函数、莫比乌斯反演、快速傅里叶变换)数据结构(树链剖分、二维/动态开点线段树、平衡树、可持久化数据结构、树套树、动态树)B排序(归并、快速、桶、堆、基数)搜索(剪枝、双向BFS、记忆化搜索、迭代加深搜索、启发式搜索)DP(背包、树形、状
蓝桥杯康复训练 Day4 (前缀和)(树状数组)(线段树)
ooold_six
2022蓝桥杯 java 算法
昨天没状态摆了一天,今天复习一下各种区间问题前缀和常规遍历区间求和复杂度O(n)单点修改复杂度O(1)前缀和区间求和复杂度O(1)单点修改复杂度O(n)前缀和数组中每个值覆盖的是从开始到该点整个区间的和值求i~j的区间和值可以通过s[j]-s[i-1]计算可以扩展成二维三维的前缀和在单点修改时需要对所有覆盖该点的值进行修改在对区间求和复杂度要求高时使用蓝桥杯–前缀和1树状数组对比前缀和复杂度前缀和
线段树刷题1
code自留地
线段树
[TJOI2009]开关luogu链接:https://www.luogu.com.cn/problem/P3870ps:好好的一道省选题打绿了不说,居然是道橙题!也就和一道dfs的难度一样···你洛谷是不是人均线段树??分析题意:我们仍然是要进行区间修改的操作,那懒标记是逃不过了喂·然后我们分析至少需要维护哪些信息:亮灯总个数是需要维护的吧但是这样够不够?因为我们还要表示出“亮灯变暗,暗灯点亮”
线段树刷题记录
弥彦_
c++ 算法 c++ 数据结构
一、区间查询无修改:(一)最值问题:1.P1816忠诚-洛谷思路:模板。注意:无。代码:#include#defineiosccios::sync_with_stdio(false),cin.tie(0),cout.tie(0)#defineendl'\n'#defineme(a,x)memset(a,x,sizeofa)#defineall(a)a.begin(),a.end()#defines
数据结构---线段树
4FGR
数据结构 开发语言 c++ 算法 数据结构
线段树参考:线段树-OIWiki线段树是一种二叉搜索树、平衡二叉树,对于区间的修改、维护和查询时间复杂度优化为log级别。对区间不断做平分区间,直到划分到只有一个或多个数据的区间,可表示区间的和或者最小最大值。在进行更新区间操作时,通过小区间更新大区间。对于下面的内容,我们主要针对于区间加法的线段树(即其节点表示区间之和)。局限性:问题需满足区间加法:对于[L,R]的区间,它的答案可以由[L,M]
洛谷所有 NOI/NOI+/CTSC 的题目
一个不会写代码的小白
c++ 洛谷 洛谷 NOI/NOI+/CTSC c++ 算法 数据结构 开发语言
洛谷——luoguOJ所有NOI/NOI+/CTSC的P/C开头题目P8861线段P5111zhtobu3232的线段树P7719「EZEC-10」多彩的线段P5210[ZJOI2017]线段树P10145[WC2024]线段树P10211[CTS2024]线段树P7445「EZEC-7」线段树P5342[TJOI2019]甲苯先生的线段树P8498[NOI2022]树上邻域数点P5659[CSP
USST新生训练赛3KLMN
Fighter_sky
题解 C++ acm
题解前言题解部分KPashmakandParmida'sproblem(1800)题目大意题解参考代码LPashmakandGraph(1900)题目大意题解参考代码MLuckyChains(1600)题目大意题解参考代码NManipulatingHistory(1600)题目大意题解参考代码前言KLMN是数据结构(线段树/树状数组)+dp+数论+结论唐题题解部分KPashmakandParmid
权值线段树和可持久化线段树(主席树)
.Q_W.
算法 算法 数据结构
目录权值线段树权值线段树的基本概念权值线段树的构建权值线段树的操作添加元素查询区间[l,r]的元素个数查询整个集合中第k小(或第k大)的元素值例题代码实现可持久化线段树(主席树)例题1代码实现例题2思路代码实现权值线段树权值线段树的基本概念权值线段树是一种特殊的线段树,它的叶子节点存储的是某个元素的权值(通常是该元素的出现次数),而不是元素本身。分支节点则存储其子节点权值的某种集合值(如和、最值等
关于队里面最菜的在博客打卡第三十七天这件事
算法好难 TAT
算法 数据结构 线段树 mex
传送门:很难想象一个非要暴力去解题人的精神状态这是一道神奇的题,题意是给你一个序列,然后问你这个序列是否可以用两个排列拼接而成,并且一左一右,如果可以的话有几种情况。问题十分的棘手(后来才发现只有3种结果),刚开始想用线段树或者树状数组去维护左右区间的数的个数,再判断数的多少和区间的大小,后来发现重复数据会出现很多问题,而且并且没有想到办法解决,于是突发奇想,好像区间的mex和区间的大小可以用来判
高级数据结构 - 线段树、权值线段树(Java & JS & Python)
程序员阿甘
算法 数据结构 Java JavaScript Python
引子现在给定一个数组arr=[4,7,5,3,8,9,0,1,2,6],arr.length=n,无规律地多次进行如下操作:查询arr指定区间[l,r]内最大值max查询arr指定区间[l,r]内元素之和sumarr指定索引i位置的元素新增C或者覆盖为Carr指定区间[l,r]内每个元素值新增C或者覆盖为C其中:查询(区间最大值、区间和)的时间复杂度为O(n)单值更新的时间复杂度为O(1)区间更新
高级数据结构之线段树(Segment Tree)
白马负金羁
数据结构与算法分析 线段树 Segment Tree LeetCode307 数据结构
线段树(SegmentTree)也是一种树形的数据结构(本质上是一棵二叉搜索树),只不过树中结点存储的值是一个区间或一个线段。常用于区间内数值的查询操作,比如一个区间内的最大值(max),最小值(min),以及加和(sum)等等。该结构由美国计算机科学家JonBentley于1977年提出,JonBentley还是畅销书《编程珠玑》的作者。有些资料上将线段树和区间树(IntervalTrees)混
[LeetCode] 树状数组+线段树总结
virgilshi
树状数组 线段树 LeetCode
文章目录写在前面线段树树桩数组相关题写在前面LeetCode树状数组+线段树的题比较少,而且这两个知识点在面试时被考察的概率极小,但是如果我们知道这两个知识点,在解题的时候会非常便捷(利用高维度工具打击低维度题目,解题所需的思维量会少很多),本文也是出于学习树状数组和线段树的目的写在这篇博客的。线段树线段树是二叉树形态的数据结构,用于存储和查询包含某个点的所有区间,时间复杂度为O(lgn+k),k
树状数组与线段树入门
Maximum_Mighty_X
c++
树状数组和线段树都是用于处理动态区间问题的数据结构。树状数组:支持区间加法的同时区间查询区间和,以及最值;线段树:支持区间加法的同时区间乘法的同时区间查询区间和,以及最值。线段树的适用范围相较于树状数组更加广泛,但树状数组相对于线段树简洁很多,且常数极小。树状数组树状数组的空间复杂度为O(n),时间上单次查询为O(logn)。首先我们需要知道这个定义:lowbit(x):表示x在二进制下从低位往高
kuangbin 最小生成树专题 - POJ - 2421 Constructing Roads (朴素 Prim算法 模板题)
会划水才能到达彼岸
最小生成树专题 kuangbin 题单 算法 图论 c++ 数据结构 树结构
kuangbin最小生成树专题-POJ-2421ConstructingRoads(朴素Prim算法模板题)英文版Clickhere~~意译版Clickhere~~总题单week3[kuangbin带你飞]题单最小生成树+线段树Clickhere~~https://blog.csdn.net/m0_46272108/article/details/108980362英文版Clickhere~~De
【刷题2025】贪心算法+KMP算法+暴力枚举+扫描树线段树+LFU缓存
cIlIegia_1234
算法 贪心算法
1.贪心算法(1)火锅题目描述入职后,导师会请你吃饭,你选择了火锅。火锅里会在不同时间下很多菜.不同食材要煮不同的时间,才能变得刚好合适。你希望吃到最多的刚好合适的菜,但你的手速不够快,用m代表手速,每次下手捞菜后至少要过m秒才能再捞(每次只能捞一个)。那么用最合理的策略,最多能吃到多少刚好合适的菜?输入描述第一行两个整数n,m,其中n代表往锅里下的菜的个数,m代表手速。(1=m:ans+=1pr
Python蓝桥杯算法模板
敲击大怪兽
python 蓝桥杯 算法
Python蓝桥杯算法模板今天来给大家分享超实用的Python蓝桥杯算法模板,助力大家在蓝桥杯比赛中披荆斩棘~目录sys库math库datetime库queue库list常用apiset常用apistr常用api进制转换与排序并查集(DSU)最短路径(Dijkstra)线段树(SegTree)sys库sys库是Python的标准库,它提供了许多与Python解释器和系统环境相关的功能。比如sys.
关于python与c++效率的对比实战
鸿雁拉着我飞
python 效率 C++ 排序
c语言是编译型语言,python是解释型语言,因此两者的效率有不小的差距,可没想到差距那么大。最近跟hackerrank上一道排序的题目杠上了(感兴趣的同学可以去看看,名为sortedsubsegment),用的python,废了几天功夫都没解出来。终于还是看了答案(用的是二分查找的思想与线段树的数据结构),答案是java写的。于是我用python实现出来,速度依然不行。于是又用c++写了一遍。结
蓝桥杯python组备赛(记录个人模板)
潇湘夜雨697
算法专项 蓝桥杯 python
文章目录栈队列堆递归装饰器并查集树状数组线段树最近公共祖先LCAST表字典树KMPmanacher跳表(代替C++STL的set)dijkstra总结栈用list代替队列用deque双端队列替代堆用heapq递归装饰器众所周知,python的递归深度只有1000,根本满足不了大部分1e5以上的数据,当然你可以使用sys.setrecursionlimit(1000000)扩到1e6,但是这会增加空
算法整理 & 复习
SP FA
数据结构与算法 c++ 算法 数据结构
搬自hzwer文章目录一、基本数据结构1.数组2.链表、双向链表3.队列、单调队列、双端队列4.栈、单调栈5.前缀和、差分二、中级数据结构1.堆2.并查集、带权并查集3.哈希、哈希冲突三、高级数据结构1.树状数组2.线段树、线段树合并3.平衡树3.1Treap随机平衡二叉树3.2Splay伸展树3.3替罪羊树3.4红黑树4.块状数组、块状链表5.树套树5.1线段树套线段树5.2线段树套平衡树5.3
玩转数据结构 java描述 一 概况
Qqun954715313
互联网 java 程序员 数据结构
第一章介绍,数据结构是计算机专业的同学必学的课程数据结构研究的是数据如何在计算机进行组织和存储,使得我们可以高效的获取数据或者修改数据。数据结构可以分为三种结构:线性结构:数组;栈;队列;链表;哈希表树结构:二叉树,二分搜索树,AVL,红黑树,Treap,Splay,堆,Trie,线段树,K-D树,并查集,哈夫曼树图结构邻接矩阵,邻接表我们需要根据应用的不同,灵活选择最合适的数据结构,例子:1,数
树状数组、线段树 | P8613 [蓝桥杯 2014 省 B] 小朋友排队C++题解
一只一只
蓝桥杯 c++ 算法
P8613[蓝桥杯2014省B]小朋友排队原题链接题目描述nnn个小朋友站成一排。现在要把他们按身高从低到高的顺序排列,但是每次只能交换位置相邻的两个小朋友。每个小朋友都有一个不高兴的程度。开始的时候,所有小朋友的不高兴程度都是000。如果某个小朋友第一次被要求交换,则他的不高兴程度增加111,如果第二次要求他交换,则他的不高兴程度增加222(即不高兴程度为333),依次类推。当要求某个小朋友第k
线段树_P3372/P3373_Python
How_doyou_do
数据结构 python 算法 线段树
前面是线段树的模版代码,后面有例题P3372和P3373的应用话不多说,上代码classNode:#节点类def__init__(self,l,r):self.l=l#区间左端点self.r=r#区间右端点self.left=None#左子节点self.right=None#右子节点self.sum=0#区间和self.max=-float('inf')#区间最大值self.min=float('
深入浅出Java Annotation(元注解和自定义注解)
Josh_Persistence
Java Annotation 元注解 自定义注解
一、基本概述
Annontation是Java5开始引入的新特征。中文名称一般叫注解。它提供了一种安全的类似注释的机制,用来将任何的信息或元数据(metadata)与程序元素(类、方法、成员变量等)进行关联。
更通俗的意思是为程序的元素(类、方法、成员变量)加上更直观更明了的说明,这些说明信息是与程序的业务逻辑无关,并且是供指定的工具或
mysql优化特定类型的查询
annan211
java 工作 mysql
本节所介绍的查询优化的技巧都是和特定版本相关的,所以对于未来mysql的版本未必适用。
1 优化count查询
对于count这个函数的网上的大部分资料都是错误的或者是理解的都是一知半解的。在做优化之前我们先来看看
真正的count()函数的作用到底是什么。
count()是一个特殊的函数,有两种非常不同的作用,他可以统计某个列值的数量,也可以统计行数。
在统
MAC下安装多版本JDK和切换几种方式
棋子chessman
jdk
环境:
MAC AIR,OS X 10.10,64位
历史:
过去 Mac 上的 Java 都是由 Apple 自己提供,只支持到 Java 6,并且OS X 10.7 开始系统并不自带(而是可选安装)(原自带的是1.6)。
后来 Apple 加入 OpenJDK 继续支持 Java 6,而 Java 7 将由 Oracle 负责提供。
在终端中输入jav
javaScript (1)
Array_06
JavaScript java 浏览器
JavaScript
1、运算符
运算符就是完成操作的一系列符号,它有七类: 赋值运算符(=,+=,-=,*=,/=,%=,<<=,>>=,|=,&=)、算术运算符(+,-,*,/,++,--,%)、比较运算符(>,<,<=,>=,==,===,!=,!==)、逻辑运算符(||,&&,!)、条件运算(?:)、位
国内顶级代码分享网站
袁潇含
java jdk oracle .net PHP
现在国内很多开源网站感觉都是为了利益而做的
当然利益是肯定的,否则谁也不会免费的去做网站
&
Elasticsearch、MongoDB和Hadoop比较
随意而生
mongodb hadoop 搜索引擎
IT界在过去几年中出现了一个有趣的现象。很多新的技术出现并立即拥抱了“大数据”。稍微老一点的技术也会将大数据添进自己的特性,避免落大部队太远,我们看到了不同技术之间的边际的模糊化。假如你有诸如Elasticsearch或者Solr这样的搜索引擎,它们存储着JSON文档,MongoDB存着JSON文档,或者一堆JSON文档存放在一个Hadoop集群的HDFS中。你可以使用这三种配
mac os 系统科研软件总结
张亚雄
mac os
1.1 Microsoft Office for Mac 2011
大客户版,自行搜索。
1.2 Latex (MacTex):
系统环境:https://tug.org/mactex/
&nb
Maven实战(四)生命周期
AdyZhang
maven
1. 三套生命周期 Maven拥有三套相互独立的生命周期,它们分别为clean,default和site。 每个生命周期包含一些阶段,这些阶段是有顺序的,并且后面的阶段依赖于前面的阶段,用户和Maven最直接的交互方式就是调用这些生命周期阶段。 以clean生命周期为例,它包含的阶段有pre-clean, clean 和 post
Linux下Jenkins迁移
aijuans
Jenkins
1. 将Jenkins程序目录copy过去 源程序在/export/data/tomcatRoot/ofctest-jenkins.jd.com下面 tar -cvzf jenkins.tar.gz ofctest-jenkins.jd.com &
request.getInputStream()只能获取一次的问题
ayaoxinchao
request Inputstream
问题:在使用HTTP协议实现应用间接口通信时,服务端读取客户端请求过来的数据,会用到request.getInputStream(),第一次读取的时候可以读取到数据,但是接下来的读取操作都读取不到数据
原因: 1. 一个InputStream对象在被读取完成后,将无法被再次读取,始终返回-1; 2. InputStream并没有实现reset方法(可以重
数据库SQL优化大总结之 百万级数据库优化方案
BigBird2012
SQL优化
网上关于SQL优化的教程很多,但是比较杂乱。近日有空整理了一下,写出来跟大家分享一下,其中有错误和不足的地方,还请大家纠正补充。
这篇文章我花费了大量的时间查找资料、修改、排版,希望大家阅读之后,感觉好的话推荐给更多的人,让更多的人看到、纠正以及补充。
1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引。
2.应尽量避免在 where
jsonObject的使用
bijian1013
java json
在项目中难免会用java处理json格式的数据,因此封装了一个JSONUtil工具类。
JSONUtil.java
package com.bijian.json.study;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
[Zookeeper学习笔记之六]Zookeeper源代码分析之Zookeeper.WatchRegistration
bit1129
zookeeper
Zookeeper类是Zookeeper提供给用户访问Zookeeper service的主要API,它包含了如下几个内部类
首先分析它的内部类,从WatchRegistration开始,为指定的znode path注册一个Watcher,
/**
* Register a watcher for a particular p
【Scala十三】Scala核心七:部分应用函数
bit1129
scala
何为部分应用函数?
Partially applied function: A function that’s used in an expression and that misses some of its arguments.For instance, if function f has type Int => Int => Int, then f and f(1) are p
Tomcat Error listenerStart 终极大法
ronin47
tomcat
Tomcat报的错太含糊了,什么错都没报出来,只提示了Error listenerStart。为了调试,我们要获得更详细的日志。可以在WEB-INF/classes目录下新建一个文件叫logging.properties,内容如下
Java代码
handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHa
不用加减符号实现加减法
BrokenDreams
实现
今天有群友发了一个问题,要求不用加减符号(包括负号)来实现加减法。
分析一下,先看最简单的情况,假设1+1,按二进制算的话结果是10,可以看到从右往左的第一位变为0,第二位由于进位变为1。
 
读《研磨设计模式》-代码笔记-状态模式-State
bylijinnan
java 设计模式
声明: 本文只为方便我个人查阅和理解,详细的分析以及源代码请移步 原作者的博客http://chjavach.iteye.com/
/*
当一个对象的内在状态改变时允许改变其行为,这个对象看起来像是改变了其类
状态模式主要解决的是当控制一个对象状态的条件表达式过于复杂时的情况
把状态的判断逻辑转移到表示不同状态的一系列类中,可以把复杂的判断逻辑简化
如果在
CUDA程序block和thread超出硬件允许值时的异常
cherishLC
CUDA
调用CUDA的核函数时指定block 和 thread大小,该大小可以是dim3类型的(三维数组),只用一维时可以是usigned int型的。
以下程序验证了当block或thread大小超出硬件允许值时会产生异常!!!GPU根本不会执行运算!!!
所以验证结果的正确性很重要!!!
在VS中创建CUDA项目会有一个模板,里面有更详细的状态验证。
以下程序在K5000GPU上跑的。
诡异的超长时间GC问题定位
chenchao051
jvm cms GC hbase swap
HBase的GC策略采用PawNew+CMS, 这是大众化的配置,ParNew经常会出现停顿时间特别长的情况,有时候甚至长到令人发指的地步,例如请看如下日志:
2012-10-17T05:54:54.293+0800: 739594.224: [GC 739606.508: [ParNew: 996800K->110720K(996800K), 178.8826900 secs] 3700
maven环境快速搭建
daizj
安装 mavne 环境配置
一 下载maven
安装maven之前,要先安装jdk及配置JAVA_HOME环境变量。这个安装和配置java环境不用多说。
maven下载地址:http://maven.apache.org/download.html,目前最新的是这个apache-maven-3.2.5-bin.zip,然后解压在任意位置,最好地址中不要带中文字符,这个做java 的都知道,地址中出现中文会出现很多
PHP网站安全,避免PHP网站受到攻击的方法
dcj3sjt126com
PHP
对于PHP网站安全主要存在这样几种攻击方式:1、命令注入(Command Injection)2、eval注入(Eval Injection)3、客户端脚本攻击(Script Insertion)4、跨网站脚本攻击(Cross Site Scripting, XSS)5、SQL注入攻击(SQL injection)6、跨网站请求伪造攻击(Cross Site Request Forgerie
yii中给CGridView设置默认的排序根据时间倒序的方法
dcj3sjt126com
GridView
public function searchWithRelated() {
$criteria = new CDbCriteria;
$criteria->together = true; //without th
Java集合对象和数组对象的转换
dyy_gusi
java集合
在开发中,我们经常需要将集合对象(List,Set)转换为数组对象,或者将数组对象转换为集合对象。Java提供了相互转换的工具,但是我们使用的时候需要注意,不能乱用滥用。
1、数组对象转换为集合对象
最暴力的方式是new一个集合对象,然后遍历数组,依次将数组中的元素放入到新的集合中,但是这样做显然过
nginx同一主机部署多个应用
geeksun
nginx
近日有一需求,需要在一台主机上用nginx部署2个php应用,分别是wordpress和wiki,探索了半天,终于部署好了,下面把过程记录下来。
1. 在nginx下创建vhosts目录,用以放置vhost文件。
mkdir vhosts
2. 修改nginx.conf的配置, 在http节点增加下面内容设置,用来包含vhosts里的配置文件
#
ubuntu添加admin权限的用户账号
hongtoushizi
ubuntu useradd
ubuntu创建账号的方式通常用到两种:useradd 和adduser . 本人尝试了useradd方法,步骤如下:
1:useradd
使用useradd时,如果后面不加任何参数的话,如:sudo useradd sysadm 创建出来的用户将是默认的三无用户:无home directory ,无密码,无系统shell。
顾应该如下操作:
第五章 常用Lua开发库2-JSON库、编码转换、字符串处理
jinnianshilongnian
nginx lua
JSON库
在进行数据传输时JSON格式目前应用广泛,因此从Lua对象与JSON字符串之间相互转换是一个非常常见的功能;目前Lua也有几个JSON库,本人用过cjson、dkjson。其中cjson的语法严格(比如unicode \u0020\u7eaf),要求符合规范否则会解析失败(如\u002),而dkjson相对宽松,当然也可以通过修改cjson的源码来完成
Spring定时器配置的两种实现方式OpenSymphony Quartz和java Timer详解
yaerfeng1989
timer quartz 定时器
原创整理不易,转载请注明出处:Spring定时器配置的两种实现方式OpenSymphony Quartz和java Timer详解
代码下载地址:http://www.zuidaima.com/share/1772648445103104.htm
有两种流行Spring定时器配置:Java的Timer类和OpenSymphony的Quartz。
1.Java Timer定时
首先继承jav
Linux下df与du两个命令的差别?
pda158
linux
一、df显示文件系统的使用情况,与du比較,就是更全盘化。 最经常使用的就是 df -T,显示文件系统的使用情况并显示文件系统的类型。 举比例如以下: [root@localhost ~]# df -T Filesystem Type &n
[转]SQLite的工具类 ---- 通过反射把Cursor封装到VO对象
ctfzh
VO android sqlite 反射 Cursor
在写DAO层时,觉得从Cursor里一个一个的取出字段值再装到VO(值对象)里太麻烦了,就写了一个工具类,用到了反射,可以把查询记录的值装到对应的VO里,也可以生成该VO的List。
使用时需要注意:
考虑到Android的性能问题,VO没有使用Setter和Getter,而是直接用public的属性。
表中的字段名需要和VO的属性名一样,要是不一样就得在查询的SQL中
该学习笔记用到的Employee表
vipbooks
oracle sql 工作
这是我在学习Oracle是用到的Employee表,在该笔记中用到的就是这张表,大家可以用它来学习和练习。
drop table Employee;
-- 员工信息表
create table Employee(
-- 员工编号
EmpNo number(3) primary key,
-- 姓