#include <bits/stdc++.h> using namespace std; #define N 1000050 long long score[N]; long long a[N], s[N]; long long n; int main(){ int tem = 0; cin >> n; for(int i = 1; i <= n; i++) a[i] = (1 + i) * i / 2; for(int i = 1; i <= n; i++) scanf("%lld", &score[i]); for(int i = 1; i <= n; i++){ if(score[i] >= score[i - 1]){ tem++; // if(i != n) continue; } s[tem]++; tem = 1; } s[tem]++; if(n == 0){ printf("0\n"); return 0; } long long ans = 0; for(int i = 1; i <= n; i++) ans += a[i] * s[i]; printf("%lld\n", ans); return 0; }
有无大佬看下今天的C题,想着找出数列中每个非递减的长度,然后保存,最后求答案,是思路有问题还是细节出错了qwq
全部评论
(0) 回帖