# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
785340 |
2023-07-17T08:35:09 Z |
lollipop |
Horses (IOI15_horses) |
C++17 |
|
455 ms |
61176 KB |
#include "horses.h"
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define int long long
#define pb push_back
#define s second
#define f first
#define pf push_front
#define inf 100000000000000000
#define bitebi __builtin_popcountll
#define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
#define YES cout <<"YES\n"
#define NO cout << "NO\n"
#define debug cout << "Here Fine" << endl ;
#define pr pair < int , int >
#define fbo find_by_order // returns iterator
#define ook order_of_key // returns strictly less numbers than key
using namespace std ;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const double Pi=acos(-1.0);
const double EPS=1E-8;
const int mod = 1000000007 ;
const int mod1 = 998244353 ;
const int N = 7e5 + 10 ;
const int MAXN = 1e9 + 10 ;
mt19937 R(time(0));
map < int , int > ma , ma1 ;
int nodex[ 4 * N ] ;
pair < int , int > nodey[ 4 * N ] ;
int x[ N ] , y[ N ] ;
void buildx( int v , int vl , int vr ){
if( vl == vr ){
nodex[ v ] = x[ vl - 1 ] ;
return ;
}
int vm = ( vl + vr ) / 2 ;
buildx( v + v , vl , vm ) ;
buildx( v + v + 1 , vm + 1 , vr ) ;
nodex[ v ] = ( nodex[ v + v ] * nodex[ v + v + 1 ] ) % mod ;
return ;
}
void updatex( int v , int vl , int vr , int pos , int val ){
if( vl == vr ){
nodex[ v ] = val ;
x[ pos - 1 ] = val ;
return ;
}
int vm = ( vl + vr ) / 2 ;
if( vm >= pos )updatex( v + v , vl , vm , pos , val ) ;
else updatex( v + v + 1 , vm + 1 , vr , pos , val ) ;
nodex[ v ] = ( nodex[ v + v ] * nodex[ v + v + 1 ] ) % mod ;
return ;
}
int getx( int v , int vl , int vr , int l , int r ){
if( l > r ) return 1 ;
if( vl == l && vr == r ){
return nodex[ v ] ;
}
int vm = ( vl + vr ) / 2 ;
int a = getx( v + v , vl , vm , l , min( r , vm ) ) ;
int b = getx( v + v + 1 , vm + 1 , vr , max( vm + 1 , l ) , r ) ;
return ( a * b ) % mod ;
}
// for y
void buildy( int v , int vl , int vr ){
if( vl == vr ){
nodey[ v ] = { y[ vl - 1 ] , vl - 1 } ;
return ;
}
int vm = ( vl + vr ) / 2 ;
buildy( v + v , vl , vm ) ;
buildy( v + v + 1 , vm + 1 , vr ) ;
nodey[ v ] = max( nodey[ v + v ] , nodey[ v + v + 1 ] ) ;
return ;
}
void updatey( int v , int vl , int vr , int pos , int val ){
if( vl == vr ){
nodey[ v ] = { val , vl - 1 } ;
y[ vl - 1 ] = val ;
return ;
}
int vm = ( vl + vr ) / 2 ;
if( vm >= pos ) updatey( v + v , vl , vm , pos , val ) ;
else updatey( v + v + 1 , vm + 1 , vr , pos , val ) ;
nodey[ v ] = max( nodey[ v + v ] , nodey[ v + v + 1 ] ) ;
return ;
}
pair < int , int > gety( int v , int vl , int vr , int l , int r ){
if( l > r ) return { 0 , 0 } ;
if( vl == l && vr == r ){
return nodey[ v ] ;
}
int vm = ( vl + vr ) / 2 ;
pair < int , int > a = gety( v + v , vl , vm , l , min( r , vm ) ) ;
pair < int , int > b = gety( v + v + 1 , vm + 1 , vr , max( vm + 1 , l ) , r ) ;
return max( a , b ) ;
}
int n ;
set < int > se ;
int pas(){
int ans = 1 ;
int mx = 0 , lst = n ;
int is_ok = n - 1 ;
for( auto yy : se ){
int X = -yy ;
pair < int , int > p = { 0 , 0 } ;
int l = X + 2 , r = lst ;
p = gety( 1 , 1 , n , l , r ) ;
if( p.f > mx ){
is_ok = p.s ;
}
mx = max( mx , p.f ) ;
if( X == -1 ) break ;
if( y[ X ] > mx ){
is_ok = X ;
}
mx = max( mx , y[ X ] ) ;
mx = mx * x[ X ] ;
if( mx > MAXN ) break ;
lst = X ;
}
ans = y[ is_ok ] * getx( 1 , 1 , n , 1 , is_ok + 1 ) ;
ans %= mod ;
return ans ;
}
signed init(signed N, signed X[], signed Y[]){
FOR( i , N ) x[ i ] = X[ i ] , y[ i ] = Y[ i ] ;
n = N ;
se.insert( 1 ) ;
FOR( i , N ){
if( x[ i ] != 1 ) se.insert( - i ) ;
}
buildx( 1 , 1 , n ) ;
buildy( 1 , 1 , n ) ;
return pas() ;
}
signed updateX(signed pos, signed val){
if( x[ pos ] != 1 ){
se.erase( se.find( - pos ) ) ;
}
if( val != 1 ) se.insert( - pos ) ;
updatex( 1 , 1 , n , pos + 1 , val ) ;
return pas() ;
}
signed updateY(signed pos, signed val){
updatey( 1 , 1 , n , pos + 1 , val ) ;
return pas() ;
}
//static char buffer[1024];
//static int currentChar = 0;
//static int charsNumber = 0;
//
//signed main() {
// signed N;
// cin >> N ;
//
// signed *X = (signed *)malloc(sizeof(int) * (unsigned int)N);
// signed *Y = (signed *)malloc(sizeof(int) * (unsigned int)N);
//
// for (int i = 0; i < N; i++) {
// cin >> X[ i ] ;
// }
//
// for (int i = 0; i < N; i++) {
// cin >> Y[ i ] ;
// }
//
// printf("%d\n", init(N, X, Y));
//
// int M;
// cin >> M ;
//
// for (int i = 0; i < M; i++) {
// int type;
// cin >> type ;
// int pos;
// cin >> pos ;
// int val;
// cin >> val ;
//
// if (type == 1) {
// printf("%d\n", updateX(pos, val));
// } else if (type == 2) {
// printf("%d\n", updateY(pos, val));
// }
// }
//
// return 0;
//}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:135:20: warning: declaration of 'N' shadows a global declaration [-Wshadow]
135 | signed init(signed N, signed X[], signed Y[]){
| ~~~~~~~^
horses.cpp:30:11: note: shadowed declaration is here
30 | const int N = 7e5 + 10 ;
| ^
horses.cpp:144:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
144 | return pas() ;
| ~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:152:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
152 | return pas() ;
| ~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:156:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
156 | return pas() ;
| ~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
488 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
173 ms |
61120 KB |
Output is correct |
2 |
Correct |
259 ms |
61168 KB |
Output is correct |
3 |
Correct |
217 ms |
61076 KB |
Output is correct |
4 |
Correct |
282 ms |
61168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
232 KB |
Output is correct |
4 |
Correct |
0 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 |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
50 ms |
36912 KB |
Output is correct |
34 |
Correct |
45 ms |
36892 KB |
Output is correct |
35 |
Correct |
163 ms |
60284 KB |
Output is correct |
36 |
Correct |
165 ms |
60292 KB |
Output is correct |
37 |
Correct |
86 ms |
36812 KB |
Output is correct |
38 |
Correct |
87 ms |
48764 KB |
Output is correct |
39 |
Correct |
38 ms |
36724 KB |
Output is correct |
40 |
Correct |
147 ms |
60248 KB |
Output is correct |
41 |
Correct |
46 ms |
36684 KB |
Output is correct |
42 |
Correct |
61 ms |
36800 KB |
Output is correct |
43 |
Correct |
133 ms |
60196 KB |
Output is correct |
44 |
Correct |
138 ms |
60072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
165 ms |
61148 KB |
Output is correct |
34 |
Correct |
250 ms |
61160 KB |
Output is correct |
35 |
Correct |
262 ms |
61144 KB |
Output is correct |
36 |
Correct |
275 ms |
61140 KB |
Output is correct |
37 |
Correct |
47 ms |
36812 KB |
Output is correct |
38 |
Correct |
46 ms |
36820 KB |
Output is correct |
39 |
Correct |
158 ms |
60436 KB |
Output is correct |
40 |
Correct |
150 ms |
60184 KB |
Output is correct |
41 |
Correct |
79 ms |
36908 KB |
Output is correct |
42 |
Correct |
86 ms |
48668 KB |
Output is correct |
43 |
Correct |
35 ms |
36652 KB |
Output is correct |
44 |
Correct |
134 ms |
60192 KB |
Output is correct |
45 |
Correct |
34 ms |
36820 KB |
Output is correct |
46 |
Correct |
62 ms |
36792 KB |
Output is correct |
47 |
Correct |
136 ms |
60148 KB |
Output is correct |
48 |
Correct |
131 ms |
60168 KB |
Output is correct |
49 |
Correct |
134 ms |
38732 KB |
Output is correct |
50 |
Correct |
97 ms |
38732 KB |
Output is correct |
51 |
Correct |
225 ms |
61176 KB |
Output is correct |
52 |
Correct |
179 ms |
61172 KB |
Output is correct |
53 |
Correct |
455 ms |
38652 KB |
Output is correct |
54 |
Correct |
173 ms |
51652 KB |
Output is correct |
55 |
Correct |
108 ms |
36972 KB |
Output is correct |
56 |
Correct |
189 ms |
61132 KB |
Output is correct |
57 |
Correct |
82 ms |
37596 KB |
Output is correct |
58 |
Correct |
370 ms |
37728 KB |
Output is correct |
59 |
Correct |
131 ms |
60120 KB |
Output is correct |