답안 #552865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
552865 2022-04-24T08:14:52 Z elazarkoren 말 (IOI15_horses) C++17
100 / 100
458 ms 65632 KB
#include "horses.h"
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
//#define int ll
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;

const int MAX_N = 5e5 + 5;
const int mod = 1e9 + 7;
const int infinity = 1e9;

struct Seg {
    int n;
    vi seg;
    vb moded;
    Seg () {}
    Seg (int m) {
        for (n = 1; n < m; n <<= 1);
        seg.resize(2 * n, 1);
        moded.resize(2 * n);
    }
    void pull(int i) {
        seg[i] = seg[i << 1] * seg[i << 1 | 1];
        moded[i] = moded[i << 1] | moded[i << 1 | 1];
    }
    void update(int i, ll x) {
        seg[i += n] = x;
        for (i >>= 1; i; i >>= 1) {
            pull(i);
            if (seg[i] >= mod) {
                moded[i] = true;
                seg[i] %= mod;
            }
        }
    }
    pair<ll, bool> query(int l, int r) {
        pair<ll, bool> p = {1, false};
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) {
                p.x *= seg[l];
                p.y |= moded[l];
                l++;
            }
            if (r & 1) {
                r--;
                p.x *= seg[r];
                p.y |= moded[r];
            }
            if (p.x >= mod) {
                p.y = true;
                p.x %= mod;
            }
        }
        return p;
    }
};

struct SegMax {
    int n;
    vi seg;
    SegMax () {}
    SegMax (int m) {
        for (n = 1; n < m; n <<= 1);
        seg.resize(2 * n);
    }
    void update(int i, int x) {
        seg[i += n] = x;
        for (i >>= 1; i; i >>= 1) {
            seg[i] = max(seg[i << 1], seg[i << 1 | 1]);
        }
    }
    ll query(int l, int r) {
        ll ans = 0;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) chkmax(ans, seg[l++]);
            if (r & 1) chkmax(ans, seg[--r]);
        }
        return ans;
    }
};

int n;
ll x[MAX_N], y[MAX_N];
set<int, greater<int>> changed;

Seg seg;
SegMax seg_max;

int Solve() {
    pii best = {0, 0};
    int cnt = 30;
    int last = n;
    changed.insert(0);
    ll add = 1;
    for (int i : changed) {
        if (!(cnt--)) break;
        ll y1 = seg_max.query(i, last), y2 = seg_max.query(best.x, best.y);
        if (y1 > add * y2) {
            best = {i, last};
            add = 1;
        }
        add *= x[i];
        if (add >= mod) break;
        last = i;
    }
    ll x1 = seg.query(0, best.x + 1).x;
    ll y1 = seg_max.query(best.x, best.y);
    return x1 * y1 % mod;
}

int32_t init(int32_t N, int32_t X[], int32_t Y[]) {
    n = N;
    seg = Seg(n);
    seg_max = SegMax(n);
    for (int i = 0; i < n; i++) {
        x[i] = X[i], y[i] = Y[i];
        if (x[i] != 1) changed.insert(i);
        seg.update(i, x[i]);
        seg_max.update(i, y[i]);
    }
    return Solve();
}

int32_t updateX(int32_t pos, int32_t val) {
    if (x[pos] != 1) changed.erase(changed.find(pos));
    x[pos] = val;
    if (x[pos] != 1) changed.insert(pos);
    seg.update(pos, x[pos]);
    return Solve();
}

int32_t updateY(int32_t pos, int32_t val) {
    y[pos] = val;
    seg_max.update(pos, val);
    return Solve();
}

//3
//2 1 3
//3 4 1
//1
//2 1 2

Compilation message

horses.cpp: In function 'int Solve()':
horses.cpp:117:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  117 |     return x1 * y1 % mod;
      |            ~~~~~~~~^~~~~
horses.cpp: In function 'int32_t init(int32_t, int32_t*, int32_t*)':
horses.cpp:128:30: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  128 |         seg_max.update(i, y[i]);
      |                              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 452 KB Output is correct
26 Correct 2 ms 452 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 324 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 272 ms 53060 KB Output is correct
2 Correct 385 ms 53028 KB Output is correct
3 Correct 342 ms 53044 KB Output is correct
4 Correct 458 ms 52988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 244 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 98 ms 32656 KB Output is correct
34 Correct 95 ms 32676 KB Output is correct
35 Correct 312 ms 62992 KB Output is correct
36 Correct 293 ms 62996 KB Output is correct
37 Correct 102 ms 30804 KB Output is correct
38 Correct 164 ms 43672 KB Output is correct
39 Correct 103 ms 30668 KB Output is correct
40 Correct 336 ms 58136 KB Output is correct
41 Correct 85 ms 30736 KB Output is correct
42 Correct 93 ms 30700 KB Output is correct
43 Correct 313 ms 58380 KB Output is correct
44 Correct 288 ms 58440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 316 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 315 ms 56896 KB Output is correct
34 Correct 434 ms 65632 KB Output is correct
35 Correct 373 ms 56900 KB Output is correct
36 Correct 457 ms 60692 KB Output is correct
37 Correct 98 ms 32724 KB Output is correct
38 Correct 125 ms 32788 KB Output is correct
39 Correct 301 ms 62940 KB Output is correct
40 Correct 290 ms 62956 KB Output is correct
41 Correct 100 ms 30852 KB Output is correct
42 Correct 192 ms 43656 KB Output is correct
43 Correct 96 ms 30636 KB Output is correct
44 Correct 256 ms 58024 KB Output is correct
45 Correct 104 ms 30648 KB Output is correct
46 Correct 99 ms 30728 KB Output is correct
47 Correct 248 ms 58448 KB Output is correct
48 Correct 274 ms 58468 KB Output is correct
49 Correct 223 ms 35792 KB Output is correct
50 Correct 156 ms 35652 KB Output is correct
51 Correct 384 ms 64860 KB Output is correct
52 Correct 324 ms 64316 KB Output is correct
53 Correct 240 ms 34056 KB Output is correct
54 Correct 228 ms 47528 KB Output is correct
55 Correct 168 ms 31748 KB Output is correct
56 Correct 324 ms 59788 KB Output is correct
57 Correct 145 ms 32308 KB Output is correct
58 Correct 181 ms 32760 KB Output is correct
59 Correct 263 ms 58412 KB Output is correct