답안 #985367

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
985367 2024-05-17T17:00:30 Z LucaIlie 말 (IOI15_horses) C++17
100 / 100
171 ms 62548 KB
#include <iostream>
#include <cmath>

using namespace std;

const int mod = 1e9 + 7;
#define nmax 500001

long long aint_rez[4 * nmax];

struct info{
    double val;
    int poz;
};

info aint[4 * nmax];
double lazy[4 * nmax];
int x[nmax], y[nmax];
double sp[nmax];
int n;


void init_aint_rez( int l, int r, int poz ) {
    if( l == r ) {
        aint_rez[poz] = x[l];
        return;
    }
    init_aint_rez( l, (l + r) / 2, 2 * poz );
    init_aint_rez( (l + r) / 2 + 1, r, 2 * poz + 1 );
    aint_rez[poz] = ( aint_rez[2 * poz] * aint_rez[2 * poz + 1] ) % mod;
}

void update_aint_rez( int l, int r, int lq, int val, int poz ) {
    if( lq < l || r < lq )
        return;
    if( l == r ) {
        aint_rez[poz] = val;
        return;
    }
    update_aint_rez( l, (l + r) / 2, lq, val, 2 * poz );
    update_aint_rez( (l + r) / 2 + 1, r, lq, val, 2 * poz + 1 );
    aint_rez[poz] = ( aint_rez[2 * poz] * aint_rez[2 * poz + 1] ) % mod;
}

long long query_aint_rez( int l, int r, int lq, int rq, int poz ) {
    if( r < lq || rq < l )
        return 1;
    if( lq <= l && r <= rq )
        return aint_rez[poz];
    return ( query_aint_rez( l, (l + r) / 2, lq, rq, 2 * poz ) * query_aint_rez( (l + r) / 2 + 1, r, lq, rq, 2 * poz + 1 ) ) % mod;
}

void afiseaza( int l, int r, int poz ) {
    cout << l << " " << r << " " << poz << "      "<< aint[poz].poz << " " << aint[poz].val << " " << lazy[poz] << "\n";
    if( l == r )
        return;
    afiseaza( l, (l + r) / 2, 2 * poz );
    afiseaza( (l + r) / 2 + 1, r, 2 * poz + 1 );
}

void init_aint( int l, int r, int poz ) {
    if( l == r ) {
        aint[poz].val = sp[l] + log2( y[l] );
        aint[poz].poz = l;
        return;
    }
    init_aint( l, (l + r) / 2, poz * 2 );
    init_aint( (l + r) / 2 + 1, r, poz * 2 + 1 );
    if( aint[2 * poz].val < aint[2 * poz + 1].val ) {
        aint[poz].val = aint[2 * poz + 1].val;
        aint[poz].poz = aint[2 * poz + 1].poz;
    } else{
        aint[poz].val = aint[2 * poz].val;
        aint[poz].poz = aint[2 * poz].poz;
    }
}

void push_lazy( int l, int r, int poz ) {
    aint[poz].val += lazy[poz];
    if( l < r ) {
        lazy[2 * poz] += lazy[poz];
        lazy[2 * poz + 1] += lazy[poz];
    }
    lazy[poz] = 0;
}

void update_aint( int l, int r, int ql, int qr, double val, int poz ) {
    push_lazy( l, r, poz );
    if( r < ql || qr < l )
        return;
    if( ql <= l && r <= qr ) {
        lazy[poz] = val;
    } else {
        update_aint( l, (l + r) / 2, ql, qr, val, poz * 2 );
        update_aint( (l + r) / 2 + 1, r, ql, qr, val, poz * 2 + 1 );
        if( aint[2 * poz].val < aint[2 * poz + 1].val ) {
            aint[poz].val = aint[2 * poz + 1].val;
            aint[poz].poz = aint[2 * poz + 1].poz;
        } else{
            aint[poz].val = aint[2 * poz].val;
            aint[poz].poz = aint[2 * poz].poz;
        }
    }
    push_lazy( l, r ,poz );
}

int init( int N, int X[], int Y[] ) {
    n = N;
    int i;
    for( i = 1; i <= n; i++ )
        x[i] = X[i - 1];
    for( i = 1; i <= n; i++ )
        y[i] = Y[i - 1];
    for( i = 1; i <= n; i++ )
        sp[i] = sp[i - 1] + log2( x[i] );
    init_aint_rez( 1, n, 1 );
    init_aint( 1, n, 1 );
    //afiseaza( 1, n, 1 );
    return (query_aint_rez( 1, n, 1, aint[1].poz, 1) * y[aint[1].poz] ) % mod;
}

int updateX( int poz, int val ) {
    poz++;
    update_aint( 1, n, poz, n, log2(val ) - log2( x[poz] ), 1 );
    update_aint_rez( 1, n, poz, val, 1 );
    x[poz] = val;
    //cout << aint[1].poz << "e ";
    //afiseaza( 1, n, 1 );
    return (query_aint_rez( 1, n, 1, aint[1].poz, 1) * y[aint[1].poz] ) % mod;
}

int updateY( int poz, int val ) {
    poz++;
    //cout << "\n" << log2(val ) - log2( y[poz] ) << "\n";
    update_aint( 1, n, poz, poz, log2(val ) - log2( y[poz] ), 1 );
    //afiseaza( 1, n, 1 );
    //cout << aint[1].poz << "e ";
    y[poz] = val;
    return (query_aint_rez( 1, n, 1, aint[1].poz, 1) * y[aint[1].poz] ) % mod;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:119:73: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  119 |     return (query_aint_rez( 1, n, 1, aint[1].poz, 1) * y[aint[1].poz] ) % mod;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:129:73: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  129 |     return (query_aint_rez( 1, n, 1, aint[1].poz, 1) * y[aint[1].poz] ) % mod;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:139:73: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  139 |     return (query_aint_rez( 1, n, 1, aint[1].poz, 1) * y[aint[1].poz] ) % mod;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8536 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8536 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8536 KB Output is correct
19 Correct 2 ms 8536 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8536 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8536 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8536 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8536 KB Output is correct
27 Correct 2 ms 8536 KB Output is correct
28 Correct 2 ms 8536 KB Output is correct
29 Correct 2 ms 8540 KB Output is correct
30 Correct 2 ms 8536 KB Output is correct
31 Correct 2 ms 8540 KB Output is correct
32 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 42256 KB Output is correct
2 Correct 171 ms 50020 KB Output is correct
3 Correct 132 ms 53776 KB Output is correct
4 Correct 158 ms 57684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8648 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8536 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 2 ms 8536 KB Output is correct
24 Correct 2 ms 8792 KB Output is correct
25 Correct 2 ms 8676 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8792 KB Output is correct
29 Correct 2 ms 8540 KB Output is correct
30 Correct 2 ms 8664 KB Output is correct
31 Correct 2 ms 8540 KB Output is correct
32 Correct 2 ms 8540 KB Output is correct
33 Correct 63 ms 53060 KB Output is correct
34 Correct 53 ms 53052 KB Output is correct
35 Correct 66 ms 52524 KB Output is correct
36 Correct 64 ms 52224 KB Output is correct
37 Correct 40 ms 51092 KB Output is correct
38 Correct 41 ms 44720 KB Output is correct
39 Correct 31 ms 43588 KB Output is correct
40 Correct 47 ms 47444 KB Output is correct
41 Correct 28 ms 44032 KB Output is correct
42 Correct 35 ms 43612 KB Output is correct
43 Correct 44 ms 47688 KB Output is correct
44 Correct 41 ms 47696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8656 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8536 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8536 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 2 ms 8536 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 2 ms 8540 KB Output is correct
30 Correct 2 ms 8540 KB Output is correct
31 Correct 2 ms 8540 KB Output is correct
32 Correct 2 ms 8540 KB Output is correct
33 Correct 86 ms 46400 KB Output is correct
34 Correct 156 ms 62548 KB Output is correct
35 Correct 130 ms 53652 KB Output is correct
36 Correct 157 ms 57680 KB Output is correct
37 Correct 54 ms 53076 KB Output is correct
38 Correct 57 ms 53072 KB Output is correct
39 Correct 71 ms 52544 KB Output is correct
40 Correct 64 ms 52308 KB Output is correct
41 Correct 38 ms 51280 KB Output is correct
42 Correct 41 ms 44684 KB Output is correct
43 Correct 32 ms 43616 KB Output is correct
44 Correct 47 ms 47440 KB Output is correct
45 Correct 28 ms 44124 KB Output is correct
46 Correct 30 ms 43576 KB Output is correct
47 Correct 41 ms 47696 KB Output is correct
48 Correct 45 ms 47984 KB Output is correct
49 Correct 158 ms 55120 KB Output is correct
50 Correct 141 ms 55100 KB Output is correct
51 Correct 134 ms 54496 KB Output is correct
52 Correct 121 ms 53732 KB Output is correct
53 Correct 140 ms 53344 KB Output is correct
54 Correct 117 ms 47684 KB Output is correct
55 Correct 94 ms 44604 KB Output is correct
56 Correct 122 ms 50732 KB Output is correct
57 Correct 77 ms 45684 KB Output is correct
58 Correct 97 ms 45648 KB Output is correct
59 Correct 40 ms 47800 KB Output is correct