# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
484937 |
2021-11-05T18:41:24 Z |
Bench0310 |
Hotel (CEOI11_hot) |
C++17 |
|
1841 ms |
96772 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=500005;
vector<int> tree(4*N,0);
vector<int> lazy(4*N,0);
void pull(int idx)
{
tree[idx]=max(tree[2*idx],tree[2*idx+1]);
}
void apply(int idx,int x)
{
tree[idx]+=x;
lazy[idx]+=x;
}
void push(int idx)
{
for(int i=0;i<2;i++) apply(2*idx+i,lazy[idx]);
lazy[idx]=0;
}
void update(int idx,int l,int r,int ql,int qr,int x)
{
if(ql>qr) return;
if(l==ql&&r==qr) apply(idx,x);
else
{
int m=(l+r)/2;
push(idx);
update(2*idx,l,m,ql,min(qr,m),x);
update(2*idx+1,m+1,r,max(ql,m+1),qr,x);
pull(idx);
}
}
int descend(int idx,int l,int r)
{
if(l==r) return l;
int m=(l+r)/2;
push(idx);
if(tree[2*idx]>=tree[2*idx+1]) return descend(2*idx,l,m);
else return descend(2*idx+1,m+1,r);
}
//void print(int idx,int l,int r)
//{
// if(l==r) cout << "[" << l << ": " << tree[idx] << "] ";
// else
// {
// int m=(l+r)/2;
// push(idx);
// print(2*idx,l,m);
// print(2*idx+1,m+1,r);
// }
//}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,o;
cin >> n >> m >> o;
vector<array<int,2>> ini(n+1,{0,0});
for(int i=1;i<=n;i++) cin >> ini[i][1] >> ini[i][0];
sort(ini.begin(),ini.end());
vector<int> p(n+1,0);
vector<int> c(n+2,0);
c[n+1]=(1<<30);
for(int i=1;i<=n;i++)
{
p[i]=ini[i][0];
c[i]=ini[i][1];
}
vector<bool> vis(n+1,0);
vector<int> v[n+1];
for(int i=1;i<=n;i++) v[i].push_back(0);
for(int i=0;i<m;i++)
{
int x,d;
cin >> x >> d;
int t=(lower_bound(p.begin(),p.end(),d)-p.begin());
if(t<=n) v[t].push_back(x);
}
for(int i=1;i<=n;i++) sort(v[i].begin(),v[i].end());
// cout << "c: ";
// for(int i=1;i<=n;i++) cout << c[i] << " ";
// cout << endl;
// cout << "opt:" << endl;
// for(int i=1;i<=n;i++)
// {
// cout << i << ": ";
// for(int x:v[i]) cout << x << " ";
// cout << endl;
// }
for(int i=1;i<=n;i++) update(1,1,n,i,i,v[i].back()-c[i]);
set<int> s;
for(int i=0;i<=n+1;i++) s.insert(i);
auto prv=[&](int x)->int
{
auto it=s.lower_bound(x);
return (*prev(it));
};
auto nxt=[&](int x)->int
{
auto it=s.lower_bound(x);
return (*it);
};
// auto state=[&]()
// {
// cout << "active: ";
// for(int x:s) cout << x << " ";
// cout << endl;
// cout << "tree: ";
// print(1,1,n);
// cout << endl;
// };
ll res=0;
while(o--)
{
int mx=tree[1];
if(mx<0) break;
res+=mx;
int t=descend(1,1,n);
// state();
// cout << "t=" << t << endl;
int d=(-v[t].back()+v[t][(int)v[t].size()-2]);
update(1,1,n,t,t,d);
v[t].pop_back();
int i=nxt(t);
// cout << "i=" << i << endl;
s.erase(i);
int r=nxt(i);
int l=prv(i);
update(1,1,n,l+1,i,c[i]-c[r]);
}
cout << res << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
15948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15908 KB |
Output is correct |
2 |
Correct |
7 ms |
15948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15948 KB |
Output is correct |
2 |
Correct |
8 ms |
15984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15948 KB |
Output is correct |
2 |
Correct |
11 ms |
15948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
17200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
20804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
24668 KB |
Output is correct |
2 |
Correct |
101 ms |
26056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
477 ms |
40636 KB |
Output is correct |
2 |
Correct |
141 ms |
31904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
631 ms |
65204 KB |
Output is correct |
2 |
Correct |
591 ms |
79624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
602 ms |
77156 KB |
Output is correct |
2 |
Correct |
1324 ms |
96772 KB |
Output is correct |
3 |
Correct |
1841 ms |
95252 KB |
Output is correct |