Submission #1059057

# Submission time Handle Problem Language Result Execution time Memory
1059057 2024-08-14T16:32:44 Z andrei_iorgulescu Horses (IOI15_horses) C++14
100 / 100
1310 ms 51028 KB
#include <bits/stdc++.h>
#include "horses.h"

using namespace std;

using ll = long long;

int modulo = (int)1e9 + 7;

int lgpow(int lul1, int lul2)
{
    int lul3 = 1;
    while (lul2 != 0)
    {
        if (lul2 % 2 == 1)
            lul3 = 1ll * lul3 * lul1 % modulo;
        lul1 = 1ll * lul1 * lul1 % modulo;
        lul2 /= 2;
    }
    return lul3;
}

int x[500005], y[500005];
int n;
set<int> grx;
int aint[2000005];
ll allx = 1;

void build(int nod, int l, int r)
{
    if (l == r)
        aint[nod] = y[l];
    else
    {
        int mij = (l + r) / 2;
        build(2 * nod,l,mij);
        build(2 * nod + 1,mij + 1,r);
        aint[nod] = max(aint[2 * nod], aint[2 * nod + 1]);
    }
}

void update(int nod, int l, int r, int pos, int val)
{
    if (l == r)
        aint[nod] = val;
    else
    {
        int mij = (l + r) / 2;
        if (pos <= mij)
            update(2 * nod,l,mij,pos,val);
        else
            update(2 * nod + 1,mij + 1,r,pos,val);
        aint[nod] = max(aint[2 * nod], aint[2 * nod + 1]);
    }
}

int query(int nod, int l, int r, int st, int dr)
{
    if (r < st or dr < l)
        return 0;
    if (st <= l and r <= dr)
        return aint[nod];
    int mij = (l + r) / 2;
    return max(query(2 * nod,l,mij,st,dr), query(2 * nod + 1,mij + 1,r,st,dr));
}

int solve()
{
    vector<pair<ll, pair<int,int>>> candi;
    vector<int> depus;
    ll prd = 1;
    int r = n;
    while (!grx.empty() and prd < (int)1e9)
    {
        int l = *grx.rbegin();
        candi.push_back({x[l], {l,r}});
        depus.push_back(l);
        grx.erase(l);
        prd *= (ll)x[l];
        r = l - 1;
    }
    if (prd < (int)1e9 and r >= 1)
        candi.push_back({1,{1,r}});
    reverse(candi.begin(),candi.end());
    for (int i = 0; i + 1 < candi.size(); i++)
        candi[i + 1].first *= candi[i].first;
    __int128 ans = 0;
    for (auto it : candi)
    {
        __int128 prr = it.first;
        __int128 prr2 = query(1,1,n,it.second.first,it.second.second);
        prr *= prr2;
        ans = max(ans,prr);
    }
    for (auto it : depus)
        grx.insert(it);
    ans %= modulo;
    ans = ans * allx % modulo;
    prd %= modulo;
    ans = ans * lgpow(prd, modulo - 2) % modulo;
    return ans;
}

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];
    for (int i = 1; i <= n; i++)
        if (x[i] > 1)
            grx.insert(i), allx = allx * x[i] % modulo;
    build(1,1,n);
    return solve();
}

int updateX(int pos, int val)
{
    pos++;
    allx *= lgpow(x[pos], modulo - 2);
    allx %= modulo;
    if (x[pos] > 1)
        grx.erase(pos);
    x[pos] = val;
    if (x[pos] > 1)
        grx.insert(pos);
    allx = allx * val % modulo;
    return solve();
}

int updateY(int pos, int val)
{
    pos++;
    update(1,1,n,pos,val);
    return solve();
}

Compilation message

horses.cpp: In function 'int lgpow(int, int)':
horses.cpp:16:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   16 |             lul3 = 1ll * lul3 * lul1 % modulo;
      |                    ~~~~~~~~~~~~~~~~~~^~~~~~~~
horses.cpp:17:34: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   17 |         lul1 = 1ll * lul1 * lul1 % modulo;
      |                ~~~~~~~~~~~~~~~~~~^~~~~~~~
horses.cpp: In function 'int solve()':
horses.cpp:85:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for (int i = 0; i + 1 < candi.size(); i++)
      |                     ~~~~~~^~~~~~~~~~~~~~
horses.cpp:100:23: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  100 |     ans = ans * lgpow(prd, modulo - 2) % modulo;
      |                       ^~~
horses.cpp:101:12: warning: conversion from '__int128' to 'int' may change value [-Wconversion]
  101 |     return ans;
      |            ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 0 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4492 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4532 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 0 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 0 ms 4444 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 0 ms 4444 KB Output is correct
23 Correct 2 ms 4444 KB Output is correct
24 Correct 1 ms 4588 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 4 ms 4444 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4636 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 3 ms 4556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1298 ms 38420 KB Output is correct
2 Correct 226 ms 39912 KB Output is correct
3 Correct 288 ms 42320 KB Output is correct
4 Correct 324 ms 46144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4540 KB Output is correct
10 Correct 0 ms 4512 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4696 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 0 ms 2392 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 0 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 1 ms 4580 KB Output is correct
27 Correct 4 ms 4444 KB Output is correct
28 Correct 4 ms 4556 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 3 ms 4444 KB Output is correct
32 Correct 4 ms 4444 KB Output is correct
33 Correct 27 ms 18072 KB Output is correct
34 Correct 24 ms 18012 KB Output is correct
35 Correct 166 ms 48344 KB Output is correct
36 Correct 123 ms 48208 KB Output is correct
37 Correct 80 ms 16268 KB Output is correct
38 Correct 94 ms 28944 KB Output is correct
39 Correct 19 ms 16128 KB Output is correct
40 Correct 112 ms 43344 KB Output is correct
41 Correct 42 ms 16140 KB Output is correct
42 Correct 53 ms 16212 KB Output is correct
43 Correct 104 ms 43712 KB Output is correct
44 Correct 101 ms 43660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4536 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 0 ms 4696 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 0 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 4 ms 4560 KB Output is correct
28 Correct 3 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 3 ms 4588 KB Output is correct
32 Correct 3 ms 4444 KB Output is correct
33 Correct 1310 ms 42324 KB Output is correct
34 Correct 243 ms 51028 KB Output is correct
35 Correct 261 ms 42068 KB Output is correct
36 Correct 324 ms 46112 KB Output is correct
37 Correct 28 ms 18012 KB Output is correct
38 Correct 24 ms 17988 KB Output is correct
39 Correct 145 ms 48468 KB Output is correct
40 Correct 121 ms 48212 KB Output is correct
41 Correct 79 ms 16212 KB Output is correct
42 Correct 109 ms 28944 KB Output is correct
43 Correct 19 ms 15960 KB Output is correct
44 Correct 115 ms 43344 KB Output is correct
45 Correct 39 ms 15960 KB Output is correct
46 Correct 55 ms 16152 KB Output is correct
47 Correct 101 ms 43780 KB Output is correct
48 Correct 100 ms 43840 KB Output is correct
49 Correct 117 ms 20996 KB Output is correct
50 Correct 105 ms 21072 KB Output is correct
51 Correct 408 ms 50156 KB Output is correct
52 Correct 190 ms 49664 KB Output is correct
53 Correct 639 ms 19288 KB Output is correct
54 Correct 446 ms 32904 KB Output is correct
55 Correct 100 ms 17160 KB Output is correct
56 Correct 209 ms 45140 KB Output is correct
57 Correct 298 ms 17748 KB Output is correct
58 Correct 434 ms 18276 KB Output is correct
59 Correct 101 ms 43856 KB Output is correct