ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#200096 | #2700. 数列 | Anonyme | 100 | 122ms | 7988kb | C++11 | 1.1kb | 2023-12-28 09:43:58 | 2023-12-28 13:55:13 |
answer
#include<bits/stdc++.h>
using namespace std;
#define QwQ330AwA return 0
#define ll long long
const int N = 1e6 + 5;
int n;
int w[N];
bool vis[N];
vector <int> pos;
ll cal(int l, int r) {
//cout << l << ' ' << r << endl;
int mn = 1e9, suf = 0;
for (int i = l; i <= r; i++) mn = min(mn, w[i]), suf += vis[i];
int pre = 0;
int ans = 1e9;
for (int i = l; i <= r; i++) {
if (mn == w[i]) pre++;
if (vis[i]) suf--;
ans = min(ans, pre + suf);
}
return ans;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
int mn = 1e9;
int f = 0;
for (int i = 1; i <= n; i++) {
cin >> w[i];
f = max(f, w[i] - mn);
mn = min(mn, w[i]);
}
mn = 1e9;
pos.push_back(0);
for (int i = 1; i <= n; i++) {
if (w[i] - mn == f) vis[i] = 1, pos.push_back(i);
mn = min(mn, w[i]);
}
int m = pos.size();
w[0] = 2e9;
ll ans = 0;
for (int i = 1, j = 1; i < m; i = j) {
while (j < m && w[pos[j]] == w[pos[i]]) j++;
//cout << i << ' ' << j << endl;
ans += cal(pos[i - 1] + 1, pos[j - 1]);
}
cout << ans;
QwQ330AwA;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 24
Accepted
Test #1:
score: 24
Accepted
time: 0ms
memory: 1264kb
input:
20 123333333 100000000 123333333 100000000 100000000 100000000 100000000 -46629627 -46629627 -466296...
output:
2
result:
ok single line: '2'
Subtask #2:
score: 16
Accepted
Test #2:
score: 16
Accepted
time: 0ms
memory: 1272kb
input:
100 100000000 123333333 123333333 123333333 123333333 123333333 123333333 100000000 123333333 100000...
output:
24
result:
ok single line: '24'
Subtask #3:
score: 21
Accepted
Test #3:
score: 21
Accepted
time: 0ms
memory: 1312kb
input:
5000 123333333 100000000 123333333 100000000 123333333 100000000 100000000 109260380 100000000 10778...
output:
1424
result:
ok single line: '1424'
Subtask #4:
score: 39
Accepted
Test #4:
score: 39
Accepted
time: 12ms
memory: 1960kb
input:
100000 107584386 100000000 117570850 100000000 100000000 100000000 123333333 113985760 100000000 100...
output:
32140
result:
ok single line: '32140'
Test #5:
score: 0
Accepted
time: 110ms
memory: 7988kb
input:
1000000 100000000 116429445 123333333 109196270 123333333 111215733 100000000 100000000 100000000 10...
output:
328969
result:
ok single line: '328969'
Extra Test:
score: 0
Extra Test Passed