# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
764450 |
2023-06-23T12:14:34 Z |
Ahmed57 |
Boat (APIO16_boat) |
C++17 |
|
95 ms |
8228 KB |
#include <bits/stdc++.h>
using namespace std;
int z = 0;
long long bit[100001];
long long mod = 1000000007;
void add(long long e,long long v){
while(e<=z){
bit[e]+=v;
bit[e]%=mod;
e+=(e&-e);
}
}
long long sum(long long e){
long long res = 0;
while(e>=1){
res+=bit[e];
res%=mod;
e-=(e&-e);
}
return res;
}
int main(){
int n;
cin>>n;
map<long long,long long> comp,sav;
vector<pair<long long,long long>> v;
vector<long long> ans;
for(int i = 0;i<n;i++){
long long x,y;
cin>>x>>y;
v.push_back({x,y});
ans.push_back(x+1);
ans.push_back(x);
ans.push_back(x-1);
ans.push_back(y);
ans.push_back(y+1);
ans.push_back(y-1);
}
sort(ans.begin(),ans.end());
vector<pair<long long,long long>> all[n];
for(int i = 0;i<v.size();i++){
long long st = v[i].first;
while(st<=v[i].second){
int it = lower_bound(ans.begin(),ans.end(),st)-ans.begin();
all[i].push_back({st,ans[it]});
comp[st]++;comp[ans[it]]++;
st = ans[it]+1;
}
}
for(auto i:comp){
sav[i.first] = ++z;
}
long long fin = 0;
for(int i = n-1;i>=0;i--){
for(auto j:all[i]){
long long sz = ((((sum(z)-sum(sav[j.second])+1)%mod+mod)%mod)*(j.second-j.first+1))%mod;
fin+=sz;fin%=mod;
add(sav[j.first],sz);
}
}
cout<<fin<<endl;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i = 0;i<v.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Incorrect |
95 ms |
8228 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Incorrect |
95 ms |
8228 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |