Submission #68999

# Submission time Handle Problem Language Result Execution time Memory
68999 2018-08-19T12:26:47 Z theknife2001 Horses (IOI15_horses) C++17
54 / 100
1500 ms 134116 KB
#include "horses.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
#define mid (l+r)/2

using namespace std;
const int N=5e5+55;
long long tree[N*4];
long long x[N];
long long y[N];
int n;
int m=1e9+7;

void build(int l , int r , int node)
{
    if(l==r)
    {
        tree[node]=x[l];
        return ;
    }
    build(l,mid,node*2);
    build(mid+1,r,node*2+1);
    tree[node]=tree[node*2]*tree[node*2+1];
    tree[node]%=m;
}

void update(int l , int r , int node , int ind , int val)
{
    if(l==r&&l==ind)
    {
        tree[node]=val;
        return ;
    }
    if(ind<=mid)
        update(l,mid,node*2,ind,val);
    else
        update(mid+1,r,node*2+1,ind,val);
    tree[node]=tree[node*2]*tree[node*2+1];
    tree[node]%=m;
}

long long query(int l , int r , int node , int x , int y)
{
    if(x<=l&&r<=y)
        return tree[node];
    if(l>y||r<x)
        return 1;
    return (query(l,mid,node*2,x,y)*query(mid+1,r,node*2+1,x,y))%m;
}

int solve()
{
	int i=n-1;
    long long ret=0;
	long long temp=1;
	long long s=1;
	while(i>=0)
    {
        s*=x[i];
        i--;
        if(s>10000000000)
            break;
    }
    i++;
    int j=i+1;
    bool q=0;
    int bestpos=n-1;
    for(;i<n;i++)
    {
        temp*=x[i];
        if(y[i]*temp>ret)
        {
            ret=y[i]*temp;
            bestpos=i;
        }
        if(ret<0||y[i]*temp<0)
        {
            q=1;
            break;
        }
    }
    if(q)
    {
        i=j;
        temp=1;
        ret=0;
        bestpos=n-1;
        for(;i<n;i++)
        {
            temp*=x[i];
            if(y[i]*temp>ret)
            {
                ret=y[i]*temp;
                bestpos=i;
            }
            if(ret<0||y[i]*temp<0)
            {
                assert(0);
            }
        }
    }
    return (y[bestpos]*query(0,n-1,1,0,bestpos))%m;
}

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];
    }
    build(0,n-1,1);
    return solve();
}

int updateX(int pos, int val) {
    x[pos]=val;
    update(0,n-1,1,pos,val);
    return solve();
}

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

Compilation message

horses.cpp: In function 'long long int query(int, int, int, int, int)':
horses.cpp:42:57: warning: declaration of 'y' shadows a global declaration [-Wshadow]
 long long query(int l , int r , int node , int x , int y)
                                                         ^
horses.cpp:10:11: note: shadowed declaration is here
 long long y[N];
           ^
horses.cpp:42:57: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 long long query(int l , int r , int node , int x , int y)
                                                         ^
horses.cpp:9:11: note: shadowed declaration is here
 long long x[N];
           ^
horses.cpp: In function 'int solve()':
horses.cpp:102:49: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return (y[bestpos]*query(0,n-1,1,0,bestpos))%m;
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:105:33: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 int init(int N, int X[], int Y[])
                                 ^
horses.cpp:7:11: note: shadowed declaration is here
 const int N=5e5+55;
           ^
# 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 440 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 520 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 3 ms 568 KB Output is correct
9 Correct 2 ms 568 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 720 KB Output is correct
12 Correct 3 ms 720 KB Output is correct
13 Correct 3 ms 720 KB Output is correct
14 Correct 2 ms 744 KB Output is correct
15 Correct 3 ms 744 KB Output is correct
16 Correct 2 ms 744 KB Output is correct
17 Correct 2 ms 744 KB Output is correct
18 Correct 3 ms 744 KB Output is correct
19 Correct 3 ms 744 KB Output is correct
20 Correct 2 ms 744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 744 KB Output is correct
2 Correct 2 ms 744 KB Output is correct
3 Correct 2 ms 744 KB Output is correct
4 Correct 2 ms 744 KB Output is correct
5 Correct 2 ms 744 KB Output is correct
6 Correct 2 ms 744 KB Output is correct
7 Correct 2 ms 744 KB Output is correct
8 Correct 3 ms 744 KB Output is correct
9 Correct 3 ms 744 KB Output is correct
10 Correct 2 ms 744 KB Output is correct
11 Correct 3 ms 744 KB Output is correct
12 Correct 3 ms 744 KB Output is correct
13 Correct 2 ms 744 KB Output is correct
14 Correct 2 ms 744 KB Output is correct
15 Correct 2 ms 744 KB Output is correct
16 Correct 3 ms 744 KB Output is correct
17 Correct 2 ms 744 KB Output is correct
18 Correct 2 ms 744 KB Output is correct
19 Correct 2 ms 744 KB Output is correct
20 Correct 2 ms 744 KB Output is correct
21 Correct 2 ms 744 KB Output is correct
22 Correct 2 ms 744 KB Output is correct
23 Correct 4 ms 744 KB Output is correct
24 Correct 3 ms 744 KB Output is correct
25 Correct 4 ms 744 KB Output is correct
26 Correct 4 ms 744 KB Output is correct
27 Correct 5 ms 744 KB Output is correct
28 Correct 4 ms 748 KB Output is correct
29 Correct 7 ms 780 KB Output is correct
30 Correct 6 ms 792 KB Output is correct
31 Correct 6 ms 828 KB Output is correct
32 Correct 8 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 21740 KB Output is correct
2 Correct 189 ms 21740 KB Output is correct
3 Correct 129 ms 25740 KB Output is correct
4 Correct 202 ms 33232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 33232 KB Output is correct
2 Correct 3 ms 33232 KB Output is correct
3 Correct 2 ms 33232 KB Output is correct
4 Correct 3 ms 33232 KB Output is correct
5 Correct 3 ms 33232 KB Output is correct
6 Correct 3 ms 33232 KB Output is correct
7 Correct 2 ms 33232 KB Output is correct
8 Correct 3 ms 33232 KB Output is correct
9 Correct 2 ms 33232 KB Output is correct
10 Correct 2 ms 33232 KB Output is correct
11 Correct 2 ms 33232 KB Output is correct
12 Correct 2 ms 33232 KB Output is correct
13 Correct 3 ms 33232 KB Output is correct
14 Correct 3 ms 33232 KB Output is correct
15 Correct 2 ms 33232 KB Output is correct
16 Correct 3 ms 33232 KB Output is correct
17 Correct 2 ms 33232 KB Output is correct
18 Correct 2 ms 33232 KB Output is correct
19 Correct 3 ms 33232 KB Output is correct
20 Correct 3 ms 33232 KB Output is correct
21 Correct 2 ms 33232 KB Output is correct
22 Correct 3 ms 33232 KB Output is correct
23 Correct 3 ms 33232 KB Output is correct
24 Correct 4 ms 33232 KB Output is correct
25 Correct 3 ms 33232 KB Output is correct
26 Correct 4 ms 33232 KB Output is correct
27 Correct 5 ms 33232 KB Output is correct
28 Correct 4 ms 33232 KB Output is correct
29 Correct 7 ms 33232 KB Output is correct
30 Correct 5 ms 33232 KB Output is correct
31 Correct 7 ms 33232 KB Output is correct
32 Correct 8 ms 33232 KB Output is correct
33 Correct 173 ms 36400 KB Output is correct
34 Correct 56 ms 40368 KB Output is correct
35 Correct 93 ms 51260 KB Output is correct
36 Correct 86 ms 62072 KB Output is correct
37 Correct 801 ms 64364 KB Output is correct
38 Correct 59 ms 67184 KB Output is correct
39 Execution timed out 1560 ms 69144 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 69144 KB Output is correct
2 Correct 2 ms 69144 KB Output is correct
3 Correct 2 ms 69144 KB Output is correct
4 Correct 2 ms 69144 KB Output is correct
5 Correct 3 ms 69144 KB Output is correct
6 Correct 3 ms 69144 KB Output is correct
7 Correct 2 ms 69144 KB Output is correct
8 Correct 2 ms 69144 KB Output is correct
9 Correct 3 ms 69144 KB Output is correct
10 Correct 2 ms 69144 KB Output is correct
11 Correct 3 ms 69144 KB Output is correct
12 Correct 2 ms 69144 KB Output is correct
13 Correct 4 ms 69144 KB Output is correct
14 Correct 3 ms 69144 KB Output is correct
15 Correct 2 ms 69144 KB Output is correct
16 Correct 2 ms 69144 KB Output is correct
17 Correct 2 ms 69144 KB Output is correct
18 Correct 2 ms 69144 KB Output is correct
19 Correct 3 ms 69144 KB Output is correct
20 Correct 3 ms 69144 KB Output is correct
21 Correct 2 ms 69144 KB Output is correct
22 Correct 2 ms 69144 KB Output is correct
23 Correct 3 ms 69144 KB Output is correct
24 Correct 5 ms 69144 KB Output is correct
25 Correct 4 ms 69144 KB Output is correct
26 Correct 3 ms 69144 KB Output is correct
27 Correct 4 ms 69144 KB Output is correct
28 Correct 4 ms 69144 KB Output is correct
29 Correct 7 ms 69144 KB Output is correct
30 Correct 5 ms 69144 KB Output is correct
31 Correct 8 ms 69144 KB Output is correct
32 Correct 7 ms 69144 KB Output is correct
33 Correct 131 ms 74136 KB Output is correct
34 Correct 169 ms 86900 KB Output is correct
35 Correct 128 ms 90584 KB Output is correct
36 Correct 206 ms 98216 KB Output is correct
37 Correct 155 ms 101200 KB Output is correct
38 Correct 57 ms 105180 KB Output is correct
39 Correct 96 ms 116276 KB Output is correct
40 Correct 89 ms 126904 KB Output is correct
41 Correct 835 ms 129276 KB Output is correct
42 Correct 62 ms 132032 KB Output is correct
43 Execution timed out 1577 ms 134116 KB Time limit exceeded
44 Halted 0 ms 0 KB -