ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#204960 | #3643. B | LJ07 | 100 | 4683ms | 29084kb | C++11 | 2.9kb | 2024-06-16 11:04:38 | 2024-06-16 13:52:30 |
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define pb emplace_back
#define sz(a) int(a.size())
const int N = 2e5 + 5, M = 3 * N;
int n, m, k, l, a[N];
set<pair<int, int>> S;
vector<int> vec[N], disc, b;
#define mid ((L + R) >> 1)
#define Ls rt << 1, L, mid
#define Rs rt << 1 | 1, mid + 1, R
int tr[M << 2];
void upd(int p, int v, int rt = 1, int L = 1, int R = sz(disc)) {
if (L == R) {
tr[rt] = v;
return ;
}
p <= mid ? upd(p, v, Ls) : upd(p, v, Rs);
tr[rt] = max(tr[rt << 1], tr[rt << 1 | 1]);
}
int qry(int l, int r, int rt = 1, int L = 1, int R = sz(disc)) {
if (l <= L && R <= r) {
return tr[rt];
}
int res = 0;
if (l <= mid) {
res = max(res, qry(l, r, Ls));
}
if (r > mid) {
res = max(res, qry(l, r, Rs));
}
return res;
}
void build(int rt = 1, int L = 1, int R = sz(disc)) {
tr[rt] = 0;
if (L == R) {
return ;
}
build(Ls), build(Rs);
}
#undef mid
#undef Ls
#undef Rs
inline int askd(int x) {
return lower_bound(disc.begin(), disc.end(), x) - disc.begin() + 1;
}
inline int calc(int x) {
return x >= 1 ? (x - 1) / (k + 1) + 1 : 0;
}
inline int calc(set<pair<int, int>>::iterator it) {
return calc(it->second - it->first + 1 - ((it->first != 1) + (it->second != m)) * k);
}
void work() {
cin >> n >> m >> k >> l;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
disc.pb(a[i]), disc.pb(max(1, a[i] - k)), disc.pb(min(m, a[i] + k));
b.pb(a[i]);
}
sort(disc.begin(), disc.end());
disc.erase(unique(disc.begin(), disc.end()), disc.end());
sort(b.begin(), b.end());
b.erase(unique(b.begin(), b.end()), b.end());
for (int i = 1; i <= n; ++i) {
upd(askd(a[i]), qry(askd(max(1, a[i] - k)), askd(min(m, a[i] + k))) + 1);
}
int pre = 1, now = 0;
for (int v : b) {
vec[qry(askd(v), askd(v))].pb(v);
if (pre < v) {
now += calc(S.emplace(pre, v - 1).first);
}
pre = v + 1;
}
if (pre <= m) {
now += calc(S.emplace(pre, m).first);
}
LL ans = n;
for (int i = 1; i <= tr[1]; ++i) {
ans += now;
for (auto v : vec[i]) {
auto it = S.lower_bound(make_pair(v, 0));
int l = v, r = v;
if (it != S.begin() && prev(it)->second == v - 1) {
l = prev(it)->first, now -= calc(prev(it)), S.erase(prev(it));
}
if (it != S.end() && it->first == v + 1) {
r = it->second, now -= calc(it), S.erase(it);
}
now += calc(S.emplace(l, r).first);
}
}
ans += 1ll * (l - tr[1]) * calc(m);
cout << ans << '\n';
}
void clear() {
S.clear();
for (int i = 1; i <= tr[1]; ++i) {
vector<int>().swap(vec[i]);
}
if (sz(disc)) {
build();
}
vector<int>().swap(disc);
vector<int>().swap(b);
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int test;
for (cin >> test; test--; ) {
work(), clear();
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 109ms
memory: 5980kb
input:
20000 10 1000000000 1000000000 1000000000 226659035 250054074 546576995 203093961 170837339 20860008...
output:
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1...
result:
ok 20000 numbers
Test #2:
score: 0
Accepted
time: 472ms
memory: 27508kb
input:
1 200000 1000000000 1000000000 1000000000 992449362 651860722 269632286 716245558 965251943 31661828...
output:
1000000000
result:
ok 1 number(s): "1000000000"
Subtask #2:
score: 5
Accepted
Test #3:
score: 5
Accepted
time: 115ms
memory: 5984kb
input:
20000 10 1000000000 0 1000000000 246183521 96198515 305798977 625503123 211932925 163211461 15744794...
output:
1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 ...
result:
ok 20000 numbers
Test #4:
score: 0
Accepted
time: 326ms
memory: 21828kb
input:
1 200000 1000000000 0 1000000000 600021167 265035305 374864967 680233689 752439987 270740797 8326820...
output:
1000000000000000000
result:
ok 1 number(s): "1000000000000000000"
Subtask #3:
score: 10
Accepted
Test #5:
score: 10
Accepted
time: 119ms
memory: 5964kb
input:
200000 0 1000000000 3 1000000000 0 1000000000 3 1000000000 0 1000000000 3 1000000000 0 1000000000 3 ...
output:
250000000000000000 250000000000000000 250000000000000000 250000000000000000 250000000000000000 25000...
result:
ok 200000 numbers
Test #6:
score: 0
Accepted
time: 100ms
memory: 5964kb
input:
200000 0 1000000000 100 1000000000 0 1000000000 100 1000000000 0 1000000000 100 1000000000 0 1000000...
output:
9900991000000000 9900991000000000 9900991000000000 9900991000000000 9900991000000000 990099100000000...
result:
ok 200000 numbers
Test #7:
score: 0
Accepted
time: 113ms
memory: 5960kb
input:
200000 0 1000000000 100000 1000000000 0 1000000000 100000 1000000000 0 1000000000 100000 1000000000 ...
output:
10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 1000000000...
result:
ok 200000 numbers
Test #8:
score: 0
Accepted
time: 111ms
memory: 5964kb
input:
200000 0 1000000000 1000000 1000000000 0 1000000000 1000000 1000000000 0 1000000000 1000000 10000000...
output:
1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 10...
result:
ok 200000 numbers
Subtask #4:
score: 15
Accepted
Test #9:
score: 15
Accepted
time: 205ms
memory: 5984kb
input:
200000 1 1000000000 3 1000000000 813113588 1 1000000000 3 1000000000 162432886 1 1000000000 3 100000...
output:
250000000000000000 250000000000000000 250000000000000000 250000000000000000 250000000000000000 25000...
result:
ok 200000 numbers
Test #10:
score: 0
Accepted
time: 212ms
memory: 5984kb
input:
200000 1 1000000000 100 1000000000 65059908 1 1000000000 100 1000000000 780925625 1 1000000000 100 1...
output:
9900990999999999 9900990999999999 9900990999999999 9900990999999999 9900990999999999 990099100000000...
result:
ok 200000 numbers
Test #11:
score: 0
Accepted
time: 209ms
memory: 5984kb
input:
200000 1 1000000000 100000 1000000000 310169056 1 1000000000 100000 1000000000 130497483 1 100000000...
output:
10000000000000 9999999999999 10000000000000 10000000000000 10000000000000 10000000000000 10000000000...
result:
ok 200000 numbers
Test #12:
score: 0
Accepted
time: 213ms
memory: 5984kb
input:
200000 1 1000000000 1000000 1000000000 42196964 1 1000000000 1000000 1000000000 116096811 1 10000000...
output:
1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 10...
result:
ok 200000 numbers
Subtask #5:
score: 30
Accepted
Test #13:
score: 30
Accepted
time: 2ms
memory: 5976kb
input:
300 10 10 3 10 6 7 5 1 7 6 4 8 8 7 10 10 3 10 6 7 10 10 9 3 3 3 5 6 10 10 3 10 8 1 4 2 4 6 6 4 3 5 1...
output:
18 25 22 24 19 24 23 23 19 25 20 21 25 25 17 24 24 19 24 26 18 26 24 22 26 24 23 25 23 25 19 25 20 2...
result:
ok 300 numbers
Test #14:
score: 0
Accepted
time: 0ms
memory: 5976kb
input:
300 10 10 4 10 3 9 3 9 7 2 10 4 9 5 10 10 4 10 3 7 8 8 2 5 8 9 5 2 10 10 4 10 7 10 10 2 8 2 7 6 9 10...
output:
19 14 20 13 19 16 19 20 18 17 17 15 18 13 17 15 16 14 15 16 19 19 13 15 14 13 18 19 15 16 15 18 18 1...
result:
ok 300 numbers
Test #15:
score: 0
Accepted
time: 2ms
memory: 5984kb
input:
30 100 100 30 100 11 97 61 92 62 96 1 14 97 94 98 1 70 77 58 42 51 34 24 16 98 1 21 74 79 65 87 24 9...
output:
249 263 255 278 258 284 267 256 265 285 259 231 249 307 261 262 250 289 272 262 282 253 267 250 280 ...
result:
ok 30 numbers
Test #16:
score: 0
Accepted
time: 0ms
memory: 5984kb
input:
30 100 100 13 100 81 75 72 3 50 68 39 54 15 25 64 22 39 61 40 71 58 76 68 17 35 32 18 9 60 30 52 71 ...
output:
634 658 671 696 680 672 675 649 668 613 613 660 657 654 671 651 648 593 639 655 617 665 666 656 687 ...
result:
ok 30 numbers
Test #17:
score: 0
Accepted
time: 5ms
memory: 6124kb
input:
1 3000 3000 121 3000 1594 2003 742 1589 318 301 1116 1085 2883 180 2522 1755 1722 781 2082 712 887 2...
output:
70042
result:
ok 1 number(s): "70042"
Test #18:
score: 0
Accepted
time: 2ms
memory: 6120kb
input:
1 3000 3000 2987 3000 2467 1579 998 1618 1357 2165 1926 860 1375 1176 52 268 1860 2873 1418 2470 66 ...
output:
3000
result:
ok 1 number(s): "3000"
Subtask #6:
score: 35
Accepted
Test #19:
score: 35
Accepted
time: 121ms
memory: 5980kb
input:
20000 10 1000000000 3 1000000000 579022231 974160358 916238000 335408245 905609147 18568878 94851631...
output:
249999999999999997 249999999999999996 249999999999999997 249999999999999996 249999999999999996 24999...
result:
ok 20000 numbers
Test #20:
score: 0
Accepted
time: 117ms
memory: 5984kb
input:
20000 10 1000000000 4 1000000000 592826245 78674384 405780822 141131769 582921763 650893783 35034114...
output:
199999999999999996 199999999999999997 199999999999999997 199999999999999998 199999999999999996 19999...
result:
ok 20000 numbers
Test #21:
score: 0
Accepted
time: 161ms
memory: 5996kb
input:
2000 100 1000000000 30 1000000000 706959573 917853556 339926158 407774192 279323674 960270530 748240...
output:
32258064999999955 32258064999999953 32258064999999951 32258064999999957 32258064999999951 3225806499...
result:
ok 2000 numbers
Test #22:
score: 0
Accepted
time: 162ms
memory: 5996kb
input:
2000 100 1000000000 13 1000000000 467549977 585965482 521809854 595741967 458729064 95285208 2663221...
output:
71428571999999955 71428571999999955 71428571999999956 71428571999999950 71428571999999953 7142857199...
result:
ok 2000 numbers
Test #23:
score: 0
Accepted
time: 385ms
memory: 21680kb
input:
1 200000 1000000 121 1000000000 891005 278822 654128 505498 208457 970237 141411 104733 391594 92964...
output:
8196999698403
result:
ok 1 number(s): "8196999698403"
Test #24:
score: 0
Accepted
time: 375ms
memory: 27996kb
input:
1 200000 999976568 1210 1000000000 642090932 240890376 155277558 882428733 286350032 180672252 96799...
output:
825744999882269
result:
ok 1 number(s): "825744999882269"
Test #25:
score: 0
Accepted
time: 496ms
memory: 28560kb
input:
1 200000 999987679 1232131 1000000000 465561785 304303085 734834193 217572194 764029307 920399750 98...
output:
811999658121
result:
ok 1 number(s): "811999658121"
Test #26:
score: 0
Accepted
time: 551ms
memory: 29084kb
input:
1 200000 999576588 31031231 1000000000 349872441 576165215 659166910 621934286 226126614 746808809 6...
output:
32999613908
result:
ok 1 number(s): "32999613908"
Extra Test:
score: 0
Extra Test Passed