# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
980998 |
2024-05-12T17:15:28 Z |
salmon |
Boat (APIO16_boat) |
C++14 |
|
585 ms |
524288 KB |
#include <bits/stdc++.h>
using namespace std;
int N;
pair<int,int> lst[510];
int a, b;
int mod = 1'000'000'007;
long long int st[510 * 4];
vector<pair<int,int>> num;
void build(int i, int s, int e){
st[i] = 0;
int m = (s + e)/2;
if(s != e){
build(i * 2, s, m);
build(i * 2 + 1, m + 1, e);
}
}
void update(int i, int s, int e, int in, int k){
st[i] += k;
st[i] %= mod;
if(s == e) return;
int m = (s + e)/2;
if(in <= m){
update(i * 2, s , m, in , k);
}
else{
update(i * 2 + 1, m + 1, e, in, k);
}
}
long long int query(int i, int s, int e, int S, int E){
if(S <= s && e <= E) return st[i];
int m = (s + e)/2;
long long int V = 0;
if(S <= m){
V += query(i * 2, s , m, S, E);
}
if(m < E){
V += query(i * 2 + 1, m + 1, e, S, E);
}
return V %= mod;
}
int main(){
scanf(" %d",&N);
for(int i = 1; i <= N; i++){
scanf(" %d",&a);
scanf(" %d",&b);
lst[i] = {a,b};
for(int j = a; j <= b; j++){
num.push_back({j,i});
}
}
sort(num.begin(),num.end());
build(1, 0 , N);
int it = 0;
update(1,0,N,0,1);
while(it < num.size()){
vector<int> v = {num[it].second};
int t = num[it].first;
it++;
while(it < num.size() && num[it].first == t){
v.push_back(num[it].second);
it++;
}
reverse(v.begin(),v.end());
for(int j : v){
update(1,0,N,j, query(1,0,N, 0, j - 1));
}
}
printf("%d",query(1,0,N, 0, N) - 1);
}
/*
2
1 2
2 3
*/
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:77:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | while(it < num.size()){
| ~~~^~~~~~~~~~~~
boat.cpp:82: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]
82 | while(it < num.size() && num[it].first == t){
| ~~~^~~~~~~~~~~~
boat.cpp:94:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
94 | printf("%d",query(1,0,N, 0, N) - 1);
| ~^ ~~~~~~~~~~~~~~~~~~~~~~
| | |
| int long long int
| %lld
boat.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf(" %d",&N);
| ~~~~~^~~~~~~~~~
boat.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf(" %d",&a);
| ~~~~~^~~~~~~~~~
boat.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf(" %d",&b);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
162 ms |
10440 KB |
Output is correct |
22 |
Correct |
159 ms |
10692 KB |
Output is correct |
23 |
Correct |
149 ms |
9668 KB |
Output is correct |
24 |
Correct |
164 ms |
10440 KB |
Output is correct |
25 |
Correct |
166 ms |
8904 KB |
Output is correct |
26 |
Correct |
180 ms |
9416 KB |
Output is correct |
27 |
Correct |
187 ms |
10716 KB |
Output is correct |
28 |
Correct |
179 ms |
8900 KB |
Output is correct |
29 |
Correct |
183 ms |
10440 KB |
Output is correct |
30 |
Correct |
144 ms |
9672 KB |
Output is correct |
31 |
Correct |
147 ms |
9160 KB |
Output is correct |
32 |
Correct |
141 ms |
8900 KB |
Output is correct |
33 |
Correct |
138 ms |
9672 KB |
Output is correct |
34 |
Correct |
141 ms |
9672 KB |
Output is correct |
35 |
Correct |
151 ms |
10440 KB |
Output is correct |
36 |
Correct |
155 ms |
10440 KB |
Output is correct |
37 |
Correct |
152 ms |
9928 KB |
Output is correct |
38 |
Correct |
145 ms |
9672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
585 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
162 ms |
10440 KB |
Output is correct |
22 |
Correct |
159 ms |
10692 KB |
Output is correct |
23 |
Correct |
149 ms |
9668 KB |
Output is correct |
24 |
Correct |
164 ms |
10440 KB |
Output is correct |
25 |
Correct |
166 ms |
8904 KB |
Output is correct |
26 |
Correct |
180 ms |
9416 KB |
Output is correct |
27 |
Correct |
187 ms |
10716 KB |
Output is correct |
28 |
Correct |
179 ms |
8900 KB |
Output is correct |
29 |
Correct |
183 ms |
10440 KB |
Output is correct |
30 |
Correct |
144 ms |
9672 KB |
Output is correct |
31 |
Correct |
147 ms |
9160 KB |
Output is correct |
32 |
Correct |
141 ms |
8900 KB |
Output is correct |
33 |
Correct |
138 ms |
9672 KB |
Output is correct |
34 |
Correct |
141 ms |
9672 KB |
Output is correct |
35 |
Correct |
151 ms |
10440 KB |
Output is correct |
36 |
Correct |
155 ms |
10440 KB |
Output is correct |
37 |
Correct |
152 ms |
9928 KB |
Output is correct |
38 |
Correct |
145 ms |
9672 KB |
Output is correct |
39 |
Runtime error |
585 ms |
524288 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |