답안 #726035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
726035 2023-04-18T10:35:45 Z TheSahib 말 (IOI15_horses) C++17
100 / 100
196 ms 38092 KB
#include "horses.h"
#include <bits/stdc++.h>

#define ll long long
#define pii pair<int, ll>

using namespace std;

const int MOD = 1e9 + 7;
const ll oo = 1e9 + 9;
const int MAX = 5e5 + 5;

struct DATA{
    int index, leftMultipliyer, rightMultiplier;
};

int n;
int price[MAX], cnt[MAX];
DATA tree[MAX * 4];


DATA merge(DATA a, DATA b){
    ll m = min(oo, 1ll * a.rightMultiplier * b.leftMultipliyer);
    if(price[a.index] / m >= price[b.index]){
        return {a.index, a.leftMultipliyer, min(oo, m * b.rightMultiplier)};
    }
    else{
        return {b.index, min(oo, m * a.leftMultipliyer), b.rightMultiplier};
    }
}

void build(int node, int l, int r){
    if(l == r){
        tree[node] = {l, cnt[l], 1};
        return;
    }

    int mid = (l + r) / 2;
    build(node << 1 | 1, l, mid);
    build((node + 1) << 1, mid + 1, r);

    tree[node] = merge(tree[(node << 1) | 1], tree[(node + 1) << 1]);
}

void update(int node, int l, int r, int pos, int val){
    if(l == r){
        tree[node] = {l, cnt[l], 1};
        return;
    }
    int mid = (l + r) / 2;
    if(pos <= mid){
        update((node << 1) + 1, l, mid, pos, val);
    }
    else{
        update((node + 1) << 1, mid + 1, r, pos, val);
    }
    tree[node] = merge(tree[(node << 1) | 1], tree[(node + 1) << 1]);
}



int tree1[MAX * 4];

void build2(int node, int l, int r){
    if(l == r){
        tree1[node] = cnt[l];
        return;
    }
    int mid = (l + r) / 2;
    build2((node << 1) + 1, l, mid);
    build2((node + 1) << 1, mid + 1, r);
    tree1[node] = (1ll * tree1[(node << 1) + 1] * tree1[(node + 1) << 1]) % MOD;
}

void update2(int node, int l, int r, int pos, int val){
    if(l == r){
        tree1[node] = val;
        return;
    }
    int mid = (l + r) / 2;
    if(pos <= mid){
        update2((node << 1) + 1, l, mid, pos, val);
    }
    else{
        update2((node + 1) << 1, mid + 1, r, pos, val);
    }
    tree1[node] = (1ll * tree1[(node << 1) + 1] * tree1[(node + 1) << 1]) % MOD;
}

int ask2(int node, int l, int r, int ql, int qr){
    if(qr < l || ql > r){
        return 1;
    }
    if(ql <= l && r <= qr){
        return tree1[node];
    }
    int mid = (l + r) / 2;
    return (1ll * ask2((node << 1) + 1, l, mid, ql, qr) * ask2((node + 1) << 1, mid + 1, r, ql, qr)) % MOD;
}

int calcAns(){
    DATA ans = tree[0];
    return 1ll * ask2(0, 0, n - 1, 0, ans.index) * price[ans.index] % MOD;
}


int init(int N, int X[], int Y[]) {
    n = N;
    for (int i = 0; i < n; i++)
    {
        cnt[i] = X[i];
        price[i] = Y[i];
    }
    build(0, 0, n - 1);
    build2(0, 0, n - 1);
    return calcAns();
}

int updateX(int pos, int val) {	
	cnt[pos] = val;
    update(0, 0, n - 1, pos, cnt[pos]);
    update2(0, 0, n - 1, pos, val);
    return calcAns();
}

int updateY(int pos, int val) {
	price[pos] = val;
    update(0, 0, n - 1, pos, cnt[pos]);
    return calcAns();
}

Compilation message

horses.cpp: In function 'DATA merge(DATA, DATA)':
horses.cpp:25:48: warning: narrowing conversion of '(long long int)std::min<long long int>(oo, (m * ((long long int)b.DATA::rightMultiplier)))' from 'long long int' to 'int' [-Wnarrowing]
   25 |         return {a.index, a.leftMultipliyer, min(oo, m * b.rightMultiplier)};
      |                                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:25:48: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
horses.cpp:28:29: warning: narrowing conversion of '(long long int)std::min<long long int>(oo, (m * ((long long int)a.DATA::leftMultipliyer)))' from 'long long int' to 'int' [-Wnarrowing]
   28 |         return {b.index, min(oo, m * a.leftMultipliyer), b.rightMultiplier};
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:28:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
horses.cpp: In function 'void build2(int, int, int)':
horses.cpp:72:75: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   72 |     tree1[node] = (1ll * tree1[(node << 1) + 1] * tree1[(node + 1) << 1]) % MOD;
      |                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void update2(int, int, int, int, int)':
horses.cpp:87:75: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   87 |     tree1[node] = (1ll * tree1[(node << 1) + 1] * tree1[(node + 1) << 1]) % MOD;
      |                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int ask2(int, int, int, int, int)':
horses.cpp:98:102: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   98 |     return (1ll * ask2((node << 1) + 1, l, mid, ql, qr) * ask2((node + 1) << 1, mid + 1, r, ql, qr)) % MOD;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int calcAns()':
horses.cpp:103:69: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  103 |     return 1ll * ask2(0, 0, n - 1, 0, ans.index) * price[ans.index] % MOD;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 324 KB Output is correct
29 Correct 2 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
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 28240 KB Output is correct
2 Correct 167 ms 38088 KB Output is correct
3 Correct 135 ms 29260 KB Output is correct
4 Correct 185 ms 33148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 308 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 408 KB Output is correct
25 Correct 2 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 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 324 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 57 ms 28328 KB Output is correct
34 Correct 55 ms 28500 KB Output is correct
35 Correct 79 ms 35468 KB Output is correct
36 Correct 77 ms 35396 KB Output is correct
37 Correct 50 ms 26708 KB Output is correct
38 Correct 49 ms 27640 KB Output is correct
39 Correct 42 ms 26636 KB Output is correct
40 Correct 59 ms 30496 KB Output is correct
41 Correct 46 ms 26700 KB Output is correct
42 Correct 43 ms 26736 KB Output is correct
43 Correct 52 ms 30912 KB Output is correct
44 Correct 54 ms 30928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 316 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 340 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 328 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 324 KB Output is correct
27 Correct 1 ms 324 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 324 KB Output is correct
33 Correct 112 ms 29284 KB Output is correct
34 Correct 167 ms 38092 KB Output is correct
35 Correct 134 ms 29284 KB Output is correct
36 Correct 196 ms 33192 KB Output is correct
37 Correct 56 ms 28560 KB Output is correct
38 Correct 56 ms 28496 KB Output is correct
39 Correct 76 ms 35600 KB Output is correct
40 Correct 73 ms 35388 KB Output is correct
41 Correct 45 ms 26768 KB Output is correct
42 Correct 52 ms 27620 KB Output is correct
43 Correct 41 ms 26632 KB Output is correct
44 Correct 56 ms 30480 KB Output is correct
45 Correct 40 ms 26640 KB Output is correct
46 Correct 40 ms 26724 KB Output is correct
47 Correct 51 ms 30908 KB Output is correct
48 Correct 53 ms 30952 KB Output is correct
49 Correct 167 ms 30564 KB Output is correct
50 Correct 172 ms 30504 KB Output is correct
51 Correct 149 ms 37468 KB Output is correct
52 Correct 127 ms 36912 KB Output is correct
53 Correct 154 ms 28944 KB Output is correct
54 Correct 133 ms 29532 KB Output is correct
55 Correct 117 ms 27700 KB Output is correct
56 Correct 140 ms 32380 KB Output is correct
57 Correct 100 ms 28288 KB Output is correct
58 Correct 110 ms 28824 KB Output is correct
59 Correct 53 ms 30892 KB Output is correct