Submission #71560

# Submission time Handle Problem Language Result Execution time Memory
71560 2018-08-25T07:05:21 Z mr_banana Horses (IOI15_horses) C++17
0 / 100
865 ms 36332 KB
#include <bits/stdc++.h>
#include "horses.h"

using namespace std;
const int MN=5e5+100,mod=1e9+7;
int n,x[MN],y[MN],seg[4*MN],mulx=1;
set<int,greater<int> > more;
int powm(int x,int y){
    if(y==0){
        return 1;
    }
    int ans=powm(x,y/2);
    ans=(1ll*ans*ans)%mod;
    if(y&1){
        ans=(1ll*ans*x)%mod;
    }
    return ans;
}
void build(int v=1,int s=0,int e=n){
    if(e-s<2){
        seg[v]=y[s];
        return ;
    }
    int mid=(s+e)/2;
    build(2*v,s,mid);
    build(2*v+1,mid,e);
    seg[v]=max(seg[2*v],seg[2*v+1]);
}
void st(int p,int val,int v=1,int s=0,int e=n){
    if(e-s<2){
        seg[v]=val;
        return;
    }
    int mid=(s+e)/2;
    if(p<mid){
        st(p,val,2*v,s,mid);
    }
    else{
        st(p,val,2*v+1,mid,e);
    }
    seg[v]=max(seg[2*v],seg[2*v+1]);
}
int get(int l,int r,int v=1,int s=0,int e=n){
    if(l<=s && e<=r){
        return seg[v];
    }
    if(l>=e || s>=r){
        return 0;
    }
    int mid=(s+e)/2;
    return max(get(l,r,2*v,s,mid),get(l,r,2*v+1,mid,e));
}
int ans(){
    long long mul=1,mulm=1,ym=y[n-1];
    for(int i:more){
        int yi=get(i,n);
        if(mulm*yi>mul*ym){
            ym=yi;
            mulm=mul;
        }
        mul=mul*x[i];
        if(mul>mod){
            break;
        }
    }

    return (((mulx*powm(mulm,mod-2))%mod)*ym)%mod;
}
int init(int N, int X[], int Y[]) {
    n=N;
    for(int i=0;i<n;i++){
        x[i]=X[i];
        mulx=(1ll*mulx*x[i]);
        y[i]=Y[i];
        if(x[i]>1){
            more.insert(i);
        }
    }
    more.insert(0);
    build();
	return ans();
}

int updateX(int pos, int val) {
    if(pos>0 && x[pos]>1 && val<2){
        more.erase(pos);
    }
    if(x[pos]<2 && val>1){
        more.insert(pos);
    }
    x[pos]=val;
	return ans();
}

int updateY(int pos, int val) {
	y[pos]=val;
    st(pos,val);
	return ans();
}

Compilation message

horses.cpp: In function 'int powm(int, int)':
horses.cpp:8:21: warning: declaration of 'y' shadows a global declaration [-Wshadow]
 int powm(int x,int y){
                     ^
horses.cpp:6:13: note: shadowed declaration is here
 int n,x[MN],y[MN],seg[4*MN],mulx=1;
             ^
horses.cpp:8:21: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 int powm(int x,int y){
                     ^
horses.cpp:6:7: note: shadowed declaration is here
 int n,x[MN],y[MN],seg[4*MN],mulx=1;
       ^
horses.cpp:13:22: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     ans=(1ll*ans*ans)%mod;
         ~~~~~~~~~~~~~^~~~
horses.cpp:15:24: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         ans=(1ll*ans*x)%mod;
             ~~~~~~~~~~~^~~~
horses.cpp: In function 'int ans()':
horses.cpp:67:35: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return (((mulx*powm(mulm,mod-2))%mod)*ym)%mod;
                                   ^
horses.cpp:67:46: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return (((mulx*powm(mulm,mod-2))%mod)*ym)%mod;
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:73:23: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         mulx=(1ll*mulx*x[i]);
              ~~~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 3 ms 440 KB Output is correct
5 Correct 3 ms 620 KB Output is correct
6 Correct 3 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 3 ms 720 KB Output is correct
10 Correct 3 ms 720 KB Output is correct
11 Correct 3 ms 720 KB Output is correct
12 Correct 2 ms 728 KB Output is correct
13 Incorrect 2 ms 728 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 728 KB Output is correct
2 Correct 3 ms 728 KB Output is correct
3 Correct 3 ms 728 KB Output is correct
4 Correct 3 ms 728 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 3 ms 728 KB Output is correct
8 Correct 3 ms 728 KB Output is correct
9 Correct 2 ms 728 KB Output is correct
10 Correct 3 ms 728 KB Output is correct
11 Correct 3 ms 728 KB Output is correct
12 Correct 2 ms 728 KB Output is correct
13 Incorrect 2 ms 728 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 865 ms 36332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 36332 KB Output is correct
2 Correct 3 ms 36332 KB Output is correct
3 Correct 2 ms 36332 KB Output is correct
4 Correct 3 ms 36332 KB Output is correct
5 Correct 3 ms 36332 KB Output is correct
6 Correct 2 ms 36332 KB Output is correct
7 Correct 2 ms 36332 KB Output is correct
8 Correct 2 ms 36332 KB Output is correct
9 Correct 3 ms 36332 KB Output is correct
10 Correct 2 ms 36332 KB Output is correct
11 Correct 2 ms 36332 KB Output is correct
12 Correct 2 ms 36332 KB Output is correct
13 Incorrect 4 ms 36332 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 36332 KB Output is correct
2 Correct 3 ms 36332 KB Output is correct
3 Correct 3 ms 36332 KB Output is correct
4 Correct 3 ms 36332 KB Output is correct
5 Correct 2 ms 36332 KB Output is correct
6 Correct 2 ms 36332 KB Output is correct
7 Correct 2 ms 36332 KB Output is correct
8 Correct 2 ms 36332 KB Output is correct
9 Correct 2 ms 36332 KB Output is correct
10 Correct 2 ms 36332 KB Output is correct
11 Correct 2 ms 36332 KB Output is correct
12 Correct 2 ms 36332 KB Output is correct
13 Incorrect 3 ms 36332 KB Output isn't correct
14 Halted 0 ms 0 KB -