답안 #1092003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092003 2024-09-22T19:53:37 Z triplem5ds 말 (IOI15_horses) C++14
100 / 100
1310 ms 60868 KB
#include "horses.h"
#include "bits/stdc++.h"
using namespace std;


const int MOD = 1e9 + 7;
const int N = 5e5 + 5;

struct segTreeNode
{
    int mulX;
    int maxY;
    segTreeNode(int _mulX = 0, int _maxY = 0) : mulX(_mulX), maxY(_maxY) {}
    friend segTreeNode operator + (segTreeNode a, segTreeNode b) {
        return segTreeNode(
            1ll * a.mulX * b.mulX % MOD,
            max(a.maxY, b.maxY)
        );
    }
};

int x[N], y[N], n;
segTreeNode tree[N << 2];
set<int> hotPoints;

void build(int node, int s, int e) {
    if (s == e) {
        tree[node] = segTreeNode(x[s], y[s]);
        return;
    }
    int md = (s + e) >> 1;
    build(node << 1, s, md);
    build(node << 1 | 1, md + 1, e);
    tree[node] = tree[node << 1] + tree[node << 1 | 1];
}

segTreeNode query(int node, int s, int e, int l, int r) {
    if (r < s || e < l)  return segTreeNode(1, 0);
    if (l <= s && e <= r)
        return tree[node];
    int md = (s + e) >> 1;
    return query(node << 1, s, md, l, r) + query(node << 1 | 1, md + 1, e, l, r);
}

void update(int node, int s, int e, int index) {
    if (s == e) {
        tree[node] = segTreeNode(x[s], y[s]);
        return;
    }
    int md = (s + e) >> 1;
    if (index <= md)
        update(node << 1, s, md, index);
    else
        update(node << 1 | 1, md + 1, e, index);
    tree[node] = tree[node << 1] + tree[node << 1 | 1];
}

int calcAnswer() {
    hotPoints.insert(0);
    vector<array<int, 3>> vec; ///(x, y)
    int prv = n;

    ///Extract last 30 elements
    for (auto it = hotPoints.rbegin(); it != hotPoints.rend() && vec.size() < 60; it++) {
        vec.push_back({
            x[*it],
            query(1, 0, n - 1, *it, prv - 1).maxY,
            *it
            });
        prv = *it;
    }

    reverse(begin(vec), end(vec));  ///reorder to go from first to last

    ///I want to get the best Y
    int choosen = 0;
    long long cur = 1;
    for (int i = 1; i < vec.size(); i++) {
        /*
            I want to get the first j > i such that
            x[i + 1] * ... * x[j] * y[j] > y[i]
        */
        cur = cur * vec[i][0];
        if (cur > vec[choosen][1] || cur * vec[i][1] > vec[choosen][1]) { ///to avoid overflow
            choosen = i;
            cur = 1;
        }
    }

    return 1ll * query(1, 0, n - 1, 0, vec[choosen][2]).mulX * vec[choosen][1] % MOD;
}

int init(int N, int X[], int Y[]) {
    copy(X, X + N, x);
    copy(Y, Y + N, y);
    n = N;
    build(1, 0, N - 1);
    for (int i = 0; i < N; i++) {
        if (X[i] > 1) hotPoints.insert(i);
    }
    return calcAnswer();
}

int updateX(int pos, int val) {
    if (x[pos] > 1)hotPoints.erase(pos);
    x[pos] = val;
    if (x[pos] > 1)hotPoints.insert(pos);
    update(1, 0, n - 1, pos);
    return calcAnswer();
}

int updateY(int pos, int val) {
    y[pos] = val;
    update(1, 0, n - 1, pos);
    return calcAnswer();
}


// int main() {
//     int n = 3;
//     int x[] = { 2,1,3 };
//     int y[] = { 3,4,1 };
//     cout << init(n, x, y) << "\n";
//     cout << updateY(1, 2) << "\n";

// }

Compilation message

horses.cpp: In function 'segTreeNode operator+(segTreeNode, segTreeNode)':
horses.cpp:16:35: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   16 |             1ll * a.mulX * b.mulX % MOD,
      |             ~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int calcAnswer()':
horses.cpp:78:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for (int i = 1; i < vec.size(); i++) {
      |                     ~~^~~~~~~~~~~~
horses.cpp:90:80: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   90 |     return 1ll * query(1, 0, n - 1, 0, vec[choosen][2]).mulX * vec[choosen][1] % MOD;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:93:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   93 | int init(int N, int X[], int Y[]) {
      |          ~~~~^
horses.cpp:7:11: note: shadowed declaration is here
    7 | const int N = 5e5 + 5;
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15960 KB Output is correct
2 Correct 7 ms 15964 KB Output is correct
3 Correct 7 ms 16064 KB Output is correct
4 Correct 7 ms 15964 KB Output is correct
5 Correct 9 ms 15964 KB Output is correct
6 Correct 6 ms 15964 KB Output is correct
7 Correct 7 ms 15964 KB Output is correct
8 Correct 6 ms 15964 KB Output is correct
9 Correct 7 ms 15964 KB Output is correct
10 Correct 7 ms 15964 KB Output is correct
11 Correct 6 ms 15964 KB Output is correct
12 Correct 6 ms 15964 KB Output is correct
13 Correct 6 ms 15964 KB Output is correct
14 Correct 6 ms 15964 KB Output is correct
15 Correct 6 ms 15964 KB Output is correct
16 Correct 7 ms 16096 KB Output is correct
17 Correct 6 ms 15960 KB Output is correct
18 Correct 7 ms 15964 KB Output is correct
19 Correct 6 ms 16096 KB Output is correct
20 Correct 6 ms 15960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15964 KB Output is correct
2 Correct 6 ms 16008 KB Output is correct
3 Correct 6 ms 15964 KB Output is correct
4 Correct 8 ms 15964 KB Output is correct
5 Correct 7 ms 15984 KB Output is correct
6 Correct 7 ms 15964 KB Output is correct
7 Correct 8 ms 16088 KB Output is correct
8 Correct 6 ms 16008 KB Output is correct
9 Correct 7 ms 15964 KB Output is correct
10 Correct 7 ms 16016 KB Output is correct
11 Correct 6 ms 15964 KB Output is correct
12 Correct 6 ms 16100 KB Output is correct
13 Correct 6 ms 15964 KB Output is correct
14 Correct 7 ms 15964 KB Output is correct
15 Correct 7 ms 15964 KB Output is correct
16 Correct 7 ms 16216 KB Output is correct
17 Correct 7 ms 15964 KB Output is correct
18 Correct 6 ms 16112 KB Output is correct
19 Correct 6 ms 15964 KB Output is correct
20 Correct 6 ms 15964 KB Output is correct
21 Correct 7 ms 15964 KB Output is correct
22 Correct 7 ms 15960 KB Output is correct
23 Correct 13 ms 16012 KB Output is correct
24 Correct 12 ms 15976 KB Output is correct
25 Correct 12 ms 15964 KB Output is correct
26 Correct 13 ms 16072 KB Output is correct
27 Correct 12 ms 15960 KB Output is correct
28 Correct 12 ms 15964 KB Output is correct
29 Correct 7 ms 16048 KB Output is correct
30 Correct 14 ms 16188 KB Output is correct
31 Correct 8 ms 15964 KB Output is correct
32 Correct 10 ms 15964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1092 ms 52048 KB Output is correct
2 Correct 1199 ms 60784 KB Output is correct
3 Correct 1201 ms 51980 KB Output is correct
4 Correct 1234 ms 56120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 15964 KB Output is correct
2 Correct 7 ms 15964 KB Output is correct
3 Correct 7 ms 15920 KB Output is correct
4 Correct 7 ms 15964 KB Output is correct
5 Correct 7 ms 15964 KB Output is correct
6 Correct 8 ms 15964 KB Output is correct
7 Correct 7 ms 16104 KB Output is correct
8 Correct 6 ms 15964 KB Output is correct
9 Correct 7 ms 15984 KB Output is correct
10 Correct 7 ms 15964 KB Output is correct
11 Correct 7 ms 15964 KB Output is correct
12 Correct 6 ms 15964 KB Output is correct
13 Correct 7 ms 15968 KB Output is correct
14 Correct 6 ms 15964 KB Output is correct
15 Correct 7 ms 15964 KB Output is correct
16 Correct 8 ms 16024 KB Output is correct
17 Correct 7 ms 15964 KB Output is correct
18 Correct 7 ms 15964 KB Output is correct
19 Correct 6 ms 15964 KB Output is correct
20 Correct 7 ms 15964 KB Output is correct
21 Correct 7 ms 15964 KB Output is correct
22 Correct 7 ms 15964 KB Output is correct
23 Correct 13 ms 15964 KB Output is correct
24 Correct 12 ms 15964 KB Output is correct
25 Correct 11 ms 16140 KB Output is correct
26 Correct 11 ms 15980 KB Output is correct
27 Correct 13 ms 15960 KB Output is correct
28 Correct 11 ms 15964 KB Output is correct
29 Correct 6 ms 15960 KB Output is correct
30 Correct 12 ms 15964 KB Output is correct
31 Correct 9 ms 15964 KB Output is correct
32 Correct 11 ms 16240 KB Output is correct
33 Correct 171 ms 27844 KB Output is correct
34 Correct 132 ms 27916 KB Output is correct
35 Correct 242 ms 58192 KB Output is correct
36 Correct 247 ms 58192 KB Output is correct
37 Correct 162 ms 26452 KB Output is correct
38 Correct 168 ms 38992 KB Output is correct
39 Correct 31 ms 25948 KB Output is correct
40 Correct 239 ms 53388 KB Output is correct
41 Correct 57 ms 25940 KB Output is correct
42 Correct 73 ms 25948 KB Output is correct
43 Correct 143 ms 53636 KB Output is correct
44 Correct 144 ms 53544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 15964 KB Output is correct
2 Correct 6 ms 15964 KB Output is correct
3 Correct 7 ms 15964 KB Output is correct
4 Correct 7 ms 15964 KB Output is correct
5 Correct 7 ms 15964 KB Output is correct
6 Correct 7 ms 15960 KB Output is correct
7 Correct 10 ms 15964 KB Output is correct
8 Correct 6 ms 16088 KB Output is correct
9 Correct 6 ms 16100 KB Output is correct
10 Correct 7 ms 16100 KB Output is correct
11 Correct 6 ms 15880 KB Output is correct
12 Correct 6 ms 15964 KB Output is correct
13 Correct 6 ms 15964 KB Output is correct
14 Correct 6 ms 15964 KB Output is correct
15 Correct 7 ms 15964 KB Output is correct
16 Correct 6 ms 15964 KB Output is correct
17 Correct 8 ms 15964 KB Output is correct
18 Correct 7 ms 16100 KB Output is correct
19 Correct 7 ms 15960 KB Output is correct
20 Correct 6 ms 16012 KB Output is correct
21 Correct 7 ms 15964 KB Output is correct
22 Correct 6 ms 15964 KB Output is correct
23 Correct 13 ms 16216 KB Output is correct
24 Correct 11 ms 15964 KB Output is correct
25 Correct 12 ms 15964 KB Output is correct
26 Correct 13 ms 15964 KB Output is correct
27 Correct 11 ms 16080 KB Output is correct
28 Correct 12 ms 15960 KB Output is correct
29 Correct 6 ms 15948 KB Output is correct
30 Correct 12 ms 16104 KB Output is correct
31 Correct 8 ms 16116 KB Output is correct
32 Correct 10 ms 16060 KB Output is correct
33 Correct 1078 ms 52196 KB Output is correct
34 Correct 1166 ms 60868 KB Output is correct
35 Correct 1165 ms 52052 KB Output is correct
36 Correct 1254 ms 55896 KB Output is correct
37 Correct 184 ms 28040 KB Output is correct
38 Correct 128 ms 27856 KB Output is correct
39 Correct 245 ms 58448 KB Output is correct
40 Correct 260 ms 58128 KB Output is correct
41 Correct 167 ms 26196 KB Output is correct
42 Correct 168 ms 38996 KB Output is correct
43 Correct 32 ms 25940 KB Output is correct
44 Correct 238 ms 53328 KB Output is correct
45 Correct 58 ms 25824 KB Output is correct
46 Correct 73 ms 26012 KB Output is correct
47 Correct 138 ms 53588 KB Output is correct
48 Correct 142 ms 53604 KB Output is correct
49 Correct 1310 ms 30904 KB Output is correct
50 Correct 1039 ms 30936 KB Output is correct
51 Correct 1136 ms 60068 KB Output is correct
52 Correct 1129 ms 59696 KB Output is correct
53 Correct 1296 ms 29356 KB Output is correct
54 Correct 1104 ms 42872 KB Output is correct
55 Correct 131 ms 26964 KB Output is correct
56 Correct 1219 ms 55200 KB Output is correct
57 Correct 394 ms 27700 KB Output is correct
58 Correct 552 ms 28164 KB Output is correct
59 Correct 141 ms 53588 KB Output is correct