QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#259197 | #5459. Goose, goose, DUCK? | andyc_03 | WA | 1151ms | 122716kb | C++14 | 2.3kb | 2023-11-20 18:26:01 | 2023-11-20 18:26:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e6 + 5;
int n, k;
int a[maxn], gs[maxn];
vector <int> pos[maxn];
int tag[maxn << 2], cnt[maxn << 2], mn[maxn << 2];
void pushup(int now)
{
mn[now] = min(mn[now << 1], mn[now << 1 | 1]);
if (mn[now << 1] == mn[now << 1 | 1])
cnt[now] = cnt[now << 1] + cnt[now << 1 | 1];
if (mn[now << 1] < mn[now << 1 | 1])
cnt[now] = cnt[now << 1];
if (mn[now << 1] > mn[now << 1 | 1])
cnt[now] = cnt[now << 1 | 1];
}
void build(int now, int l, int r)
{
if (l == r) {
cnt[now] = 1;
return;
}
int mid = l + r >> 1;
build(now << 1, l, mid);
build(now << 1 | 1, mid + 1, r);
pushup(now);
}
void pushdown(int now)
{
if (!tag[now]) return;
tag[now << 1] += tag[now];
tag[now << 1 | 1] += tag[now];
mn[now << 1] += tag[now];
mn[now << 1 | 1] += tag[now];
tag[now] = 0;
return;
}
void modify(int now, int l, int r, int L, int R, int v)
{
// cerr << l << " " << r << " " << tag[now] << endl;
if (l >= L && r <= R) {
tag[now] += v;
mn[now] += v;
return;
}
int mid = l + r >> 1;
pushdown(now);
if (L <= mid) modify(now << 1, l, mid, L, R, v);
if (mid < R) modify(now << 1 | 1, mid + 1, r, L, R, v);
// cerr << mn[now << 1] << " " << mn[now << 1 | 1] << endl;
pushup(now);
// cerr << now << " " << l << " " << r << " " << mn[now << 1] << " " << mn[now << 1 | 1] << " " << mn[now] << endl;
}
int nowgs[maxn];
int main()
{
scanf("%d%d", &n, &k);
for (int i = 1; i <= 1e6; i++) pos[i].push_back(0);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
gs[a[i]]++;
pos[a[i]].push_back(i);
}
for (int i = 1; i <= 1e6; i++) pos[i].push_back(n + 1);
build(1, 1, n);
for (int i = 1; i <= 1e6; i++)
if (gs[i] >= k)
// cerr << pos[i][k + 1] - 1 << endl;
modify(1, 1, n, pos[i][k], pos[i][k + 1] - 1, 1);
// modify(1, 1, n, 1, n, 1);
ll ans = 0;
for (int i = 1; i <= n; i++) {
if (!mn[1]) ans += n - cnt[1];
else ans += n;
if (nowgs[a[i]] + k <= gs[a[i]])
modify(1, 1, n, pos[a[i]][nowgs[a[i]] + k], pos[a[i]][nowgs[a[i]] + k + 1] - 1, -1);
nowgs[a[i]]++;
if (nowgs[a[i]] + k <= gs[a[i]])
modify(1, 1, n, pos[a[i]][nowgs[a[i]] + k], pos[a[i]][nowgs[a[i]] + k + 1] - 1, 1);
}
printf("%lld\n", n * (n + 1) / 2 - ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 51ms
memory: 82740kb
input:
6 2 1 2 2 1 3 3
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 44ms
memory: 83392kb
input:
6 1 1 2 3 4 5 6
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 42ms
memory: 82624kb
input:
100 10 142826 764475 142826 986320 764475 142826 142826 986320 764475 986320 764475 764475 764475 142826 142826 986320 764475 986320 764475 764475 142826 764475 142826 764475 986320 986320 764475 142826 764475 764475 142826 764475 764475 986320 142826 142826 142826 142826 764475 986320 986320 764475...
output:
4309
result:
ok 1 number(s): "4309"
Test #4:
score: 0
Accepted
time: 45ms
memory: 83556kb
input:
1000 100 144044 144044 606320 144044 144044 653289 606320 606320 606320 144044 653289 606320 144044 606320 144044 653289 606320 653289 144044 144044 606320 606320 606320 144044 606320 653289 653289 144044 606320 606320 606320 606320 606320 606320 606320 606320 653289 606320 653289 606320 653289 6532...
output:
494331
result:
ok 1 number(s): "494331"
Test #5:
score: 0
Accepted
time: 50ms
memory: 83928kb
input:
1000 2 37158 712133 695735 352502 37158 111876 979836 322207 850 170255 712133 37158 68113 170255 269273 322207 644692 127744 575843 269273 352502 68113 166126 413274 111876 575843 704107 695735 37158 604776 127744 269273 166126 704107 850 111876 352502 979836 850 850 712133 850 979836 575843 704107...
output:
382010
result:
ok 1 number(s): "382010"
Test #6:
score: 0
Accepted
time: 55ms
memory: 83248kb
input:
1000 1 439144 11249 309118 842057 842057 938195 823723 842057 589439 914850 938195 455713 91595 938195 553566 761181 553566 70966 455713 439144 704849 11249 11249 236580 320993 933831 872377 589439 435476 558991 914850 690853 482410 690853 715546 155003 435476 155003 435476 435476 842057 236580 7096...
output:
341042
result:
ok 1 number(s): "341042"
Test #7:
score: 0
Accepted
time: 43ms
memory: 86188kb
input:
1000 1 675227 756097 647871 465683 473815 162625 396802 61313 758469 968915 283015 326083 86904 672294 145904 621859 346020 237440 669779 282692 626616 722910 999031 141389 440533 971280 807058 346648 405103 669779 463968 214284 50833 661085 826455 991362 984243 704592 426668 998421 949882 147122 72...
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: -100
Wrong Answer
time: 1151ms
memory: 122716kb
input:
1000000 1 420242 544222 171447 777913 987553 724009 569564 35971 931705 898245 672004 267555 967920 126950 627536 979230 592634 345070 437097 838283 124796 525563 988560 362647 502828 510728 538451 742569 327219 207978 943947 684879 278534 669721 356340 258535 85663 265714 956295 291196 419333 19692...
output:
-500363689984
result:
wrong answer 1st numbers differ - expected: '0', found: '-500363689984'