QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#716696 | #9584. 顾影自怜 | PHarr | WA | 70ms | 112560kb | C++20 | 1.5kb | 2024-11-06 15:50:42 | 2024-11-06 15:50:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i32 = int32_t;
using i64 = long long;
using ui32 = unsigned int;
#define int i64
using vi = vector<int>;
void solve() {
int n, k;
cin >> n >> k;
vi a(n + 1);
for(int i = 1; i <= n; i ++)
cin >> a[i];
vector vis(n + 1, vi(1, 0));
for(int i = 1;i <= n; i ++)
vis[a[i]].push_back(i);
for(int i = 1; i <= n; i ++)
vis[i].push_back(n + 1);
vi lst(n + 1), nxt(n + 1, -1), ed(n + 1, -1);
for(int i = 1; i <= n; i ++) {
if(vis[i].size() - 2 < k) continue;
for(int l = 1, r = k; r + 1 < vis[i].size(); l ++, r ++) {
lst[vis[i][l]] = vis[i][l - 1];
ed[vis[i][l]] = vis[i][r];
nxt[vis[i][l]] = vis[i][r + 1];
}
}
vi L(n + 1);
stack<int> stk;
for(int i = 1; i <= n; i ++) {
while(not stk.empty() and a[stk.top()] <= a[i])
stk.pop();
if(stk.empty()) L[i] = 0;
else L[i] = stk.top();
stk.push(i);
}
vi R(n + 1);
stk = stack<int>();
for(int i = n; i >= 1; i --) {
while(not stk.empty() and a[stk.top()] <= a[i])
stk.pop();
if(stk.empty()) R[i] = n + 1;
else R[i] = stk.top();
stk.push(i);
}
int res = 0;
for(int i = 1; i <= n; i ++){
if(nxt[i] == -1) continue;
int l = i - max(lst[i], L[i]);
int r = min(nxt[i], R[i]) - ed[i];
res += l * r;
}
cout << res << "\n";
return ;
}
i32 main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int T;
cin >> T;
while(T --)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3672kb
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: -100
Wrong Answer
time: 70ms
memory: 112560kb
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:
1000000
result:
wrong answer 1st lines differ - expected: '500000500000', found: '1000000'