减成一
题目链接以为是个线段树,结果写到一半写不出来了。。赛后看别人代码发现是思维AC代码:/** @Author: hesorchen* @Date: 2020-04-14 10:33:26* @LastEditTime: 2020-05-31 17:44:16* @Link: https://hesorchen.github.io/*/#include <map>#include <
·
以为是个线段树,结果写到一半写不出来了。。
赛后看别人代码发现是思维
AC代码:
/*
* @Author: hesorchen
* @Date: 2020-04-14 10:33:26
* @LastEditTime: 2020-05-31 17:44:16
* @Link: https://hesorchen.github.io/
*/
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define endl '\n'
#define PI cos(-1)
#define PB push_back
#define ll long long
#define INF 0x3f3f3f3f
#define mod 998244353
#define lowbit(abcd) (abcd & (-abcd))
#define max(a, b) ((a > b) ? (a) : (b))
#define min(a, b) ((a < b) ? (a) : (b))
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define FRE \
{ \
freopen("in.txt", "r", stdin); \
freopen("out.txt", "w", stdout); \
}
inline ll read()
{
ll x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
//==============================================================================
ll a[100010];
int main()
{
int t;
cin >> t;
while (t--)
{
ll n;
n = read();
for (int i = 1; i <= n; i++)
a[i] = read() - 1;
ll maxx = 0;
ll ans = 0;
for (int i = 1; i <= n; i++)
{
if (a[i] > maxx)
ans += a[i] - maxx, maxx = max(maxx, a[i]);
else
maxx = a[i];
}
cout << ans << endl;
}
return 0;
}
/*
0 2 4 1 6 0
*/
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献2条内容
所有评论(0)