답안 #310670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
310670 2020-10-07T15:10:37 Z talant117408 말 (IOI15_horses) C++17
100 / 100
205 ms 39036 KB
#include "horses.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) (int)(v).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const ll mod = 1e9+7;
const int mxn = 5e5+7;
int x[mxn], y[mxn];
int n;

struct Node{
    int x, y;
    double _x, _y;
};

int mult(int a, int b){
    return (ll(a)*ll(b))%mod;
}

Node combine(Node a, Node b){
    Node res;
    
    if(a._y > a._x+b._y){
        res.y = a.y;
        res._y = a._y;
    }
    else{
        res.y = mult(a.x, b.y);
        res._y = a._x+b._y;
    }
    res.x = mult(a.x, b.x);
    res._x = a._x+b._x;
    
    return res;
}

struct Tree{
    Node tree[mxn*3];
    
    void build(int v, int l, int r){
        if(l == r){
            tree[v].x = x[l];
            tree[v].y = mult(y[l], x[l]);
            tree[v]._x = log2(x[l]);
            tree[v]._y = log2(y[l])+log2(x[l]);
            return;
        }
        int mid = (l+r) >> 1;
        build(v<<1, l, mid);
        build((v<<1)+1, mid+1, r);
        tree[v] = combine(tree[v<<1], tree[(v<<1)+1]);
    }
    
    void update(int v, int l, int r, int pos){
        if(pos == l && r == l){
            tree[v].x = x[l];
            tree[v].y = mult(y[l], x[l]);
            tree[v]._x = log2(x[l]);
            tree[v]._y = log2(y[l])+log2(x[l]);
            return;
        }
        int mid = (l+r) >> 1;
        if(pos <= mid){
            update(v<<1, l, mid, pos);
        }
        else{
            update((v<<1)+1, mid+1, r, pos);
        }
        tree[v] = combine(tree[v<<1], tree[(v<<1)+1]);
    }
    
    int query(){
        return tree[1].y;
    }
} tree;

int init(int N, int X[], int Y[]) {
    n = N; 
    for(int i = 0; i < n; i++){
        x[i] = X[i];
        y[i] = Y[i];
    }
    tree.build(1, 0, n-1);
    
    return tree.query();
}

int updateX(int pos, int val){
    x[pos] = val;
    tree.update(1, 0, n-1, pos);
    
	return tree.query();
}

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

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

8
6
*/

Compilation message

horses.cpp: In function 'int mult(int, int)':
horses.cpp:33:25: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   33 |     return (ll(a)*ll(b))%mod;
      |            ~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 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 1 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 1 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 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 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 1 ms 384 KB Output is correct
3 Correct 0 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 1 ms 384 KB Output is correct
7 Correct 1 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 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 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
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 444 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 33784 KB Output is correct
2 Correct 205 ms 38264 KB Output is correct
3 Correct 141 ms 36728 KB Output is correct
4 Correct 166 ms 36728 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 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 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 1 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 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 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 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 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 77 ms 34428 KB Output is correct
34 Correct 79 ms 35964 KB Output is correct
35 Correct 111 ms 37116 KB Output is correct
36 Correct 111 ms 37016 KB Output is correct
37 Correct 53 ms 34936 KB Output is correct
38 Correct 74 ms 35832 KB Output is correct
39 Correct 48 ms 34808 KB Output is correct
40 Correct 88 ms 35832 KB Output is correct
41 Correct 48 ms 34936 KB Output is correct
42 Correct 49 ms 34896 KB Output is correct
43 Correct 85 ms 35704 KB Output is correct
44 Correct 84 ms 35704 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 1 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 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 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 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 0 ms 384 KB Output is correct
20 Correct 1 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 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 100 ms 37240 KB Output is correct
34 Correct 204 ms 39036 KB Output is correct
35 Correct 141 ms 36728 KB Output is correct
36 Correct 165 ms 36728 KB Output is correct
37 Correct 77 ms 35844 KB Output is correct
38 Correct 77 ms 35832 KB Output is correct
39 Correct 119 ms 36728 KB Output is correct
40 Correct 109 ms 36728 KB Output is correct
41 Correct 53 ms 34936 KB Output is correct
42 Correct 72 ms 35832 KB Output is correct
43 Correct 48 ms 34808 KB Output is correct
44 Correct 86 ms 35832 KB Output is correct
45 Correct 46 ms 34936 KB Output is correct
46 Correct 46 ms 34936 KB Output is correct
47 Correct 83 ms 35704 KB Output is correct
48 Correct 85 ms 35704 KB Output is correct
49 Correct 161 ms 36728 KB Output is correct
50 Correct 163 ms 36728 KB Output is correct
51 Correct 149 ms 38648 KB Output is correct
52 Correct 142 ms 38136 KB Output is correct
53 Correct 143 ms 36828 KB Output is correct
54 Correct 115 ms 36728 KB Output is correct
55 Correct 83 ms 35960 KB Output is correct
56 Correct 135 ms 36728 KB Output is correct
57 Correct 84 ms 36600 KB Output is correct
58 Correct 87 ms 36856 KB Output is correct
59 Correct 85 ms 35704 KB Output is correct