Submission #134250

# Submission time Handle Problem Language Result Execution time Memory
134250 2019-07-22T09:30:56 Z Runtime_error_ Horses (IOI15_horses) C++14
100 / 100
1468 ms 131484 KB
#include "horses.h"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define le node+node
#define ri node+node+1
#define mid (l+r)/2
using namespace std;
const ll inf = 5e5+9,mod = 1e9+7;
ll n,dp2[inf],x[inf],y[inf];
ld dp1[inf];

ll power(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;

}

struct Node{

    ld mx1 , lzy1;
    ll mx2 , lzy2;

    Node(ll idx = 0){
        lzy1 = 0.0;
        lzy2 = 1;
        mx1 = dp1[idx];
        mx2 = dp2[idx];
    }
};
Node tree[inf<<2];

Node merge(Node x , Node y){
    if(x.mx1 >= y.mx1)
        return x;
    return y;
}

void push(int node,int l,int r){

    if(tree[node].lzy2 == 1)
        return ;
    tree[node].mx1 += tree[node].lzy1;
    tree[node].mx2 = (tree[node].mx2 * tree[node].lzy2)%mod;
    if(l!=r)
        tree[le].lzy1 += tree[node].lzy1, tree[le].lzy2 = (tree[le].lzy2 * tree[node].lzy2)%mod,
        tree[ri].lzy1 += tree[node].lzy1, tree[ri].lzy2 = (tree[ri].lzy2 * tree[node].lzy2)%mod;
    tree[node].lzy2 = 1,tree[node].lzy1 = 0.0;
}

void build(int node,int l,int r){

    if(l == r)
        return void(tree[node] = Node(l));

    build(le,l,mid);
    build(ri,mid+1,r);
    tree[node] = merge( tree[le] , tree[ri] );
}

void update(int node,int l,int r,int x,int y,ll val,int sign){

    push(node,l,r);
    if(l>r || r<x || l>y)
        return ;
    if(l>=x && r<=y){
        if(sign == -1){
            tree[node].lzy1 = -1.0*log(1.0*val);
            tree[node].lzy2 = power(val,mod-2,mod);
        }
        else{
            tree[node].lzy1 = 1.0*log(1.0*val);
            tree[node].lzy2 = val;
        }
        push(node,l,r);
        return;
    }
    update(le,l,mid,x,y,val,sign);
    update(ri,mid+1,r,x,y,val,sign);
    tree[node] = merge( tree[le] , tree[ri] );
}


void calc(){

    ld lcur=log(1.0),lret = 0.0,ltmp=0.0;

	ll cur = 1,ret = 0,tmp=0;

	for(int i=1;i<=n;i++){
        cur = (cur*x[i])%mod;
        lcur += log(1.0*x[i]);

        tmp = (cur*y[i])%mod;
        ltmp = lcur+log(1.0*y[i]);

        if(ltmp>=lret)
            lret = ltmp,ret = tmp;

        dp1[i] = ltmp;
        dp2[i] = tmp;
	}

}

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

    n = N;
    for(int i=1;i<=N;i++)
        x[i] = X[i-1] , y[i] = Y[i-1];
    calc();
    build(1,1,n);
    //cout<<tree[1].mx2<<endl;

    return tree[1].mx2;
}

int updateX(int pos, int val) {
    pos++;

    update(1,1,n,pos,n,x[pos],-1);

    x[pos] = val;

    update(1,1,n,pos,n,x[pos],1);
    //cout<<tree[1].mx2<<endl;

    return tree[1].mx2;
}

int updateY(int pos, int val) {
    pos++;

    update(1,1,n,pos,pos,y[pos],-1);
    y[pos] = val;
    update(1,1,n,pos,pos,y[pos],1);
    //cout<<tree[1].mx2<<endl;
	return tree[1].mx2;
}

Compilation message

horses.cpp: In function 'long long int power(long long int, long long int, long long int)':
horses.cpp:13:24: warning: declaration of 'n' shadows a global declaration [-Wshadow]
 ll power(ll x,ll n,ll M)
                        ^
horses.cpp:10:4: note: shadowed declaration is here
 ll n,dp2[inf],x[inf],y[inf];
    ^
horses.cpp:13:24: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 ll power(ll x,ll n,ll M)
                        ^
horses.cpp:10:15: note: shadowed declaration is here
 ll n,dp2[inf],x[inf],y[inf];
               ^
horses.cpp: In function 'Node merge(Node, Node)':
horses.cpp:38:27: warning: declaration of 'y' shadows a global declaration [-Wshadow]
 Node merge(Node x , Node y){
                           ^
horses.cpp:10:22: note: shadowed declaration is here
 ll n,dp2[inf],x[inf],y[inf];
                      ^
horses.cpp:38:27: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 Node merge(Node x , Node y){
                           ^
horses.cpp:10:15: note: shadowed declaration is here
 ll n,dp2[inf],x[inf],y[inf];
               ^
horses.cpp: In function 'void update(int, int, int, int, int, long long int, int)':
horses.cpp:66:61: warning: declaration of 'y' shadows a global declaration [-Wshadow]
 void update(int node,int l,int r,int x,int y,ll val,int sign){
                                                             ^
horses.cpp:10:22: note: shadowed declaration is here
 ll n,dp2[inf],x[inf],y[inf];
                      ^
horses.cpp:66:61: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 void update(int node,int l,int r,int x,int y,ll val,int sign){
                                                             ^
horses.cpp:10:15: note: shadowed declaration is here
 ll n,dp2[inf],x[inf],y[inf];
               ^
horses.cpp:73:44: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
             tree[node].lzy1 = -1.0*log(1.0*val);
                                            ^~~
horses.cpp:77:43: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
             tree[node].lzy1 = 1.0*log(1.0*val);
                                           ^~~
horses.cpp: In function 'void calc()':
horses.cpp:97:28: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
         lcur += log(1.0*x[i]);
                         ~~~^
horses.cpp:100:32: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
         ltmp = lcur+log(1.0*y[i]);
                             ~~~^
horses.cpp:93:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
  ll cur = 1,ret = 0,tmp=0;
             ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:117:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     build(1,1,n);
                ^
horses.cpp:120:20: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return tree[1].mx2;
            ~~~~~~~~^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:126:33: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     update(1,1,n,pos,n,x[pos],-1);
                                 ^
horses.cpp:126:33: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
horses.cpp:130:32: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     update(1,1,n,pos,n,x[pos],1);
                                ^
horses.cpp:130:32: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
horses.cpp:133:20: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return tree[1].mx2;
            ~~~~~~~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:139:35: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     update(1,1,n,pos,pos,y[pos],-1);
                                   ^
horses.cpp:141:34: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     update(1,1,n,pos,pos,y[pos],1);
                                  ^
horses.cpp:143:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return tree[1].mx2;
         ~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 81 ms 94328 KB Output is correct
2 Correct 81 ms 94328 KB Output is correct
3 Correct 81 ms 94328 KB Output is correct
4 Correct 97 ms 94328 KB Output is correct
5 Correct 82 ms 94356 KB Output is correct
6 Correct 92 ms 94300 KB Output is correct
7 Correct 89 ms 94428 KB Output is correct
8 Correct 86 ms 94456 KB Output is correct
9 Correct 97 ms 94232 KB Output is correct
10 Correct 93 ms 94220 KB Output is correct
11 Correct 83 ms 94208 KB Output is correct
12 Correct 82 ms 94328 KB Output is correct
13 Correct 83 ms 94244 KB Output is correct
14 Correct 83 ms 94372 KB Output is correct
15 Correct 82 ms 94328 KB Output is correct
16 Correct 82 ms 94256 KB Output is correct
17 Correct 82 ms 94328 KB Output is correct
18 Correct 83 ms 94288 KB Output is correct
19 Correct 82 ms 94328 KB Output is correct
20 Correct 82 ms 94240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 94300 KB Output is correct
2 Correct 83 ms 94300 KB Output is correct
3 Correct 83 ms 94344 KB Output is correct
4 Correct 82 ms 94328 KB Output is correct
5 Correct 81 ms 94288 KB Output is correct
6 Correct 82 ms 94300 KB Output is correct
7 Correct 97 ms 94236 KB Output is correct
8 Correct 95 ms 94292 KB Output is correct
9 Correct 117 ms 94456 KB Output is correct
10 Correct 83 ms 94328 KB Output is correct
11 Correct 82 ms 94332 KB Output is correct
12 Correct 84 ms 94328 KB Output is correct
13 Correct 105 ms 94412 KB Output is correct
14 Correct 83 ms 94328 KB Output is correct
15 Correct 87 ms 94328 KB Output is correct
16 Correct 90 ms 94284 KB Output is correct
17 Correct 83 ms 94292 KB Output is correct
18 Correct 81 ms 94328 KB Output is correct
19 Correct 81 ms 94304 KB Output is correct
20 Correct 82 ms 94328 KB Output is correct
21 Correct 83 ms 94328 KB Output is correct
22 Correct 85 ms 94276 KB Output is correct
23 Correct 86 ms 94328 KB Output is correct
24 Correct 100 ms 94300 KB Output is correct
25 Correct 84 ms 94328 KB Output is correct
26 Correct 86 ms 94304 KB Output is correct
27 Correct 85 ms 94328 KB Output is correct
28 Correct 97 ms 94428 KB Output is correct
29 Correct 97 ms 94328 KB Output is correct
30 Correct 102 ms 94344 KB Output is correct
31 Correct 139 ms 94328 KB Output is correct
32 Correct 99 ms 94456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 381 ms 120440 KB Output is correct
2 Correct 1053 ms 131392 KB Output is correct
3 Correct 975 ms 122604 KB Output is correct
4 Correct 1425 ms 126520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 94244 KB Output is correct
2 Correct 82 ms 94328 KB Output is correct
3 Correct 82 ms 94328 KB Output is correct
4 Correct 82 ms 94276 KB Output is correct
5 Correct 81 ms 94328 KB Output is correct
6 Correct 82 ms 94304 KB Output is correct
7 Correct 82 ms 94280 KB Output is correct
8 Correct 82 ms 94328 KB Output is correct
9 Correct 81 ms 94300 KB Output is correct
10 Correct 83 ms 94268 KB Output is correct
11 Correct 82 ms 94324 KB Output is correct
12 Correct 81 ms 94328 KB Output is correct
13 Correct 81 ms 94328 KB Output is correct
14 Correct 82 ms 94328 KB Output is correct
15 Correct 81 ms 94304 KB Output is correct
16 Correct 81 ms 94304 KB Output is correct
17 Correct 81 ms 94200 KB Output is correct
18 Correct 83 ms 94468 KB Output is correct
19 Correct 88 ms 94220 KB Output is correct
20 Correct 82 ms 94328 KB Output is correct
21 Correct 82 ms 94328 KB Output is correct
22 Correct 83 ms 94428 KB Output is correct
23 Correct 85 ms 94456 KB Output is correct
24 Correct 87 ms 94456 KB Output is correct
25 Correct 84 ms 94432 KB Output is correct
26 Correct 86 ms 94328 KB Output is correct
27 Correct 85 ms 94416 KB Output is correct
28 Correct 88 ms 94304 KB Output is correct
29 Correct 86 ms 94328 KB Output is correct
30 Correct 88 ms 94456 KB Output is correct
31 Correct 97 ms 94456 KB Output is correct
32 Correct 89 ms 94456 KB Output is correct
33 Correct 244 ms 117880 KB Output is correct
34 Correct 253 ms 121756 KB Output is correct
35 Correct 212 ms 128776 KB Output is correct
36 Correct 308 ms 128748 KB Output is correct
37 Correct 207 ms 119984 KB Output is correct
38 Correct 253 ms 120924 KB Output is correct
39 Correct 240 ms 119968 KB Output is correct
40 Correct 290 ms 123896 KB Output is correct
41 Correct 161 ms 120100 KB Output is correct
42 Correct 179 ms 120012 KB Output is correct
43 Correct 162 ms 124152 KB Output is correct
44 Correct 160 ms 124152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 94204 KB Output is correct
2 Correct 82 ms 94260 KB Output is correct
3 Correct 82 ms 94328 KB Output is correct
4 Correct 84 ms 94240 KB Output is correct
5 Correct 92 ms 94328 KB Output is correct
6 Correct 86 ms 94328 KB Output is correct
7 Correct 82 ms 94328 KB Output is correct
8 Correct 85 ms 94372 KB Output is correct
9 Correct 83 ms 94300 KB Output is correct
10 Correct 82 ms 94328 KB Output is correct
11 Correct 99 ms 94300 KB Output is correct
12 Correct 96 ms 94228 KB Output is correct
13 Correct 84 ms 94200 KB Output is correct
14 Correct 86 ms 94456 KB Output is correct
15 Correct 87 ms 94300 KB Output is correct
16 Correct 82 ms 94224 KB Output is correct
17 Correct 82 ms 94200 KB Output is correct
18 Correct 81 ms 94328 KB Output is correct
19 Correct 82 ms 94328 KB Output is correct
20 Correct 82 ms 94328 KB Output is correct
21 Correct 82 ms 94300 KB Output is correct
22 Correct 82 ms 94284 KB Output is correct
23 Correct 85 ms 94328 KB Output is correct
24 Correct 86 ms 94456 KB Output is correct
25 Correct 85 ms 94328 KB Output is correct
26 Correct 86 ms 94376 KB Output is correct
27 Correct 85 ms 94332 KB Output is correct
28 Correct 86 ms 94300 KB Output is correct
29 Correct 87 ms 94328 KB Output is correct
30 Correct 87 ms 94328 KB Output is correct
31 Correct 84 ms 94368 KB Output is correct
32 Correct 85 ms 94456 KB Output is correct
33 Correct 380 ms 120464 KB Output is correct
34 Correct 1040 ms 131484 KB Output is correct
35 Correct 975 ms 122584 KB Output is correct
36 Correct 1468 ms 126680 KB Output is correct
37 Correct 234 ms 121720 KB Output is correct
38 Correct 232 ms 121784 KB Output is correct
39 Correct 227 ms 128728 KB Output is correct
40 Correct 280 ms 128828 KB Output is correct
41 Correct 200 ms 119988 KB Output is correct
42 Correct 269 ms 121056 KB Output is correct
43 Correct 220 ms 119792 KB Output is correct
44 Correct 279 ms 123916 KB Output is correct
45 Correct 156 ms 119872 KB Output is correct
46 Correct 177 ms 119944 KB Output is correct
47 Correct 160 ms 124152 KB Output is correct
48 Correct 159 ms 124152 KB Output is correct
49 Correct 921 ms 123824 KB Output is correct
50 Correct 934 ms 123828 KB Output is correct
51 Correct 454 ms 130552 KB Output is correct
52 Correct 1095 ms 130088 KB Output is correct
53 Correct 828 ms 122156 KB Output is correct
54 Correct 1129 ms 122720 KB Output is correct
55 Correct 1025 ms 121080 KB Output is correct
56 Correct 1268 ms 125592 KB Output is correct
57 Correct 365 ms 121460 KB Output is correct
58 Correct 599 ms 122048 KB Output is correct
59 Correct 159 ms 124188 KB Output is correct