#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
const int N = 1 << 19;
const int mod = 1e9 + 7;
struct node{
double log;
long long va;
node() : log( 0 ), va( 1 ) { }
node( double log, long long va ) : log( log ), va( va ) { }
friend node operator+( const node &a, const node &b ) {
node ret;
ret.log = a.log + b.log;
ret.va = ( a.va * b.va ) % mod;
return ret;
}
friend bool operator<( const node &a, const node &b ) {
return make_pair( a.log, a.va ) < make_pair( b.log, b.va );
}
} seg[N<<1], lz[N<<1];
int n, x[N], y[N];
node a[N];
void build( int l = 1, int r = n, int now = 1 ) {
if( l == r ) return void( seg[now] = a[l-1] );
int mid = ( l + r ) >> 1;
build( l, mid, now << 1 ), build( mid + 1, r, now << 1 | 1 );
seg[now] = seg[now<<1] < seg[now<<1|1] ? seg[now<<1|1] : seg[now<<1];
return ;
}
void push( int now, int l, int r ) {
seg[now] = seg[now] + lz[now];
if( l != r ) {
lz[now<<1] = lz[now<<1] + lz[now];
lz[now<<1|1] = lz[now<<1|1] + lz[now];
}
lz[now] = node( 0, 1 );
return ;
}
void update( int ll, int rr, node k, int l = 1, int r = n, int now = 1 ) {
push( now, l, r );
if( l > rr || r < ll ) return ;
if( l >= ll && r <= rr ) {
lz[now] = lz[now] + k;
push( now, l, r );
return ;
}
int mid = ( l + r ) >> 1;
update( ll, rr, k, l, mid, now << 1 ), update( ll, rr, k, mid + 1, r, now << 1 | 1 );
seg[now] = seg[now<<1] < seg[now<<1|1] ? seg[now<<1|1] : seg[now<<1];
}
int init( int N, int X[], int Y[] ) {
n = N;
node cul( 0, 1 );
for( int i = 0 ; i < n ; i++ ) {
x[i] = X[i], y[i] = Y[i];
cul = cul + node( ( double )log2( x[i] ), x[i] );
a[i] = cul + node( ( double )log2( y[i] ), y[i] );
}
build();
return seg[1].va;
}
long long modpower( long long base, long long power ) {
long long ret = 1;
for( ; power ; power >>= 1 ) {
if( power & 1 ) ret = ( ret * base ) % mod;
base = ( base * base ) % mod;
}
return ret;
}
int updateX( int pos, int val ) {
double ll = ( double )log2( val ) - ( double )log2( x[pos] );
long long vc = ( long long )( 1ll * val * modpower( x[pos], mod - 2 ) ) % mod;
x[pos] = val;
update( pos + 1, n, node( ll, vc ) );
return seg[1].va;
}
int updateY( int pos, int val ) {
double ll = ( double )log2( val ) - ( double )log2( y[pos] );
long long vc = ( long long )( 1ll * val * modpower( y[pos], mod - 2 ) ) % mod;
y[pos] = val;
update( pos + 1, pos + 1, node( ll, vc ) );
return seg[1].va;
}
// int main()
// {
// int n, m, x[N], y[N];
// scanf("%d %d",&n,&m);
// for( int i = 0 ; i < n ; i++ ) scanf("%d",&x[i]);
// for( int i = 0 ; i < n ; i++ ) scanf("%d",&y[i]);
// cout << init( n, x, y );
// }
Compilation message
horses.cpp: In constructor 'node::node(double, long long int)':
horses.cpp:13:38: warning: declaration of 'va' shadows a member of 'node' [-Wshadow]
node( double log, long long va ) : log( log ), va( va ) { }
^
horses.cpp:11:15: note: shadowed declaration is here
long long va;
^~
horses.cpp:13:38: warning: declaration of 'log' shadows a member of 'node' [-Wshadow]
node( double log, long long va ) : log( log ), va( va ) { }
^
horses.cpp:10:12: note: shadowed declaration is here
double log;
^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:59:35: warning: declaration of 'N' shadows a global declaration [-Wshadow]
int init( int N, int X[], int Y[] ) {
^
horses.cpp:6:11: note: shadowed declaration is here
const int N = 1 << 19;
^
horses.cpp:68:19: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return seg[1].va;
~~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:85:19: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return seg[1].va;
~~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:93:19: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return seg[1].va;
~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
41464 KB |
Output is correct |
2 |
Correct |
40 ms |
41336 KB |
Output is correct |
3 |
Correct |
33 ms |
41336 KB |
Output is correct |
4 |
Correct |
35 ms |
41344 KB |
Output is correct |
5 |
Correct |
41 ms |
41592 KB |
Output is correct |
6 |
Correct |
39 ms |
41316 KB |
Output is correct |
7 |
Correct |
40 ms |
41340 KB |
Output is correct |
8 |
Correct |
41 ms |
41360 KB |
Output is correct |
9 |
Correct |
34 ms |
41336 KB |
Output is correct |
10 |
Correct |
39 ms |
41464 KB |
Output is correct |
11 |
Correct |
37 ms |
41336 KB |
Output is correct |
12 |
Correct |
37 ms |
41336 KB |
Output is correct |
13 |
Correct |
38 ms |
41344 KB |
Output is correct |
14 |
Correct |
37 ms |
41336 KB |
Output is correct |
15 |
Correct |
36 ms |
41344 KB |
Output is correct |
16 |
Correct |
36 ms |
41336 KB |
Output is correct |
17 |
Correct |
38 ms |
41472 KB |
Output is correct |
18 |
Correct |
37 ms |
41340 KB |
Output is correct |
19 |
Correct |
36 ms |
41336 KB |
Output is correct |
20 |
Correct |
36 ms |
41468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
41344 KB |
Output is correct |
2 |
Correct |
35 ms |
41340 KB |
Output is correct |
3 |
Correct |
36 ms |
41376 KB |
Output is correct |
4 |
Correct |
37 ms |
41336 KB |
Output is correct |
5 |
Correct |
36 ms |
41368 KB |
Output is correct |
6 |
Correct |
34 ms |
41336 KB |
Output is correct |
7 |
Correct |
36 ms |
41464 KB |
Output is correct |
8 |
Correct |
38 ms |
41348 KB |
Output is correct |
9 |
Correct |
37 ms |
41336 KB |
Output is correct |
10 |
Correct |
36 ms |
41336 KB |
Output is correct |
11 |
Correct |
35 ms |
41464 KB |
Output is correct |
12 |
Correct |
34 ms |
41336 KB |
Output is correct |
13 |
Correct |
37 ms |
41344 KB |
Output is correct |
14 |
Correct |
37 ms |
41464 KB |
Output is correct |
15 |
Correct |
40 ms |
41336 KB |
Output is correct |
16 |
Correct |
38 ms |
41336 KB |
Output is correct |
17 |
Correct |
36 ms |
41308 KB |
Output is correct |
18 |
Correct |
35 ms |
41336 KB |
Output is correct |
19 |
Correct |
35 ms |
41432 KB |
Output is correct |
20 |
Correct |
35 ms |
41456 KB |
Output is correct |
21 |
Correct |
41 ms |
41340 KB |
Output is correct |
22 |
Correct |
35 ms |
41336 KB |
Output is correct |
23 |
Correct |
35 ms |
41464 KB |
Output is correct |
24 |
Correct |
35 ms |
41436 KB |
Output is correct |
25 |
Correct |
37 ms |
41456 KB |
Output is correct |
26 |
Correct |
40 ms |
41436 KB |
Output is correct |
27 |
Correct |
37 ms |
41464 KB |
Output is correct |
28 |
Correct |
36 ms |
41472 KB |
Output is correct |
29 |
Correct |
42 ms |
41336 KB |
Output is correct |
30 |
Correct |
34 ms |
41464 KB |
Output is correct |
31 |
Correct |
35 ms |
41464 KB |
Output is correct |
32 |
Correct |
44 ms |
41464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
54024 KB |
Output is correct |
2 |
Correct |
320 ms |
62756 KB |
Output is correct |
3 |
Correct |
300 ms |
54008 KB |
Output is correct |
4 |
Correct |
309 ms |
57988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
41336 KB |
Output is correct |
2 |
Correct |
35 ms |
41344 KB |
Output is correct |
3 |
Correct |
38 ms |
41336 KB |
Output is correct |
4 |
Correct |
43 ms |
41336 KB |
Output is correct |
5 |
Correct |
36 ms |
41336 KB |
Output is correct |
6 |
Correct |
39 ms |
41500 KB |
Output is correct |
7 |
Correct |
35 ms |
41336 KB |
Output is correct |
8 |
Correct |
33 ms |
41336 KB |
Output is correct |
9 |
Correct |
36 ms |
41336 KB |
Output is correct |
10 |
Correct |
35 ms |
41336 KB |
Output is correct |
11 |
Correct |
33 ms |
41328 KB |
Output is correct |
12 |
Correct |
34 ms |
41340 KB |
Output is correct |
13 |
Correct |
35 ms |
41344 KB |
Output is correct |
14 |
Correct |
38 ms |
41336 KB |
Output is correct |
15 |
Correct |
34 ms |
41336 KB |
Output is correct |
16 |
Correct |
35 ms |
41336 KB |
Output is correct |
17 |
Correct |
34 ms |
41336 KB |
Output is correct |
18 |
Correct |
41 ms |
41464 KB |
Output is correct |
19 |
Correct |
36 ms |
41436 KB |
Output is correct |
20 |
Correct |
34 ms |
41336 KB |
Output is correct |
21 |
Correct |
35 ms |
41328 KB |
Output is correct |
22 |
Correct |
42 ms |
41312 KB |
Output is correct |
23 |
Correct |
34 ms |
41472 KB |
Output is correct |
24 |
Correct |
36 ms |
41448 KB |
Output is correct |
25 |
Correct |
39 ms |
41464 KB |
Output is correct |
26 |
Correct |
36 ms |
41464 KB |
Output is correct |
27 |
Correct |
36 ms |
41464 KB |
Output is correct |
28 |
Correct |
42 ms |
41464 KB |
Output is correct |
29 |
Correct |
41 ms |
41344 KB |
Output is correct |
30 |
Correct |
36 ms |
41464 KB |
Output is correct |
31 |
Correct |
36 ms |
41464 KB |
Output is correct |
32 |
Correct |
38 ms |
41436 KB |
Output is correct |
33 |
Correct |
103 ms |
53196 KB |
Output is correct |
34 |
Correct |
108 ms |
53240 KB |
Output is correct |
35 |
Correct |
121 ms |
60152 KB |
Output is correct |
36 |
Correct |
119 ms |
60152 KB |
Output is correct |
37 |
Correct |
82 ms |
51448 KB |
Output is correct |
38 |
Correct |
85 ms |
52344 KB |
Output is correct |
39 |
Correct |
88 ms |
51344 KB |
Output is correct |
40 |
Correct |
119 ms |
55160 KB |
Output is correct |
41 |
Correct |
90 ms |
51340 KB |
Output is correct |
42 |
Correct |
89 ms |
51448 KB |
Output is correct |
43 |
Correct |
108 ms |
55644 KB |
Output is correct |
44 |
Correct |
113 ms |
55644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
41336 KB |
Output is correct |
2 |
Correct |
40 ms |
41320 KB |
Output is correct |
3 |
Correct |
39 ms |
41380 KB |
Output is correct |
4 |
Correct |
35 ms |
41336 KB |
Output is correct |
5 |
Correct |
36 ms |
41336 KB |
Output is correct |
6 |
Correct |
43 ms |
41336 KB |
Output is correct |
7 |
Correct |
36 ms |
41336 KB |
Output is correct |
8 |
Correct |
36 ms |
41300 KB |
Output is correct |
9 |
Correct |
40 ms |
41432 KB |
Output is correct |
10 |
Correct |
34 ms |
41304 KB |
Output is correct |
11 |
Correct |
36 ms |
41336 KB |
Output is correct |
12 |
Correct |
36 ms |
41408 KB |
Output is correct |
13 |
Correct |
34 ms |
41336 KB |
Output is correct |
14 |
Correct |
37 ms |
41436 KB |
Output is correct |
15 |
Correct |
34 ms |
41336 KB |
Output is correct |
16 |
Correct |
36 ms |
41328 KB |
Output is correct |
17 |
Correct |
36 ms |
41356 KB |
Output is correct |
18 |
Correct |
34 ms |
41372 KB |
Output is correct |
19 |
Correct |
39 ms |
41316 KB |
Output is correct |
20 |
Correct |
34 ms |
41336 KB |
Output is correct |
21 |
Correct |
36 ms |
41336 KB |
Output is correct |
22 |
Correct |
35 ms |
41416 KB |
Output is correct |
23 |
Correct |
43 ms |
41464 KB |
Output is correct |
24 |
Correct |
36 ms |
41428 KB |
Output is correct |
25 |
Correct |
41 ms |
41436 KB |
Output is correct |
26 |
Correct |
43 ms |
41464 KB |
Output is correct |
27 |
Correct |
38 ms |
41464 KB |
Output is correct |
28 |
Correct |
36 ms |
41424 KB |
Output is correct |
29 |
Correct |
34 ms |
41436 KB |
Output is correct |
30 |
Correct |
41 ms |
41376 KB |
Output is correct |
31 |
Correct |
35 ms |
41464 KB |
Output is correct |
32 |
Correct |
41 ms |
41464 KB |
Output is correct |
33 |
Correct |
163 ms |
54048 KB |
Output is correct |
34 |
Correct |
308 ms |
62816 KB |
Output is correct |
35 |
Correct |
256 ms |
54012 KB |
Output is correct |
36 |
Correct |
288 ms |
57848 KB |
Output is correct |
37 |
Correct |
114 ms |
53244 KB |
Output is correct |
38 |
Correct |
107 ms |
53212 KB |
Output is correct |
39 |
Correct |
124 ms |
60336 KB |
Output is correct |
40 |
Correct |
116 ms |
60344 KB |
Output is correct |
41 |
Correct |
92 ms |
51448 KB |
Output is correct |
42 |
Correct |
97 ms |
52416 KB |
Output is correct |
43 |
Correct |
77 ms |
51292 KB |
Output is correct |
44 |
Correct |
96 ms |
55160 KB |
Output is correct |
45 |
Correct |
79 ms |
51320 KB |
Output is correct |
46 |
Correct |
110 ms |
51448 KB |
Output is correct |
47 |
Correct |
86 ms |
55564 KB |
Output is correct |
48 |
Correct |
87 ms |
55672 KB |
Output is correct |
49 |
Correct |
296 ms |
55336 KB |
Output is correct |
50 |
Correct |
282 ms |
55260 KB |
Output is correct |
51 |
Correct |
187 ms |
62112 KB |
Output is correct |
52 |
Correct |
217 ms |
61540 KB |
Output is correct |
53 |
Correct |
333 ms |
53624 KB |
Output is correct |
54 |
Correct |
192 ms |
54136 KB |
Output is correct |
55 |
Correct |
151 ms |
52348 KB |
Output is correct |
56 |
Correct |
178 ms |
56952 KB |
Output is correct |
57 |
Correct |
207 ms |
52984 KB |
Output is correct |
58 |
Correct |
228 ms |
53496 KB |
Output is correct |
59 |
Correct |
78 ms |
55544 KB |
Output is correct |