codeforces 599C (树状数组)
来源:互联网 发布:sql 2005 编辑:程序博客网 时间:2024/04/30 06:38
题意是给你n个城堡,最多能把他们分成几个连续的区间使得每个区间按照高度排序完以后整体高度也是升序
用某种数据结构维护一下去前缀和就行了
#include <bits/stdc++.h>using namespace std;#define maxn 111111int c[maxn];struct node { int num, pos; bool operator < (node a) const { return num < a.num || (num == a.num && pos < a.pos); }}a[maxn];int n;int lowbit (int x) { return x & (-x);}void add (int pos) { for (int i = pos; i <= n; i += lowbit (i)) c[i]++;}int sum (int pos) { int ans = 0; for (int i = pos; i > 0; i -= lowbit (i)) ans += c[i]; return ans;}int main () { scanf ("%d", &n); memset (c, 0, sizeof c); for (int i = 1; i <= n; i++) { scanf ("%d", &a[i].num); a[i].pos = i; } sort (a+1, a+1+n); int ans = 0; for (int i = 1; i <= n; i++) { add (a[i].pos); //cout << "sum:" << sum (i) << endl; if (sum (i) == i) ans++; } cout << ans << endl; return 0;}
0 0
- codeforces 599C (树状数组)
- codeforces 827C 树状数组
- Codeforces 853C 树状数组
- Codeforces 383C Propagating tree(树状数组)
- CodeForces 396C 树状数组 + DFS
- Codeforces 597C(树状数组 + dp)
- Codeforces 597C Subsequences dp + 树状数组
- codeforces-597C-Subsequences【树状数组】
- codeforces 597C (树状数组+DP)
- Subsequences CodeForces - 597C 树状数组 + dp
- CodeForces 597C 树状数组 dp
- Codeforces Round #413 C-Fountains 树状数组
- Codeforces 383C Propagating tree(树状数组)
- codeforces 362 C. Insertion Sort(树状数组,逆序数)
- Codeforces Round 223 380C Sereja and Brackets 树状数组
- Codeforces 383C Propagating tree(树状数组)
- Codeforces 396C On Changing Tree(树状数组)
- Codeforces 383C . Propagating tree【树状数组,dfs】
- bfs
- Binary Tree Paths
- 奇技淫巧之浏览器秒秒钟变编辑器
- 我的第一篇博客(mysql只比较月日的情况)
- HDU 1358 Period
- codeforces 599C (树状数组)
- Android之常用头文件列表
- Maven管理Oracle10g和Oracle11g驱动包
- 文本编辑距离
- adapter入门
- 黑马程序员——线程
- ViewPager的基本用法
- Android之常用代码片段收集
- js字符串的分割