Submission #58504

# Submission time Handle Problem Language Result Execution time Memory
58504 2018-07-18T04:27:23 Z ngkan146 Horses (IOI15_horses) C++11
100 / 100
1116 ms 62524 KB
#include "horses.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int,int> ii;
const ll mod = (ll) 1e9+7;
struct segTreeMul{
    ll node[2000005];
    segTreeMul(){
        for(int i=1;i<=2000000;i++) node[i] = 1;
    }
    void upd(int id,int l,int r,int pos,int val){
        if (r < pos || pos < l) return;
        if (l == r){
            node[id] = val;
            return;
        }
        upd(2*id,l,(l+r)/2,pos,val);
        upd(2*id+1,(l+r)/2+1,r,pos,val);
        node[id] = node[2*id] * node[2*id+1] % mod;
    }
    ll get(int id,int l,int r,int u,int v){
        if (r < u || v < l) return 1;
        if (u <= l && r <= v)   return node[id];
        return get(2*id, l, (l+r)/2, u, v) * get(2*id+1, (l+r)/2+1, r, u, v) % mod;
    }
};
struct segTreeMax{
    ll node[2000005];
    segTreeMax(){
        for(int i=1;i<=2000000;i++) node[i] = -1;
    }
    void upd(int id,int l,int r,int pos,int val){
        if (r < pos || pos < l) return;
        if (l == r){
            node[id] = val;
            return;
        }
        upd(2*id,l,(l+r)/2,pos,val);
        upd(2*id+1,(l+r)/2+1,r,pos,val);
        node[id] = max(node[2*id], node[2*id+1]);
    }
    ll get(int id,int l,int r,int u,int v){
        if (r < u || v < l) return 1;
        if (u <= l && r <= v)   return node[id];
        return max(get(2*id, l, (l+r)/2, u, v), get(2*id+1, (l+r)/2+1, r, u, v));
    }
};
segTreeMul segMul;
segTreeMax segMax;

int n;
int growthNum[500005];
set <int> notOneLst;
ll getBest(){
    if (notOneLst.empty())
        return segMax.get(1,1,n,1,n);

    vector <int> importants;
    importants.push_back(n+1);

    set<int>::iterator it = notOneLst.end();
    ll prod = 1;
    while(it != notOneLst.begin() && prod < mod){
        it --;
        importants.push_back(*it);
        prod *= growthNum[*it];
    }

    if (prod < mod && importants[0] != 1)
        importants.push_back(1);
    //reverse(importants.begin(), importants.end());

    double bestRatio = 0;
    int bestPos = -1;

    ll denominator = 1;
    for(int i=1;i<importants.size();i++){
        ll ma = segMax.get(1,1,n,importants[i], importants[i-1]-1);
        if (1.0 * ma / denominator > bestRatio){
            bestPos = i;
            bestRatio = 1.0 * ma / denominator;
        }
        denominator *= growthNum[importants[i]];
    }

    return segMul.get(1,1,n,1,importants[bestPos]) * segMax.get(1,1,n,importants[bestPos], importants[bestPos-1]-1) % mod;
}
int init(int N, int X[], int Y[]) {
    n = N;
    for(int i=0;i<n;i++){
        growthNum[i+1] = X[i];
        if (growthNum[i+1] > 1)
            notOneLst.insert(i+1);
        segMul.upd(1,1,n,i+1,X[i]);
    }
    for(int i=0;i<n;i++){
        segMax.upd(1,1,n,i+1,Y[i]);
    }
	return getBest();
}

int updateX(int pos, int val) {
    pos++;
    if (growthNum[pos] > 1) notOneLst.erase(pos);
    growthNum[pos] = val;
    segMul.upd(1,1,n,pos,val);
    if (growthNum[pos] > 1) notOneLst.insert(pos);
	return getBest();
}

int updateY(int pos, int val) {
	pos++;
	segMax.upd(1,1,n,pos,val);
	return getBest();
}

Compilation message

horses.cpp: In function 'long long int getBest()':
horses.cpp:78:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<importants.size();i++){
                 ~^~~~~~~~~~~~~~~~~~
horses.cpp:80:19: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
         if (1.0 * ma / denominator > bestRatio){
                   ^~
horses.cpp:80:24: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
         if (1.0 * ma / denominator > bestRatio){
                        ^~~~~~~~~~~
horses.cpp:82:31: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
             bestRatio = 1.0 * ma / denominator;
                               ^~
horses.cpp:82:36: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
             bestRatio = 1.0 * ma / denominator;
                                    ^~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:100:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return getBest();
         ~~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:109:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return getBest();
         ~~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:115:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return getBest();
         ~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 24 ms 31608 KB Output is correct
2 Correct 25 ms 31716 KB Output is correct
3 Correct 25 ms 31716 KB Output is correct
4 Correct 25 ms 31796 KB Output is correct
5 Correct 24 ms 31828 KB Output is correct
6 Correct 28 ms 31828 KB Output is correct
7 Correct 28 ms 31904 KB Output is correct
8 Correct 27 ms 31904 KB Output is correct
9 Correct 26 ms 31904 KB Output is correct
10 Correct 24 ms 31904 KB Output is correct
11 Correct 27 ms 31904 KB Output is correct
12 Correct 24 ms 31904 KB Output is correct
13 Correct 25 ms 31904 KB Output is correct
14 Correct 25 ms 31904 KB Output is correct
15 Correct 26 ms 31904 KB Output is correct
16 Correct 25 ms 31904 KB Output is correct
17 Correct 25 ms 31904 KB Output is correct
18 Correct 25 ms 31904 KB Output is correct
19 Correct 27 ms 31940 KB Output is correct
20 Correct 30 ms 31940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 31940 KB Output is correct
2 Correct 29 ms 31972 KB Output is correct
3 Correct 26 ms 31972 KB Output is correct
4 Correct 27 ms 31972 KB Output is correct
5 Correct 31 ms 31972 KB Output is correct
6 Correct 32 ms 31996 KB Output is correct
7 Correct 28 ms 31996 KB Output is correct
8 Correct 33 ms 31996 KB Output is correct
9 Correct 28 ms 31996 KB Output is correct
10 Correct 29 ms 31996 KB Output is correct
11 Correct 30 ms 31996 KB Output is correct
12 Correct 30 ms 31996 KB Output is correct
13 Correct 30 ms 31996 KB Output is correct
14 Correct 30 ms 31996 KB Output is correct
15 Correct 28 ms 31996 KB Output is correct
16 Correct 34 ms 31996 KB Output is correct
17 Correct 31 ms 31996 KB Output is correct
18 Correct 33 ms 31996 KB Output is correct
19 Correct 29 ms 31996 KB Output is correct
20 Correct 32 ms 31996 KB Output is correct
21 Correct 32 ms 31996 KB Output is correct
22 Correct 31 ms 31996 KB Output is correct
23 Correct 27 ms 31996 KB Output is correct
24 Correct 26 ms 31996 KB Output is correct
25 Correct 33 ms 32044 KB Output is correct
26 Correct 28 ms 32044 KB Output is correct
27 Correct 28 ms 32044 KB Output is correct
28 Correct 29 ms 32044 KB Output is correct
29 Correct 33 ms 32044 KB Output is correct
30 Correct 28 ms 32044 KB Output is correct
31 Correct 29 ms 32044 KB Output is correct
32 Correct 35 ms 32044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1116 ms 62412 KB Output is correct
2 Correct 774 ms 62428 KB Output is correct
3 Correct 699 ms 62488 KB Output is correct
4 Correct 910 ms 62524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 62524 KB Output is correct
2 Correct 26 ms 62524 KB Output is correct
3 Correct 27 ms 62524 KB Output is correct
4 Correct 25 ms 62524 KB Output is correct
5 Correct 26 ms 62524 KB Output is correct
6 Correct 25 ms 62524 KB Output is correct
7 Correct 28 ms 62524 KB Output is correct
8 Correct 25 ms 62524 KB Output is correct
9 Correct 30 ms 62524 KB Output is correct
10 Correct 29 ms 62524 KB Output is correct
11 Correct 27 ms 62524 KB Output is correct
12 Correct 27 ms 62524 KB Output is correct
13 Correct 28 ms 62524 KB Output is correct
14 Correct 28 ms 62524 KB Output is correct
15 Correct 27 ms 62524 KB Output is correct
16 Correct 30 ms 62524 KB Output is correct
17 Correct 30 ms 62524 KB Output is correct
18 Correct 26 ms 62524 KB Output is correct
19 Correct 32 ms 62524 KB Output is correct
20 Correct 28 ms 62524 KB Output is correct
21 Correct 27 ms 62524 KB Output is correct
22 Correct 31 ms 62524 KB Output is correct
23 Correct 34 ms 62524 KB Output is correct
24 Correct 28 ms 62524 KB Output is correct
25 Correct 32 ms 62524 KB Output is correct
26 Correct 34 ms 62524 KB Output is correct
27 Correct 32 ms 62524 KB Output is correct
28 Correct 26 ms 62524 KB Output is correct
29 Correct 30 ms 62524 KB Output is correct
30 Correct 30 ms 62524 KB Output is correct
31 Correct 32 ms 62524 KB Output is correct
32 Correct 32 ms 62524 KB Output is correct
33 Correct 281 ms 62524 KB Output is correct
34 Correct 264 ms 62524 KB Output is correct
35 Correct 578 ms 62524 KB Output is correct
36 Correct 457 ms 62524 KB Output is correct
37 Correct 326 ms 62524 KB Output is correct
38 Correct 449 ms 62524 KB Output is correct
39 Correct 285 ms 62524 KB Output is correct
40 Correct 488 ms 62524 KB Output is correct
41 Correct 291 ms 62524 KB Output is correct
42 Correct 308 ms 62524 KB Output is correct
43 Correct 460 ms 62524 KB Output is correct
44 Correct 453 ms 62524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 62524 KB Output is correct
2 Correct 30 ms 62524 KB Output is correct
3 Correct 28 ms 62524 KB Output is correct
4 Correct 29 ms 62524 KB Output is correct
5 Correct 32 ms 62524 KB Output is correct
6 Correct 26 ms 62524 KB Output is correct
7 Correct 26 ms 62524 KB Output is correct
8 Correct 25 ms 62524 KB Output is correct
9 Correct 30 ms 62524 KB Output is correct
10 Correct 26 ms 62524 KB Output is correct
11 Correct 26 ms 62524 KB Output is correct
12 Correct 25 ms 62524 KB Output is correct
13 Correct 27 ms 62524 KB Output is correct
14 Correct 27 ms 62524 KB Output is correct
15 Correct 27 ms 62524 KB Output is correct
16 Correct 26 ms 62524 KB Output is correct
17 Correct 25 ms 62524 KB Output is correct
18 Correct 24 ms 62524 KB Output is correct
19 Correct 26 ms 62524 KB Output is correct
20 Correct 26 ms 62524 KB Output is correct
21 Correct 30 ms 62524 KB Output is correct
22 Correct 28 ms 62524 KB Output is correct
23 Correct 27 ms 62524 KB Output is correct
24 Correct 28 ms 62524 KB Output is correct
25 Correct 31 ms 62524 KB Output is correct
26 Correct 27 ms 62524 KB Output is correct
27 Correct 28 ms 62524 KB Output is correct
28 Correct 32 ms 62524 KB Output is correct
29 Correct 30 ms 62524 KB Output is correct
30 Correct 29 ms 62524 KB Output is correct
31 Correct 28 ms 62524 KB Output is correct
32 Correct 28 ms 62524 KB Output is correct
33 Correct 982 ms 62524 KB Output is correct
34 Correct 735 ms 62524 KB Output is correct
35 Correct 683 ms 62524 KB Output is correct
36 Correct 889 ms 62524 KB Output is correct
37 Correct 242 ms 62524 KB Output is correct
38 Correct 257 ms 62524 KB Output is correct
39 Correct 550 ms 62524 KB Output is correct
40 Correct 453 ms 62524 KB Output is correct
41 Correct 314 ms 62524 KB Output is correct
42 Correct 382 ms 62524 KB Output is correct
43 Correct 285 ms 62524 KB Output is correct
44 Correct 504 ms 62524 KB Output is correct
45 Correct 320 ms 62524 KB Output is correct
46 Correct 327 ms 62524 KB Output is correct
47 Correct 459 ms 62524 KB Output is correct
48 Correct 469 ms 62524 KB Output is correct
49 Correct 439 ms 62524 KB Output is correct
50 Correct 431 ms 62524 KB Output is correct
51 Correct 690 ms 62524 KB Output is correct
52 Correct 619 ms 62524 KB Output is correct
53 Correct 855 ms 62524 KB Output is correct
54 Correct 695 ms 62524 KB Output is correct
55 Correct 426 ms 62524 KB Output is correct
56 Correct 608 ms 62524 KB Output is correct
57 Correct 629 ms 62524 KB Output is correct
58 Correct 800 ms 62524 KB Output is correct
59 Correct 458 ms 62524 KB Output is correct