QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#619831 | #2448. Make Rounddog Happy | untitledtwo# | WA | 123ms | 13660kb | C++17 | 1.7kb | 2024-10-07 15:34:26 | 2024-10-07 15:34:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 600005;
typedef long long ll;
typedef pair<int, int> PR;
#define fi first
#define se second
#define PB push_back
#define MP make_pair
ll ans = 0;
int mx[MAXN], a[MAXN], dis[MAXN], Dis[MAXN], cnt[MAXN], n, K;
void solve(int l, int r) {
if (l == r) return;
int mid = (l + r) >> 1;
for (int i = mid; i >= l ; -- i) mx[i] = (i == mid ? a[i] : max(mx[i + 1], a[i]));
for (int i = mid + 1; i <= r ; ++ i) mx[i] = (i == mid + 1 ? a[i] : max(mx[i - 1], a[i]));
for (int i = mid + 1, nw = mid; i <= r ; ++ i) {
while (nw >= l && mx[nw] < mx[i]) -- nw;
ans += max(min(K - mx[r] + i + 1, mid) - max(nw + 1, dis[i]) + 1, 0);
}
for (int i = mid, nw = mid + 1; i >= l ; -- i) {
while (nw <= r && mx[nw] <= mx[i]) ++ nw;
ans += max(min(nw - 1, Dis[i]) - max(mx[l] + i - 1 - K, mid + 1) + 1, 0);
}
solve(l, mid);
solve(mid + 1, r);
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("a.in", "r", stdin);
#endif
int Case;
scanf("%d", &Case);
while (Case --) {
scanf("%d%d", &n, &K);
for (int i = 1; i <= n ; ++ i) scanf("%d", &a[i]);
for (int i = 1; i <= n ; ++ i) cnt[i] = 0;
for (int i = 1, l = 1, num = 0; i <= n ; ++ i) {
++ cnt[a[i]];
if (cnt[a[i]] == 2) ++ num;
while (num) {
if (cnt[a[l]] == 2) -- num;
-- cnt[a[l]], ++ l;
}
dis[i] = l;
}
for (int i = 1; i <= n ; ++ i) cnt[i] = 0;
for (int i = n, r = n, num = 0; i >= 1 ; -- i) {
++ cnt[a[i]];
if (cnt[a[i]] == 2) ++ num;
while (num) {
if (cnt[a[r]] == 2) -- num;
-- cnt[a[r]], -- r;
}
Dis[i] = r;
}
ans = 0;
for (int i = 1; i <= n ; ++ i)
if (a[i] - 1 <= K) ++ ans;
solve(1, n);
printf("%lld\n", ans);
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 123ms
memory: 13660kb
input:
13 10000 9950 8745 9998 467 7434 1964 9375 9997 48 8597 2568 3761 9498 1576 6348 4819 4870 9997 9043 8623 2147 8768 9555 9709 2657 5124 2631 3010 2249 2212 2997 9996 4320 796 5189 5556 5548 5290 2026 5555 187 9090 9149 908 8714 5238 3236 3986 5510 8571 3020 5118 2522 2465 384 9105 1342 8220 8291 672...
output:
165502 4 2314 2774 7380 181732 5 2332 2814 351 66020944 282378987 285690123
result:
wrong answer 1st lines differ - expected: '224745', found: '165502'