# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
480696 |
2021-10-17T20:43:16 Z |
Deepesson |
Sails (IOI07_sails) |
C++17 |
|
181 ms |
4380 KB |
#include <bits/stdc++.h>
#define MAX 205000
#define LSB(A) (A & (-A))
typedef std::pair<int,int> pii;
long long seq[MAX],ft[MAX];
void update(int k,int t){
while(k<MAX){
ft[k]+=t;
k+=LSB(k);
}
}
int query(int k){
int res=0;
while(k>0){
res+=ft[k];
k-=LSB(k);
}
return res;
}
void update_range(int l,int r,int t){
update(l,t);
update(r+1,-t);
}
void clean(){
memset(ft,0,sizeof(ft));
}
std::vector<pii> vec;
const int base = 150000;
bool solve(int M){
int cur=0;
for(int i=0;i!=vec.size();++i){
int inicio = base-vec[i].first;
cur=std::max(cur,inicio);
while(query(cur)==M){
++cur;
}
int fim = cur+vec[i].second-1;
if(fim>base)return false;
update_range(cur,fim,1);
}
return true;
}
int main()
{
for(int i=1;i!=MAX;++i){
seq[i]=i+seq[i-1];
}
int N;
std::cin>>N;
for(int i=0;i!=N;++i){
int H,K;
std::cin>>H>>K;
vec.push_back({H,K});
}
std::sort(vec.begin(),vec.end());
std::reverse(vec.begin(),vec.end());
{
int l=1,r=MAX;
while(l<r){
int m = (l+r)/2;
clean();
if(solve(m)){
r=m;
}else l=m+1;
}
clean();
solve(l);
}
long long val=0;
for(int i=0;i!=MAX;++i){
int u = query(i);
if(u>=1){
// printf("%d ",u);
val+=seq[query(i)-1];
}
}
// printf("\n");
std::cout<<val<<"\n";
}
Compilation message
sails.cpp: In function 'bool solve(int)':
sails.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i=0;i!=vec.size();++i){
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
3404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3500 KB |
Output is correct |
2 |
Incorrect |
5 ms |
3404 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
3404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
3404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
3528 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
3532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
63 ms |
3836 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
85 ms |
3924 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
160 ms |
4152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
181 ms |
4332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
160 ms |
4380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |