답안 #117718

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
117718 2019-06-17T07:01:26 Z zubec 말 (IOI15_horses) C++14
100 / 100
293 ms 70904 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;


const ll MOD = 1e9+7;
const int N = 500100;
const ll MAX = 2000000000;

int n;

int tmx[N*4], a[N], b[N];

struct node{
    int val, ans;
    ld sum, mx;
};

node combine(node lft, node rgt){
    node res;
    if (lft.mx < lft.sum+rgt.mx){
        res.mx = lft.sum+rgt.mx;
        res.ans = (lft.val*1ll*rgt.ans)%MOD;
    } else {
        res.mx = lft.mx;
        res.ans = lft.ans;
    }
    res.val = (lft.val*1ll*rgt.val)%MOD;
    res.sum = (lft.sum+rgt.sum);
    return res;
}

node t[N*4];

void build(int v, int l, int r){
    if (l == r){
        t[v].val = a[l];
        t[v].sum = log((ld)a[l]);
        t[v].mx = log((ld)a[l])+log((ld)b[l]);
        t[v].ans = a[l]*1ll*b[l]%MOD;
        return;
    }
    int mid = (l+r)>>1;
    build(v+v, l, mid);
    build(v+v+1, mid+1, r);
    t[v] = combine(t[v+v], t[v+v+1]);
}

void update(int v, int l, int r, int pos){
    if (l == r){
        t[v].val = a[l];
        t[v].sum = log((ld)a[l]);
        t[v].mx = log((ld)a[l])+log((ld)b[l]);
        t[v].ans = a[l]*1ll*b[l]%MOD;
        return;
    }
    int mid = (l+r)>>1;
    if (pos <= mid)
        update(v+v, l, mid, pos); else
        update(v+v+1, mid+1, r, pos);
    t[v] = combine(t[v+v], t[v+v+1]);
}

int query(){
    return t[1].ans;
}

int init(int N, int X[], int Y[]) {
    n = N;
    for (int i = 1; i <= n; i++){
        a[i] = X[i-1];
        b[i] = Y[i-1];
    }
    build(1, 1, n);
    return query();
}

int updateX(int pos, int val) {
    ++pos;
    a[pos] = val;
    update(1, 1, n, pos);
    return query();
}

int updateY(int pos, int val) {
    ++pos;
    b[pos] = val;
    update(1, 1, n, pos);
    return query();
}

/**

3
2 1 3
3 4 1
1
2 1 2



*/

Compilation message

horses.cpp: In function 'node combine(node, node)':
horses.cpp:25:40: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         res.ans = (lft.val*1ll*rgt.ans)%MOD;
                   ~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp:30:36: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     res.val = (lft.val*1ll*rgt.val)%MOD;
               ~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'void build(int, int, int)':
horses.cpp:42:33: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         t[v].ans = a[l]*1ll*b[l]%MOD;
                    ~~~~~~~~~~~~~^~~~
horses.cpp: In function 'void update(int, int, int, int)':
horses.cpp:56:33: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         t[v].ans = a[l]*1ll*b[l]%MOD;
                    ~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:70:33: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 int init(int N, int X[], int Y[]) {
                                 ^
horses.cpp:9:11: note: shadowed declaration is here
 const int N = 500100;
           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 284 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 484 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 58512 KB Output is correct
2 Correct 268 ms 58424 KB Output is correct
3 Correct 259 ms 62236 KB Output is correct
4 Correct 252 ms 66040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 356 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 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 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 149 ms 61432 KB Output is correct
34 Correct 150 ms 61516 KB Output is correct
35 Correct 137 ms 68472 KB Output is correct
36 Correct 138 ms 68344 KB Output is correct
37 Correct 149 ms 59640 KB Output is correct
38 Correct 127 ms 60488 KB Output is correct
39 Correct 139 ms 59512 KB Output is correct
40 Correct 132 ms 63392 KB Output is correct
41 Correct 138 ms 59640 KB Output is correct
42 Correct 138 ms 59656 KB Output is correct
43 Correct 129 ms 63832 KB Output is correct
44 Correct 127 ms 63832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 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 3 ms 512 KB Output is correct
26 Correct 3 ms 484 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 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 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 168 ms 62280 KB Output is correct
34 Correct 271 ms 70904 KB Output is correct
35 Correct 293 ms 62212 KB Output is correct
36 Correct 289 ms 66040 KB Output is correct
37 Correct 157 ms 61404 KB Output is correct
38 Correct 213 ms 61560 KB Output is correct
39 Correct 140 ms 68472 KB Output is correct
40 Correct 143 ms 68400 KB Output is correct
41 Correct 149 ms 59736 KB Output is correct
42 Correct 123 ms 60536 KB Output is correct
43 Correct 140 ms 59508 KB Output is correct
44 Correct 164 ms 63480 KB Output is correct
45 Correct 143 ms 59720 KB Output is correct
46 Correct 140 ms 59688 KB Output is correct
47 Correct 130 ms 63820 KB Output is correct
48 Correct 130 ms 63736 KB Output is correct
49 Correct 273 ms 63480 KB Output is correct
50 Correct 273 ms 63480 KB Output is correct
51 Correct 187 ms 70368 KB Output is correct
52 Correct 185 ms 69752 KB Output is correct
53 Correct 274 ms 61816 KB Output is correct
54 Correct 184 ms 62640 KB Output is correct
55 Correct 193 ms 60536 KB Output is correct
56 Correct 195 ms 65272 KB Output is correct
57 Correct 205 ms 61356 KB Output is correct
58 Correct 203 ms 61760 KB Output is correct
59 Correct 132 ms 63736 KB Output is correct