QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#745875 | #9584. 顾影自怜 | TJUHuangTao | WA | 66ms | 50872kb | C++20 | 1.6kb | 2024-11-14 12:07:23 | 2024-11-14 12:07:26 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define inf 0x3f3f3f3f
#define ll long long
#define pii pair<int, int>
#define tii tuple<int, int, int>
#define db double
#define all(a) a.begin(), a.end()
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 998244353;
int L[maxn], R[maxn];
int arr[maxn], nxt[maxn];
vector<int> pos[maxn];
void solve() {
stack<int> stk;
int n, k; cin >> n >> k;
for (int i = 1; i <= n; i++) pos[i].clear(), nxt[i] = n + 1;
for (int i = 1; i <= n; i++) cin >> arr[i];
for (int i = 1; i <= n; i++) {
while (!stk.empty() && arr[i] > arr[stk.top()])
stk.pop();
if (!stk.empty()) L[i] = stk.top();
stk.push(i);
pos[arr[i]].push_back(i);
}
while (!stk.empty()) stk.pop();
for (int i = n; i; i--) {
while (!stk.empty() && arr[i] >= arr[stk.top()]) stk.pop();
if (!stk.empty()) R[i] = stk.top();
else R[i] = n + 1;
stk.push(i);
}
for (int i = 1; i <= n; i++) {
if (pos[i].size() >= k) {
for (int j = 0; j + k - 1 < pos[i].size(); j++)
nxt[pos[i][j]] = pos[i][j + k - 1];
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
int l = i - L[i], r = R[i] - 1 - max(nxt[i] - 1, i - 1);
if (l > 0 && r > 0) ans += l * r;
}
cout << ans << "\n";
}
signed main() {
// freopen("1.in", "r", stdin);
// freopen("1.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 12052kb
input:
2 5 2 1 3 3 2 2 4 3 1 4 2 1
output:
7 0
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 38ms
memory: 50872kb
input:
1 1000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
500000500000
result:
ok single line: '500000500000'
Test #3:
score: -100
Wrong Answer
time: 66ms
memory: 9716kb
input:
158921 1 1 1 2 1 1 1 2 2 1 1 2 1 1 2 2 2 1 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 3 1 1 1 1 3 2 1 1 1 3 3 1 1 1 3 1 1 1 2 3 2 1 1 2 3 3 1 1 2 3 1 1 1 3 3 2 1 1 3 3 3 1 1 3 3 1 1 2 1 3 2 1 2 1 3 3 1 2 1 3 1 1 2 2 3 2 1 2 2 3 3 1 2 2 3 1 1 2 3 3 2 1 2 3 3 3 1 2 3 3 1 1 3 1 3 2 1 3 1 3 3 1 3 1 3 1 1 3 2 3 2...
output:
1 3 1 2 0 3 0 3 1 6 3 1 4 1 0 4 1 0 4 0 0 4 1 0 3 0 0 4 0 0 4 0 0 4 1 0 6 1 0 6 1 0 5 0 0 6 2 0 6 3 1 4 1 0 4 0 0 4 0 0 4 1 0 6 1 0 6 0 0 6 1 0 6 0 0 6 1 0 6 1 0 6 2 0 6 2 0 6 3 1 10 6 3 1 7 3 1 0 7 3 1 0 7 3 1 0 6 1 0 0 6 2 0 0 5 1 0 0 5 1 0 0 6 1 0 0 6 1 0 0 6 2 0 0 5 1 0 0 6 1 0 0 6 1 0 0 6 1 0 0...
result:
wrong answer 4th lines differ - expected: '3', found: '2'