# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
209582 |
2020-03-14T17:39:06 Z |
Lawliet |
Boat (APIO16_boat) |
C++14 |
|
1238 ms |
524292 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
const int MAXN = 510;
const int MAXV = 1000000000;
const int MOD = 1000000007;
class SparseSegmentTree
{
public:
void create()
{
e.push_back( 0 );
d.push_back( 0 );
sum.push_back( 0 );
}
int getLeft(int node)
{
if( e[node] == 0 )
{
e[node] = ++cntNode;
create();
}
return e[node];
}
int getRight(int node)
{
if( d[node] == 0 )
{
d[node] = ++cntNode;
create();
}
return d[node];
}
void update(int node, int l, int r, int i, int v)
{
if( i < l || r < i ) return;
if( l == r )
{
sum[node] += v;
sum[node] %= MOD;
return;
}
int m = ( l + r )/2;
if( i <= m ) update( getLeft(node) , l , m , i , v );
else update( getRight(node) , m + 1 , r , i , v );
sum[node] = sum[ e[node] ] + sum[ d[node] ];
sum[node] %= MOD;
}
int query(int node, int l, int r, int i, int j)
{
if( node == 0 ) return 0;
if( j < l || r < i ) return 0;
if( i <= l && r <= j ) return sum[node];
int m = ( l + r )/2;
int sumLeft = query( e[node] , l , m , i , j );
int sumRight = query( d[node] , m + 1 , r , i , j );
return ( sumLeft + sumRight )%MOD;
}
SparseSegmentTree() : cntNode(1) { create(); create(); }
private:
int cntNode;
vector< int > e, d;
vector< int > sum;
};
int n;
SparseSegmentTree SEG;
int main()
{
scanf("%d",&n);
SEG.update( 1 , 0 , MAXV , 0 , 1 );
for(int i = 1 ; i <= n ; i++)
{
int l, r;
scanf("%d %d",&l,&r);
vector< int > aux;
for(int j = l ; j <= r ; j++)
aux.push_back( SEG.query( 1 , 0 , MAXV , 0 , j - 1 ) );
for(int j = 0 ; j < aux.size() ; j++)
SEG.update( 1 , 0 , MAXV , j + l , aux[j] );
}
printf("%d\n",SEG.query( 1 , 0 , MAXV , 1 , MAXV ));
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:108:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0 ; j < aux.size() ; j++)
~~^~~~~~~~~~~~
boat.cpp:94:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
boat.cpp:101:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&l,&r);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
508 KB |
Output is correct |
7 |
Correct |
7 ms |
504 KB |
Output is correct |
8 |
Correct |
6 ms |
504 KB |
Output is correct |
9 |
Correct |
6 ms |
504 KB |
Output is correct |
10 |
Correct |
6 ms |
504 KB |
Output is correct |
11 |
Correct |
6 ms |
504 KB |
Output is correct |
12 |
Correct |
7 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
380 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
508 KB |
Output is correct |
7 |
Correct |
7 ms |
504 KB |
Output is correct |
8 |
Correct |
6 ms |
504 KB |
Output is correct |
9 |
Correct |
6 ms |
504 KB |
Output is correct |
10 |
Correct |
6 ms |
504 KB |
Output is correct |
11 |
Correct |
6 ms |
504 KB |
Output is correct |
12 |
Correct |
7 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
380 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
380 KB |
Output is correct |
21 |
Correct |
541 ms |
504 KB |
Output is correct |
22 |
Correct |
540 ms |
504 KB |
Output is correct |
23 |
Correct |
493 ms |
632 KB |
Output is correct |
24 |
Correct |
559 ms |
624 KB |
Output is correct |
25 |
Correct |
584 ms |
632 KB |
Output is correct |
26 |
Correct |
603 ms |
504 KB |
Output is correct |
27 |
Correct |
587 ms |
500 KB |
Output is correct |
28 |
Correct |
598 ms |
496 KB |
Output is correct |
29 |
Correct |
652 ms |
376 KB |
Output is correct |
30 |
Correct |
534 ms |
23792 KB |
Output is correct |
31 |
Correct |
525 ms |
23560 KB |
Output is correct |
32 |
Correct |
550 ms |
24072 KB |
Output is correct |
33 |
Correct |
520 ms |
23172 KB |
Output is correct |
34 |
Correct |
522 ms |
23560 KB |
Output is correct |
35 |
Correct |
492 ms |
22380 KB |
Output is correct |
36 |
Correct |
525 ms |
23040 KB |
Output is correct |
37 |
Correct |
538 ms |
23304 KB |
Output is correct |
38 |
Correct |
493 ms |
22540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1238 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
508 KB |
Output is correct |
7 |
Correct |
7 ms |
504 KB |
Output is correct |
8 |
Correct |
6 ms |
504 KB |
Output is correct |
9 |
Correct |
6 ms |
504 KB |
Output is correct |
10 |
Correct |
6 ms |
504 KB |
Output is correct |
11 |
Correct |
6 ms |
504 KB |
Output is correct |
12 |
Correct |
7 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
380 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
380 KB |
Output is correct |
21 |
Correct |
541 ms |
504 KB |
Output is correct |
22 |
Correct |
540 ms |
504 KB |
Output is correct |
23 |
Correct |
493 ms |
632 KB |
Output is correct |
24 |
Correct |
559 ms |
624 KB |
Output is correct |
25 |
Correct |
584 ms |
632 KB |
Output is correct |
26 |
Correct |
603 ms |
504 KB |
Output is correct |
27 |
Correct |
587 ms |
500 KB |
Output is correct |
28 |
Correct |
598 ms |
496 KB |
Output is correct |
29 |
Correct |
652 ms |
376 KB |
Output is correct |
30 |
Correct |
534 ms |
23792 KB |
Output is correct |
31 |
Correct |
525 ms |
23560 KB |
Output is correct |
32 |
Correct |
550 ms |
24072 KB |
Output is correct |
33 |
Correct |
520 ms |
23172 KB |
Output is correct |
34 |
Correct |
522 ms |
23560 KB |
Output is correct |
35 |
Correct |
492 ms |
22380 KB |
Output is correct |
36 |
Correct |
525 ms |
23040 KB |
Output is correct |
37 |
Correct |
538 ms |
23304 KB |
Output is correct |
38 |
Correct |
493 ms |
22540 KB |
Output is correct |
39 |
Runtime error |
1238 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
40 |
Halted |
0 ms |
0 KB |
- |