Submission #69847

# Submission time Handle Problem Language Result Execution time Memory
69847 2018-08-21T15:58:39 Z Vahan Horses (IOI15_horses) C++17
100 / 100
578 ms 165480 KB
#include "horses.h"
#include<cmath>
#include<iostream>
using namespace std;
pair<long double,long long> t[5000008],mec[5000008];
long double lp[600000];
long long p[600000],n,x[600000],y[600000];
long long mod=1000000007;
void build(int l,int r,int v)
{
    t[v].second=1;
    if(l==r)
    {
        t[v].first=lp[l];
        mec[v].first=lp[l];
        t[v].second=p[l];
        mec[v].second=p[l];
        return;
    }
    int mid=(l+r)/2;
    build(l,mid,2*v);
    build(mid+1,r,2*v+1);
    mec[v]=max(mec[2*v],mec[2*v+1]);
}
void update(int L,int R,int l,int r,int v,long long e,long double f)
{
    if(l>r)
        return;
    if(l==L && r==R)
    {
        t[v].first+=f;
        t[v].second*=e;
        mec[v].first+=f;
        mec[v].second*=e;
        mec[v].second%=mod;
        t[v].second%=mod;
        return;
    }
    int mid=(L+R)/2;
    update(L,mid,l,min(mid,r),2*v,e,f);
    update(mid+1,R,max(l,mid+1),r,2*v+1,e,f);
    mec[v]=max(mec[2*v],mec[2*v+1]);
    mec[v].first+=t[v].first;
    mec[v].second*=t[v].second;
    mec[v].second%=mod;
}
int init(int N, int X[], int Y[]) {
    n=N;
    for(int i=0;i<n;i++)
    {
        x[i]=X[i];
        y[i]=Y[i];
    }
    for(int i=0;i<N;i++)
    {
        p[i]=X[i];
        lp[i]+=log(X[i]);
        if(i>0)
        {
            p[i]=(p[i]*p[i-1])%mod;
            lp[i]+=lp[i-1];
        }
    }
    for(int i=0;i<N;i++)
    {
        p[i]=(p[i]*Y[i])%mod;
        lp[i]+=log(Y[i]);
    }
    build(0,n-1,1);
	return mec[1].second;
}
long long binpow(long long a,long long b)
{
    if(b==0)
        return 1;
    if(b%2==0)
    {
        long long arm=binpow(a,b/2);
        return (arm*arm)%mod;
    }
    return (a*binpow(a,b-1))%mod;
}
int updateX(int pos, int val) {
    long long e=(binpow(x[pos],mod-2)*val)%mod;
    long double f=log(val)-log(x[pos]);
    x[pos]=val;
    update(0,n-1,pos,n-1,1,e,f);
	return mec[1].second;
}

int updateY(int pos, int val) {
    long long e=(binpow(y[pos],mod-2)*val)%mod;
    long double f=log(val)-log(y[pos]);
    y[pos]=val;
    update(0,n-1,pos,pos,1,e,f);
	return mec[1].second;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:69:14: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     build(0,n-1,1);
             ~^~
horses.cpp:70:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return mec[1].second;
         ~~~~~~~^~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:87:15: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     update(0,n-1,pos,n-1,1,e,f);
              ~^~
horses.cpp:87:23: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     update(0,n-1,pos,n-1,1,e,f);
                      ~^~
horses.cpp:88:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return mec[1].second;
         ~~~~~~~^~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:95:15: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     update(0,n-1,pos,pos,1,e,f);
              ~^~
horses.cpp:96:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return mec[1].second;
         ~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 564 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 4 ms 564 KB Output is correct
6 Correct 2 ms 564 KB Output is correct
7 Correct 2 ms 564 KB Output is correct
8 Correct 3 ms 564 KB Output is correct
9 Correct 2 ms 564 KB Output is correct
10 Correct 3 ms 564 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 3 ms 676 KB Output is correct
18 Correct 2 ms 676 KB Output is correct
19 Correct 2 ms 676 KB Output is correct
20 Correct 3 ms 676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 676 KB Output is correct
2 Correct 2 ms 676 KB Output is correct
3 Correct 2 ms 676 KB Output is correct
4 Correct 2 ms 676 KB Output is correct
5 Correct 3 ms 676 KB Output is correct
6 Correct 2 ms 676 KB Output is correct
7 Correct 3 ms 676 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 676 KB Output is correct
10 Correct 2 ms 676 KB Output is correct
11 Correct 3 ms 676 KB Output is correct
12 Correct 3 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 2 ms 676 KB Output is correct
15 Correct 2 ms 676 KB Output is correct
16 Correct 2 ms 676 KB Output is correct
17 Correct 3 ms 676 KB Output is correct
18 Correct 3 ms 676 KB Output is correct
19 Correct 2 ms 676 KB Output is correct
20 Correct 3 ms 676 KB Output is correct
21 Correct 2 ms 676 KB Output is correct
22 Correct 2 ms 676 KB Output is correct
23 Correct 5 ms 848 KB Output is correct
24 Correct 5 ms 848 KB Output is correct
25 Correct 4 ms 848 KB Output is correct
26 Correct 4 ms 848 KB Output is correct
27 Correct 4 ms 848 KB Output is correct
28 Correct 5 ms 848 KB Output is correct
29 Correct 4 ms 848 KB Output is correct
30 Correct 4 ms 848 KB Output is correct
31 Correct 4 ms 848 KB Output is correct
32 Correct 4 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 351 ms 90960 KB Output is correct
2 Correct 576 ms 90960 KB Output is correct
3 Correct 455 ms 90960 KB Output is correct
4 Correct 522 ms 90960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 90960 KB Output is correct
2 Correct 3 ms 90960 KB Output is correct
3 Correct 3 ms 90960 KB Output is correct
4 Correct 3 ms 90960 KB Output is correct
5 Correct 3 ms 90960 KB Output is correct
6 Correct 2 ms 90960 KB Output is correct
7 Correct 2 ms 90960 KB Output is correct
8 Correct 3 ms 90960 KB Output is correct
9 Correct 2 ms 90960 KB Output is correct
10 Correct 2 ms 90960 KB Output is correct
11 Correct 3 ms 90960 KB Output is correct
12 Correct 2 ms 90960 KB Output is correct
13 Correct 3 ms 90960 KB Output is correct
14 Correct 3 ms 90960 KB Output is correct
15 Correct 2 ms 90960 KB Output is correct
16 Correct 3 ms 90960 KB Output is correct
17 Correct 3 ms 90960 KB Output is correct
18 Correct 2 ms 90960 KB Output is correct
19 Correct 2 ms 90960 KB Output is correct
20 Correct 3 ms 90960 KB Output is correct
21 Correct 2 ms 90960 KB Output is correct
22 Correct 3 ms 90960 KB Output is correct
23 Correct 5 ms 90960 KB Output is correct
24 Correct 5 ms 90960 KB Output is correct
25 Correct 5 ms 90960 KB Output is correct
26 Correct 5 ms 90960 KB Output is correct
27 Correct 5 ms 90960 KB Output is correct
28 Correct 4 ms 90960 KB Output is correct
29 Correct 5 ms 90960 KB Output is correct
30 Correct 6 ms 90960 KB Output is correct
31 Correct 4 ms 90960 KB Output is correct
32 Correct 4 ms 90960 KB Output is correct
33 Correct 179 ms 90960 KB Output is correct
34 Correct 199 ms 90960 KB Output is correct
35 Correct 196 ms 90960 KB Output is correct
36 Correct 186 ms 90960 KB Output is correct
37 Correct 157 ms 90960 KB Output is correct
38 Correct 163 ms 90960 KB Output is correct
39 Correct 141 ms 90960 KB Output is correct
40 Correct 159 ms 90960 KB Output is correct
41 Correct 166 ms 90960 KB Output is correct
42 Correct 134 ms 90960 KB Output is correct
43 Correct 155 ms 90960 KB Output is correct
44 Correct 168 ms 96280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 96280 KB Output is correct
2 Correct 2 ms 96280 KB Output is correct
3 Correct 2 ms 96280 KB Output is correct
4 Correct 3 ms 96280 KB Output is correct
5 Correct 3 ms 96280 KB Output is correct
6 Correct 3 ms 96280 KB Output is correct
7 Correct 2 ms 96280 KB Output is correct
8 Correct 3 ms 96280 KB Output is correct
9 Correct 2 ms 96280 KB Output is correct
10 Correct 2 ms 96280 KB Output is correct
11 Correct 2 ms 96280 KB Output is correct
12 Correct 2 ms 96280 KB Output is correct
13 Correct 2 ms 96280 KB Output is correct
14 Correct 2 ms 96280 KB Output is correct
15 Correct 2 ms 96280 KB Output is correct
16 Correct 2 ms 96280 KB Output is correct
17 Correct 3 ms 96280 KB Output is correct
18 Correct 3 ms 96280 KB Output is correct
19 Correct 3 ms 96280 KB Output is correct
20 Correct 3 ms 96280 KB Output is correct
21 Correct 2 ms 96280 KB Output is correct
22 Correct 2 ms 96280 KB Output is correct
23 Correct 4 ms 96280 KB Output is correct
24 Correct 3 ms 96280 KB Output is correct
25 Correct 4 ms 96280 KB Output is correct
26 Correct 4 ms 96280 KB Output is correct
27 Correct 6 ms 96280 KB Output is correct
28 Correct 4 ms 96280 KB Output is correct
29 Correct 4 ms 96280 KB Output is correct
30 Correct 5 ms 96280 KB Output is correct
31 Correct 5 ms 96280 KB Output is correct
32 Correct 4 ms 96280 KB Output is correct
33 Correct 333 ms 97160 KB Output is correct
34 Correct 578 ms 97212 KB Output is correct
35 Correct 455 ms 97256 KB Output is correct
36 Correct 562 ms 97256 KB Output is correct
37 Correct 164 ms 97256 KB Output is correct
38 Correct 190 ms 97256 KB Output is correct
39 Correct 180 ms 97256 KB Output is correct
40 Correct 209 ms 97256 KB Output is correct
41 Correct 185 ms 97256 KB Output is correct
42 Correct 169 ms 97256 KB Output is correct
43 Correct 127 ms 97256 KB Output is correct
44 Correct 162 ms 97256 KB Output is correct
45 Correct 162 ms 97256 KB Output is correct
46 Correct 138 ms 97256 KB Output is correct
47 Correct 168 ms 97256 KB Output is correct
48 Correct 141 ms 102604 KB Output is correct
49 Correct 495 ms 108832 KB Output is correct
50 Correct 492 ms 113780 KB Output is correct
51 Correct 407 ms 125648 KB Output is correct
52 Correct 451 ms 136940 KB Output is correct
53 Correct 469 ms 140496 KB Output is correct
54 Correct 343 ms 144308 KB Output is correct
55 Correct 353 ms 146672 KB Output is correct
56 Correct 394 ms 154212 KB Output is correct
57 Correct 300 ms 156972 KB Output is correct
58 Correct 342 ms 160272 KB Output is correct
59 Correct 154 ms 165480 KB Output is correct