日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

51NOD 1287 加农炮(不水的线段树)

發布時間:2023/11/27 生活经验 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 51NOD 1287 加农炮(不水的线段树) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

》》點擊進入原題測試《《

Input示例
9 11
1
2
0
4
3
2
1
5
7
2
8
0
7
6
5
3
4
5
6
5
Output示例
2
2
2
4
3
3
5
6
7

思路:剛開始以為結點存最大值就行了,然后大于左子樹的最大值就能進入右子樹;然后發現樣例都過不了;后面發現,并不是這個樣子,假如這個數小于等于右孩子最左邊那個數的話,也不能進入有孩子,所以結點還得保存右孩子最左邊的那個值;同時更新一個最大值,當輸入值咸魚等于a[0]或者大于最大值時跳過。

#include<climits>
#include<iostream>
#include<algorithm>
using namespace std;#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll long long
const int maxn = 5e4 + 5;
ll tree[maxn << 2], mtree[maxn << 2], a[maxn];
ll ma = INT_MIN;void build(int l, int r, int rt)
{if (l == r){tree[rt] = a[l];mtree[rt] = a[l];return;}int m = (l + r) >> 1;build(lson);build(rson);tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]);mtree[rt] = mtree[rt << 1];
}
void update(int x, int l, int r, int rt)
{if (l == r){a[l] += 1;tree[rt] += 1;mtree[rt] += 1;if (a[l] > ma)ma = a[l];return;}int m = (l + r) >> 1;if (tree[rt << 1] < x&&x>mtree[rt << 1 | 1])update(x, rson);else update(x, lson);tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]);mtree[rt] = mtree[rt << 1];
}
void Print(int l, int r, int rt)
{if (l == r){cout << rt << " = " << tree[rt] << endl;return;}cout << rt << " = " << tree[rt] << endl;int m = (r + l) >> 1;if (l <= m)Print(lson);if (r > m)Print(rson);
}
int main()
{std::ios::sync_with_stdio(false);int m, n; cin >> m >> n;for (int i = 1; i <= m; i++){cin >> a[i];if (ma < a[i])ma = a[i];}build(1, m, 1);int temp;while (n--){cin >> temp;if (temp <= a[1] || temp>ma)continue;update(temp, 1, m, 1);//Print(1, m, 1);    
    }for (int i = 1; i <= m; i++){if (i != 1)cout << endl;cout << a[i];}}

?

轉載于:https://www.cnblogs.com/zengguoqiang/p/9385192.html

總結

以上是生活随笔為你收集整理的51NOD 1287 加农炮(不水的线段树)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。