Submission #620777

# Submission time Handle Problem Language Result Execution time Memory
620777 2022-08-03T08:59:56 Z mdn2002 Horses (IOI15_horses) C++14
100 / 100
1326 ms 73764 KB
#include "horses.h"

#include<bits/stdc++.h>
using namespace std;
long long n , m , mod = 1e9 + 7 , x [500005] , y [500005] , tree [2000006];
pair < long long , long long > treemx [2000006];
set < int > vall;
void up ( int nod , int l , int r , int x , long long val )
{
    if ( x < l || r < x ) return;
    if ( l == r )
    {
        tree [nod] = val;
        return;
    }
    int mid = ( l + r ) / 2;
    up ( nod * 2 , l , mid , x , val );
    up ( nod * 2 + 1 , mid + 1 , r , x , val );
    tree [nod] = ( tree [ nod * 2 ] * tree [ nod * 2 + 1 ] ) % mod;
}
long long qr ( int nod , int l , int r , int x , int y )
{
    if ( y < l || r < x ) return 1;
    if ( x <= l && r <= y ) return tree [nod];
    int mid = ( l + r ) / 2;
    return ( qr ( nod * 2 , l , mid , x , y ) * qr ( nod * 2 + 1 , mid + 1 , r , x , y ) ) % mod;
}
void upmx ( int nod , int l , int r , int x , long long val )
{
    if ( x < l || r < x ) return;
    if ( l == r )
    {
        treemx [nod] = { val , l };
        return;
    }
    int mid = ( l + r ) / 2;
    upmx ( nod * 2 , l , mid , x , val );
    upmx ( nod * 2 + 1 , mid + 1 , r , x , val );
    treemx [nod] = max ( treemx [ nod * 2 ] , treemx [ nod * 2 + 1 ] );
}
pair < long long , long long > qrmx ( int nod , int l , int r , int x , int y )
{
    if ( y < l || r < x ) return { -1 , -1 };
    if ( x <= l && r <= y ) return treemx [nod];
    int mid = ( l + r ) / 2;
    return max ( qrmx ( nod * 2 , l , mid , x , y ) , qrmx ( nod * 2 + 1 , mid + 1 , r , x , y ) );
}
long long get ( )
{
    vector < int > ids , nig;

    ids . push_back ( n );

    if ( vall . size () )
    {
        set < int > :: iterator it = -- vall . end ();
        for ( it ; ; it -- )
        {
            ids . push_back ( * it );
            if ( it == vall . begin () ) break;
            if ( ids . size () >= 50 ) break;
        }
    }
    /*
    for ( int i = n - 1 ; i >= 0 ; i -- )
    {
        if ( x [i] > 1 ) ids . push_back ( i ) ;
    }
    */
    if ( ids [ ids . size () - 1 ] != 0 ) ids . push_back ( 0 );


    reverse ( ids . begin () , ids . end () );

    for ( int i = 0 ; i < ids . size () ; i ++ )
    {
        if ( i )
        {
            int id = qrmx ( 1 , 0 , n , ids [ i - 1 ] + 1 , ids [i] - 1 ) . second;
            if ( id != -1 ) nig . push_back ( id );
        }
        if ( i != ids . size () - 1 ) nig . push_back ( ids [i] );
    }

    long long bst = 0 , mul = 1;
    for ( int i = 1 ; i < nig . size () ; i ++ )
    {
        int id = nig [i];
        mul *= x [id];
        if ( mul > y [bst] )
        {
            mul = 1;
            bst = id;
            continue;
        }
        long long almul = mul * y [id];
        if ( almul > y [bst] )
        {
            mul = 1;
            bst = id;
        }
    }

    long long ans = qr ( 1 , 0 , n , 0 , bst );
    ans = ( ans * y [bst] ) % mod;
    return ans;
}

int init(int N, int X[], int Y[]) {

	n = N;
    for ( int i = 0 ; i < n ; i ++ )
    {
        x [i] = X [i];
        if ( x [i] > 1 ) vall . insert ( i );
        up ( 1 , 0 , n , i , x [i] );
    }
    for ( int i = 0 ; i < n ; i ++ )
    {
        y [i] = Y [i];
        upmx ( 1 , 0 , n , i , y [i] );
    }
    return get ();

}

int updateX(int pos, int val) {

	if ( x [pos] > 1 ) vall . erase ( vall . lower_bound ( pos ) );
    x [pos] = val;
    if ( x [pos] > 1 ) vall . insert ( pos );
    up ( 1 , 0 , n , pos , x [pos] );
	return get ();

}

int updateY(int pos, int val) {

	y [pos] = val;
    upmx ( 1 , 0 , n , pos , val );
	return get ();

}





Compilation message

horses.cpp: In function 'void up(int, int, int, int, long long int)':
horses.cpp:8:41: warning: declaration of 'x' shadows a global declaration [-Wshadow]
    8 | void up ( int nod , int l , int r , int x , long long val )
      |                                     ~~~~^
horses.cpp:5:35: note: shadowed declaration is here
    5 | long long n , m , mod = 1e9 + 7 , x [500005] , y [500005] , tree [2000006];
      |                                   ^
horses.cpp: In function 'long long int qr(int, int, int, int, int)':
horses.cpp:21:54: warning: declaration of 'y' shadows a global declaration [-Wshadow]
   21 | long long qr ( int nod , int l , int r , int x , int y )
      |                                                  ~~~~^
horses.cpp:5:48: note: shadowed declaration is here
    5 | long long n , m , mod = 1e9 + 7 , x [500005] , y [500005] , tree [2000006];
      |                                                ^
horses.cpp:21:46: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   21 | long long qr ( int nod , int l , int r , int x , int y )
      |                                          ~~~~^
horses.cpp:5:35: note: shadowed declaration is here
    5 | long long n , m , mod = 1e9 + 7 , x [500005] , y [500005] , tree [2000006];
      |                                   ^
horses.cpp: In function 'void upmx(int, int, int, int, long long int)':
horses.cpp:28:43: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   28 | void upmx ( int nod , int l , int r , int x , long long val )
      |                                       ~~~~^
horses.cpp:5:35: note: shadowed declaration is here
    5 | long long n , m , mod = 1e9 + 7 , x [500005] , y [500005] , tree [2000006];
      |                                   ^
horses.cpp: In function 'std::pair<long long int, long long int> qrmx(int, int, int, int, int)':
horses.cpp:41:77: warning: declaration of 'y' shadows a global declaration [-Wshadow]
   41 | pair < long long , long long > qrmx ( int nod , int l , int r , int x , int y )
      |                                                                         ~~~~^
horses.cpp:5:48: note: shadowed declaration is here
    5 | long long n , m , mod = 1e9 + 7 , x [500005] , y [500005] , tree [2000006];
      |                                                ^
horses.cpp:41:69: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   41 | pair < long long , long long > qrmx ( int nod , int l , int r , int x , int y )
      |                                                                 ~~~~^
horses.cpp:5:35: note: shadowed declaration is here
    5 | long long n , m , mod = 1e9 + 7 , x [500005] , y [500005] , tree [2000006];
      |                                   ^
horses.cpp: In function 'long long int get()':
horses.cpp:52:23: warning: conversion from 'long long int' to 'std::vector<int>::value_type' {aka 'int'} may change value [-Wconversion]
   52 |     ids . push_back ( n );
      |                       ^
horses.cpp:57:15: warning: statement has no effect [-Wunused-value]
   57 |         for ( it ; ; it -- )
      |               ^~
horses.cpp:75:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for ( int i = 0 ; i < ids . size () ; i ++ )
      |                       ~~^~~~~~~~~~~~~~~
horses.cpp:79:37: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   79 |             int id = qrmx ( 1 , 0 , n , ids [ i - 1 ] + 1 , ids [i] - 1 ) . second;
      |                                     ^
horses.cpp:79:77: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   79 |             int id = qrmx ( 1 , 0 , n , ids [ i - 1 ] + 1 , ids [i] - 1 ) . second;
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
horses.cpp:82:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         if ( i != ids . size () - 1 ) nig . push_back ( ids [i] );
      |              ~~^~~~~~~~~~~~~~~~~~~~
horses.cpp:86:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for ( int i = 1 ; i < nig . size () ; i ++ )
      |                       ~~^~~~~~~~~~~~~~~
horses.cpp:104:34: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  104 |     long long ans = qr ( 1 , 0 , n , 0 , bst );
      |                                  ^
horses.cpp:104:42: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  104 |     long long ans = qr ( 1 , 0 , n , 0 , bst );
      |                                          ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:116:22: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  116 |         up ( 1 , 0 , n , i , x [i] );
      |                      ^
horses.cpp:121:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  121 |         upmx ( 1 , 0 , n , i , y [i] );
      |                        ^
horses.cpp:123:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  123 |     return get ();
      |            ~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:132:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  132 |     up ( 1 , 0 , n , pos , x [pos] );
      |                  ^
horses.cpp:133:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  133 |  return get ();
      |         ~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:140:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  140 |     upmx ( 1 , 0 , n , pos , val );
      |                    ^
horses.cpp:141:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  141 |  return get ();
      |         ~~~~^~
# 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 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 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 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 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 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 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 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 8 ms 340 KB Output is correct
24 Correct 5 ms 340 KB Output is correct
25 Correct 7 ms 340 KB Output is correct
26 Correct 6 ms 340 KB Output is correct
27 Correct 6 ms 340 KB Output is correct
28 Correct 6 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 7 ms 456 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 5 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1241 ms 61252 KB Output is correct
2 Correct 1252 ms 61992 KB Output is correct
3 Correct 1231 ms 62180 KB Output is correct
4 Correct 1309 ms 62152 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 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 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 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 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
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 8 ms 340 KB Output is correct
24 Correct 6 ms 424 KB Output is correct
25 Correct 6 ms 340 KB Output is correct
26 Correct 5 ms 452 KB Output is correct
27 Correct 7 ms 340 KB Output is correct
28 Correct 5 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 5 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 5 ms 416 KB Output is correct
33 Correct 493 ms 36784 KB Output is correct
34 Correct 352 ms 36812 KB Output is correct
35 Correct 425 ms 60268 KB Output is correct
36 Correct 488 ms 60216 KB Output is correct
37 Correct 382 ms 36876 KB Output is correct
38 Correct 388 ms 48652 KB Output is correct
39 Correct 276 ms 36684 KB Output is correct
40 Correct 455 ms 60236 KB Output is correct
41 Correct 311 ms 36764 KB Output is correct
42 Correct 322 ms 36696 KB Output is correct
43 Correct 349 ms 60108 KB Output is correct
44 Correct 345 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 212 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 232 KB Output is correct
22 Correct 2 ms 212 KB Output is correct
23 Correct 7 ms 416 KB Output is correct
24 Correct 5 ms 340 KB Output is correct
25 Correct 6 ms 452 KB Output is correct
26 Correct 6 ms 340 KB Output is correct
27 Correct 6 ms 340 KB Output is correct
28 Correct 6 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 6 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 5 ms 340 KB Output is correct
33 Correct 1060 ms 61076 KB Output is correct
34 Correct 1220 ms 73764 KB Output is correct
35 Correct 1202 ms 65012 KB Output is correct
36 Correct 1193 ms 68784 KB Output is correct
37 Correct 367 ms 40812 KB Output is correct
38 Correct 314 ms 40752 KB Output is correct
39 Correct 434 ms 71028 KB Output is correct
40 Correct 429 ms 71016 KB Output is correct
41 Correct 371 ms 39012 KB Output is correct
42 Correct 340 ms 51696 KB Output is correct
43 Correct 236 ms 38648 KB Output is correct
44 Correct 394 ms 66112 KB Output is correct
45 Correct 261 ms 38736 KB Output is correct
46 Correct 276 ms 38836 KB Output is correct
47 Correct 377 ms 66452 KB Output is correct
48 Correct 327 ms 66460 KB Output is correct
49 Correct 1326 ms 43876 KB Output is correct
50 Correct 988 ms 43876 KB Output is correct
51 Correct 1127 ms 72928 KB Output is correct
52 Correct 1054 ms 72504 KB Output is correct
53 Correct 1260 ms 42204 KB Output is correct
54 Correct 1058 ms 55812 KB Output is correct
55 Correct 381 ms 39812 KB Output is correct
56 Correct 1069 ms 67980 KB Output is correct
57 Correct 554 ms 40512 KB Output is correct
58 Correct 732 ms 40940 KB Output is correct
59 Correct 332 ms 66692 KB Output is correct