ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#197333 | #2854. 装箱问题 box | tkswls | 100 | 1311ms | 76632kb | C++11 | 1.0kb | 2023-11-11 11:32:54 | 2023-11-11 12:12:07 |
answer
#include<bits/stdc++.h>
using namespace std;
int n, m, a[1000006], ans;
multiset<int> s;
multiset<int>::iterator it;
struct node {
int l, r, maxn;
} b[4000006];
inline void build(int p, int l, int r) {
b[p].l = l, b[p].r = r;
b[p].maxn = m;
if (l == r) {
return;
}
build(2 * p, l, (l + r) >> 1);
build(2 * p + 1, ((l + r) >> 1) + 1, r);
}
inline void update(int p, int w) {
if (b[p].l == b[p].r) {
if (b[p].maxn == m) ans++;
b[p].maxn -= w;
return;
}
if (b[2 * p].maxn >= w) update(2 * p, w);
else update(2 * p + 1, w);
b[p].maxn = max(b[2 * p].maxn, b[2 * p + 1].maxn);
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s.insert(m);
}
int p;
for (int i = 1; i <= n; i++) {
it = s.lower_bound(a[i]);
p = *it;
if (p == m) ans++;
s.erase(it);
s.insert(p - a[i]);
}
cout << ans << " ";
ans = 0;
build(1, 1, n);
for (int i = 1; i <= n; i++) {
update(1, a[i]);
}
cout << ans;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 20
Accepted
time: 0ms
memory: 1352kb
input:
1000 1000000000 5132991 971854484 937970094 913030415 51397098 98152103 78159240 972139111 994249203...
output:
517 519
result:
ok single line: '517 519'
Test #2:
score: 20
Accepted
time: 0ms
memory: 1352kb
input:
1000 1000000 32768 4096 65536 4 1 32 32768 524288 4 4096 4096 512 262144 16 524288 4 64 16 32768 163...
output:
46 46
result:
ok single line: '46 46'
Test #3:
score: 20
Accepted
time: 31ms
memory: 5348kb
input:
50000 1000000000 32768 4096 67108864 4096 1024 32768 32 524288 4194304 4096 4096 524288 262144 16384...
output:
1813 1813
result:
ok single line: '1813 1813'
Test #4:
score: 20
Accepted
time: 85ms
memory: 9428kb
input:
100000 1000000000 5132991 971854484 937970094 913030415 51397098 98152103 78159240 972139111 9942492...
output:
50119 50195
result:
ok single line: '50119 50195'
Test #5:
score: 20
Accepted
time: 1195ms
memory: 76632kb
input:
1000000 1000000000 5132991 971854484 937970094 913030415 51397098 98152103 78159240 972139111 994249...
output:
500379 500828
result:
ok single line: '500379 500828'
Extra Test:
score: 0
Extra Test Passed