답안 #316312

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
316312 2020-10-25T19:52:59 Z mohamedsobhi777 말 (IOI15_horses) C++17
100 / 100
1234 ms 43076 KB
#include "horses.h"
#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

const int _N = 5e5 + 7, mod = 1e9 + 7;
const ll inf = 2e18;
int n, m;
int X[_N], Y[_N];
set<int> st;
pii tree[_N * 4];
ll a42 = 1ll;
double l42;
int invs[_N];

void update(int node, int L, int R, int ix, int val)
{
        if (L == R)
        {
                tree[node] = {val, ix - 1};
                return;
        }
        int mid = (L + R) >> 1;
        if (ix <= mid)
                update(node * 2 + 1, L, mid, ix, val);
        else
                update(node * 2 + 2, mid + 1, R, ix, val);
        tree[node] = max(tree[node * 2 + 1], tree[node * 2 + 2]);
}

pii query(int node, int L, int R, int l, int r)
{
        if (l > r || l > R || r < L)
                return {-1, -1};
        if (L >= l && R <= r)
                return tree[node];
        int mid = (L + R) >> 1;
        pii s1 = query(node * 2 + 1, L, mid, l, r);
        pii s2 = query(node * 2 + 2, mid + 1, R, l, r);
        return max(s1, s2);
}

inline int mul(int x, int y) { return 1ll * x * y % mod; }
int faspow(int x, int y)
{
        if (!y)
                return 1ll;
        int ret = faspow(x, y / 2);
        ret = 1ll * ret * ret % mod;
        if (y & 1)
                ret = 1ll * ret * x % mod;
        return ret;
}
inline int inv(ll x) { return faspow(x, mod - 2); }

void add(int x, ll v, ll old = 1ll)
{
        ++x;
        int nv = mul(v, invs[x - 1]);
        invs[x - 1] = inv(v);
        a42 = mul(a42, nv);
        l42 += log(v) - log(old);
}

int solve()
{
        double mx = 0;
        double lg = 0;
        vector<int> indi;
        int rem = 1ll;
        if (st.size())
        {
                auto it = st.end();
                --it;
                int sz = (int)st.size();
                while (sz--)
                {
                        lg += log(X[(*it)]);
                        int de = (*it);
                        if (de)
                        {
                                rem = mul(rem, invs[*it]);
                                indi.push_back(*it);
                        }
                        if (lg > log(1e9))
                                break;
                        --it;
                }
        }
        double tot = l42 - lg;
        indi.push_back(0);
        rem = mul(rem, inv(X[0]));
        int now = mul(a42, rem);
        int ret = 1ll;
        for (int x = indi.size() - 1; ~x; --x)
        {
                int u = indi[x];
                tot += log(X[u]);
                now = mul(now, X[u]);
                pii gmax = query(0, 1, _N, u + 1, (!x ? n : indi[x - 1] + 1));
                if (tot + log(gmax.first) > mx)
                {
                        ret = mul(now, Y[gmax.second]);
                        mx = tot + log(gmax.first);
                }
        }
        return ret;
}

void putit(int x, int val)
{
        if (val > 1)
                st.insert(x);
        else
        {
                st.erase(x);
        }
}

int init(int N, int _X[], int _Y[])
{
        n = N;
        for (int i = 0; i < N; ++i)
        {
                invs[i] = 1ll;
                add(i, _X[i]);
                putit(i, _X[i]);
                update(0, 1, _N, i + 1, _Y[i]);
                X[i] = _X[i];
                Y[i] = _Y[i];
        }
        return solve();
}

int updateX(int pos, int val)
{
        add(pos, val, X[pos]);
        putit(pos, val);
        X[pos] = val;
        return solve();
}

int updateY(int pos, int val)
{
        Y[pos] = val;
        update(0, 1, _N, pos + 1, val);
        return solve();
}

Compilation message

horses.cpp: In function 'int mul(int, int)':
horses.cpp:48:51: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   48 | inline int mul(int x, int y) { return 1ll * x * y % mod; }
      |                                       ~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int faspow(int, int)':
horses.cpp:54:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   54 |         ret = 1ll * ret * ret % mod;
      |               ~~~~~~~~~~~~~~~~^~~~~
horses.cpp:56:37: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   56 |                 ret = 1ll * ret * x % mod;
      |                       ~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int inv(ll)':
horses.cpp:59:38: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   59 | inline int inv(ll x) { return faspow(x, mod - 2); }
      |                                      ^
horses.cpp: In function 'void add(int, ll, ll)':
horses.cpp:64:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   64 |         int nv = mul(v, invs[x - 1]);
      |                      ^
horses.cpp:66:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   66 |         a42 = mul(a42, nv);
      |                   ^~~
horses.cpp: In function 'int solve()':
horses.cpp:98:23: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   98 |         int now = mul(a42, rem);
      |                       ^~~
horses.cpp:100:34: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
  100 |         for (int x = indi.size() - 1; ~x; --x)
      |                      ~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 10 ms 384 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 10 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1219 ms 42964 KB Output is correct
2 Correct 665 ms 43000 KB Output is correct
3 Correct 685 ms 42872 KB Output is correct
4 Correct 821 ms 42872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 10 ms 384 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 9 ms 384 KB Output is correct
33 Correct 294 ms 18552 KB Output is correct
34 Correct 289 ms 18552 KB Output is correct
35 Correct 449 ms 41848 KB Output is correct
36 Correct 431 ms 41976 KB Output is correct
37 Correct 359 ms 18680 KB Output is correct
38 Correct 397 ms 30456 KB Output is correct
39 Correct 271 ms 18424 KB Output is correct
40 Correct 419 ms 42104 KB Output is correct
41 Correct 309 ms 18424 KB Output is correct
42 Correct 332 ms 18680 KB Output is correct
43 Correct 398 ms 41848 KB Output is correct
44 Correct 401 ms 41848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 416 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 416 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 10 ms 492 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 10 ms 384 KB Output is correct
33 Correct 1222 ms 42816 KB Output is correct
34 Correct 667 ms 42872 KB Output is correct
35 Correct 685 ms 43076 KB Output is correct
36 Correct 813 ms 42872 KB Output is correct
37 Correct 293 ms 18552 KB Output is correct
38 Correct 286 ms 18496 KB Output is correct
39 Correct 458 ms 42060 KB Output is correct
40 Correct 432 ms 41988 KB Output is correct
41 Correct 357 ms 18552 KB Output is correct
42 Correct 399 ms 30456 KB Output is correct
43 Correct 273 ms 18296 KB Output is correct
44 Correct 417 ms 41976 KB Output is correct
45 Correct 307 ms 18408 KB Output is correct
46 Correct 333 ms 18424 KB Output is correct
47 Correct 396 ms 41848 KB Output is correct
48 Correct 400 ms 41848 KB Output is correct
49 Correct 515 ms 20600 KB Output is correct
50 Correct 477 ms 20564 KB Output is correct
51 Correct 710 ms 42788 KB Output is correct
52 Correct 584 ms 42872 KB Output is correct
53 Correct 1234 ms 20576 KB Output is correct
54 Correct 786 ms 33528 KB Output is correct
55 Correct 449 ms 18552 KB Output is correct
56 Correct 595 ms 43072 KB Output is correct
57 Correct 821 ms 19448 KB Output is correct
58 Correct 1042 ms 19320 KB Output is correct
59 Correct 399 ms 41900 KB Output is correct