ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#197338 | #2854. 装箱问题 box | snow_trace | 100 | 1058ms | 53204kb | C++11 | 1.2kb | 2023-11-11 11:39:18 | 2023-11-11 12:12:27 |
answer
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[1000005];
struct node{
int l,r,mx;
}tree[4000005];
void push_up(int k){
tree[k].mx = max(tree[k<<1].mx,tree[k<<1|1].mx);
}void build(int k,int l,int r){
tree[k].l = l,tree[k].r = r;
if(l+1 == r){
tree[k].mx = m;return;
}build(k<<1,l,l+r>>1),build(k<<1|1,l+r>>1,r);push_up(k);
}int query(int k,int x){
if(tree[k].l+1 == tree[k].r)return tree[k].l;
if(x<=tree[k<<1].mx)return query(k<<1,x);
else return query(k<<1|1,x);
}void upd(int k,int pos,int add){
int l = tree[k].l,r = tree[k].r;
if(pos>=r or l>pos)return;
if(l+1 == r and l == pos){
tree[k].mx+=add;return;
}upd(k<<1,pos,add),upd(k<<1|1,pos,add);push_up(k);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1;i<=n;i++)cin >> a[i];
build(1,1,1+n);
int tot= 0,ans1 =0;
for(int i = 1;i<=n;i++){
int pos = query(1,a[i]);
if(pos>tot)++tot;upd(1,pos,-a[i]);
}ans1 = tot;
multiset<int>s;tot = 1;s.insert(m-a[1]);
for(int i = 2;i<=n;i++){
auto it= s.lower_bound(a[i]);
if(it == s.end()){
tot++;s.insert(m-a[i]);
}else{s.insert(*it-a[i]);
s.erase(it);
}
}cout << tot << " " << ans1<< endl;
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 20
Accepted
time: 0ms
memory: 1324kb
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: 1300kb
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: 18ms
memory: 3088kb
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: 66ms
memory: 7088kb
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: 974ms
memory: 53204kb
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