Submission #130360

# Submission time Handle Problem Language Result Execution time Memory
130360 2019-07-14T23:08:05 Z jovan_b Horses (IOI15_horses) C++17
100 / 100
512 ms 96512 KB
#include "horses.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

struct drvo{
    ld val;
    ld lazy;
    int prod;
    int lazyprod;
} seg[4000000];

ld x[1000005];
ld y[1000005];
ld xpref[1000005];
int u1[1000005];
int xprod[1000005];
int x1[1000005];

int n;

const int MOD = 1000000007;

int mul(int a, int b){
    return (1LL*a*b)%MOD;
}

ll pw(ll a, ll b){
    if(b == 0) return 1;
    ll res = pw(a, b/2);
    res = (res*res)%MOD;
    if(b%2) res = (res*a)%MOD;
    return res;
}

/*
ll pww(ld x){
    ll y = x;
    x -= y;
    ld res = pw(2, y);
    ld jos = pow(2, x);
    res *= jos;
    return round(res);
}*/

void seginit(int node, int l, int r){
    seg[node].lazyprod = 1;
    if(l == r){
        seg[node].val = xpref[l] + y[l];
        seg[node].prod = mul(xprod[l], u1[l]);
        return;
    }
    int mid = (l+r)/2;
    seginit(node*2, l, mid);
    seginit(node*2+1, mid+1, r);
    if(seg[node*2].val > seg[node*2+1].val){
        seg[node].val = seg[node*2].val;
        seg[node].prod = seg[node*2].prod;
    }
    else{
        seg[node].val = seg[node*2+1].val;
        seg[node].prod = seg[node*2+1].prod;
    }
}

void propagate(int node, int l, int r){
    seg[node].val += seg[node].lazy;
    seg[node].prod = mul(seg[node].prod, seg[node].lazyprod);
    if(l == r){
        seg[node].lazy = 0;
        seg[node].lazyprod = 1;
        return;
    }
    seg[node*2].lazy += seg[node].lazy;
    seg[node*2].lazyprod = mul(seg[node*2].lazyprod, seg[node].lazyprod);
    seg[node*2+1].lazy += seg[node].lazy;
    seg[node*2+1].lazyprod = mul(seg[node*2+1].lazyprod, seg[node].lazyprod);
    seg[node].lazy = 0;
    seg[node].lazyprod = 1;
}

void upd(int node, int l, int r, int tl, int tr, ld val, int prod){
    propagate(node, l, r);
    if(l > tr || tl > r) return;
    if(tl <= l && r <= tr){
        seg[node].lazy += val;
        seg[node].lazyprod = mul(seg[node].lazyprod, prod);
        propagate(node, l, r);
        return;
    }
    int mid = (l+r)/2;
    upd(node*2, l, mid, tl, tr, val, prod);
    upd(node*2+1, mid+1, r, tl, tr, val, prod);
    if(seg[node*2].val > seg[node*2+1].val){
        seg[node].val = seg[node*2].val;
        seg[node].prod = seg[node*2].prod;
    }
    else{
        seg[node].val = seg[node*2+1].val;
        seg[node].prod = seg[node*2+1].prod;
    }
}

int init(int N, int X[], int Y[]) {
    n = N;
    xprod[0] = 1;
    for(int i=0; i<N; i++){
        x[i+1] = log10l(X[i]);
        x1[i+1] = X[i];
        xpref[i+1] = x[i+1] + xpref[i];
        xprod[i+1] = mul(xprod[i], X[i]);
        y[i+1] = log10l(Y[i]);
        u1[i+1] = Y[i];
        //cout << xpref[i] << " " << y[i+1] << endl;
    }
    seginit(1, 1, n);
    //cout << seg[1].val << endl;
    return seg[1].prod;
}

int updateX(int pos, int val){
    pos++;
    ld g = x[pos];
    x[pos] = log10l(val);
    int f = x1[pos];
    x1[pos] = val;
    upd(1, 1, n, pos, n, x[pos]-g, mul(x1[pos], pw(f, MOD-2)));
	return seg[1].prod;
}

int updateY(int pos, int val) {
    pos++;
    ld g = y[pos];
    y[pos] = log10l(val);
    int f = u1[pos];
    u1[pos] = val;
    upd(1, 1, n, pos, pos, y[pos]-g, mul(u1[pos], pw(f, MOD-2)));
	return seg[1].prod;
}

Compilation message

horses.cpp: In function 'int mul(int, int)':
horses.cpp:28:21: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return (1LL*a*b)%MOD;
            ~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:130:51: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
     upd(1, 1, n, pos, n, x[pos]-g, mul(x1[pos], pw(f, MOD-2)));
                                                 ~~^~~~~~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:140:53: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
     upd(1, 1, n, pos, pos, y[pos]-g, mul(u1[pos], pw(f, MOD-2)));
                                                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 4 ms 632 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
25 Correct 4 ms 632 KB Output is correct
26 Correct 4 ms 536 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 4 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 316 ms 83996 KB Output is correct
2 Correct 455 ms 96436 KB Output is correct
3 Correct 427 ms 87664 KB Output is correct
4 Correct 434 ms 91780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 4 ms 504 KB Output is correct
25 Correct 4 ms 612 KB Output is correct
26 Correct 4 ms 508 KB Output is correct
27 Correct 4 ms 632 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 4 ms 540 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 632 KB Output is correct
33 Correct 177 ms 86904 KB Output is correct
34 Correct 175 ms 87036 KB Output is correct
35 Correct 172 ms 93816 KB Output is correct
36 Correct 174 ms 93816 KB Output is correct
37 Correct 173 ms 85112 KB Output is correct
38 Correct 152 ms 86088 KB Output is correct
39 Correct 165 ms 84984 KB Output is correct
40 Correct 168 ms 88952 KB Output is correct
41 Correct 165 ms 84984 KB Output is correct
42 Correct 164 ms 85112 KB Output is correct
43 Correct 150 ms 89304 KB Output is correct
44 Correct 150 ms 89252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 4 ms 612 KB Output is correct
25 Correct 3 ms 636 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 4 ms 632 KB Output is correct
28 Correct 3 ms 632 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 632 KB Output is correct
33 Correct 312 ms 88020 KB Output is correct
34 Correct 449 ms 96512 KB Output is correct
35 Correct 435 ms 87740 KB Output is correct
36 Correct 422 ms 91524 KB Output is correct
37 Correct 176 ms 86988 KB Output is correct
38 Correct 173 ms 87012 KB Output is correct
39 Correct 171 ms 93880 KB Output is correct
40 Correct 171 ms 93732 KB Output is correct
41 Correct 176 ms 85164 KB Output is correct
42 Correct 162 ms 86008 KB Output is correct
43 Correct 179 ms 85112 KB Output is correct
44 Correct 169 ms 88924 KB Output is correct
45 Correct 164 ms 85024 KB Output is correct
46 Correct 166 ms 85116 KB Output is correct
47 Correct 153 ms 89272 KB Output is correct
48 Correct 153 ms 89292 KB Output is correct
49 Correct 437 ms 89112 KB Output is correct
50 Correct 446 ms 88988 KB Output is correct
51 Correct 339 ms 95864 KB Output is correct
52 Correct 347 ms 95224 KB Output is correct
53 Correct 512 ms 87244 KB Output is correct
54 Correct 338 ms 87900 KB Output is correct
55 Correct 336 ms 86136 KB Output is correct
56 Correct 374 ms 90728 KB Output is correct
57 Correct 330 ms 86852 KB Output is correct
58 Correct 336 ms 87192 KB Output is correct
59 Correct 154 ms 89524 KB Output is correct