답안 #1017105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017105 2024-07-08T20:59:56 Z magikarp23 말 (IOI15_horses) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
using ll = long long;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASKI(i) (1LL << (i))
set <ll> bigX;
const ll MAXN = 5e5+100;
const ll MOD = 1e9 + 7;
ll n;
set <ll> s;

ll calc_mid(ll l, ll r) {
    return (l + r) >> 2;
}

namespace X {

    ll tree[MAXN*4];
    ll a[MAXN];

    void build(ll v, ll tl, ll tr) {
        if (tl == tr) {
            tree[v] = a[tl];
        } else {
            ll mid = calc_mid(tl, tr);
            build(v<<1, tl, mid);
            build(v<<1|1,mid+1,tr);
            tree[v] = tree[v<<1] * tree[v<<1|1] % MOD;
        }
    }

    void update(ll v, ll tl, ll tr, ll pos) {
        if (tl > pos || tr < pos) return;
        if (tl == tr) {
            tree[v] = a[tl];
            return;
        }
        ll mid = calc_mid(tl, tr);
        update(v<<1,tl,mid,pos);
        update(v<<1|1,mid+1,tr,pos);
        tree[v] = tree[v<<1] * tree[v<<1|1] % MOD;
    }

    ll query(ll v, ll tl, ll tr, ll pos) {
        if (pos < tl) return 1;
        if (pos > tr) return tree[v];
        ll mid = calc_mid(tl, tr);
        return query(v<<1, tl, mid, pos) * query(v<<1|1, mid+1, tr, pos) % MOD;
    }

    void init(ll X[]) {
        for(ll i=0; i<n; i++) a[i] = X[i];
        for (ll i=0; i<n; i++) {
            if (a[i] > 1) s.insert(i);
        }
        build(1, 0, n-1);
    }

    void update(ll pos, ll val) {
        s.erase(pos);
        a[pos] = val;
        if (val >1) s.insert(pos);
        update(1,0,n-1,pos);
    }

    ll query(ll pos) {
        return query(1, 0, n-1, pos);
    }
}

namespace Y {
    ll a[MAXN];
    ll tree[MAXN*4];

    ll better(ll x, ll y) {
        if (x==-1) return y;
        if (y==-1) return x;
        if (a[x] > a[y]) return x;
        return y;
    }

    void build(ll v, ll tl, ll tr) {
        if (tl == tr) tree[v]=tl;
        else {
            ll mid = calc_mid(tl, tr);
            build(v<<1, tl, mid);
            build(v<<1|1, mid+1, tr);
            tree[v] = better(tree[v<<1], tree[v<<1|1]);
        }
    }

    void update(ll v, ll tl, ll tr, ll pos) {
        if (tl > v || tr < v) return;
        if (tl == tr) return;

        ll mid = calc_mid(tl, tr);
        update(v<<1, tl, mid, pos);
        update(v<<1|1, mid+1, tr, pos);
        tree[v] = better(tree[v<<1], tree[id<<1|1]);
    }

    ll query(ll v, ll tl1, ll tr1, ll tl2, ll tr2) {
        if (tl1 > tr2 || tl2 > tr1) return -1;
        if (tl2 <= tl1 && tr2 >= tr1) return tree[v];
        ll mid = calc_mid(tl1, tr1);
        return better(
            query(v<<1,tl1, mid, tl2, tr2),
            query(v<<1|1,mid+1, tr1, tl2, tr2)
        );
    }

    void init(ll Y[]) {
        for (ll i=0; i< n; i++) a[i] = Y[i];
        build(1,0,n-1);
    }

    void update(ll pos, ll val) {
        a[pos] = val;
        update(1, 0, n-1, pos);
    }
    
    ll query(ll tl, ll tr) {
        return query(1,0,n-1,tl,tr);
    }
}

ll solve() {
    ll best = 0;
    ll best_id = -1;
    ll last = n;
    s.insert(0);
    for (auto it = s.rbegin(); it != s.rend(); it ++) {
        ll tmp = Y::query(*it, last-1);
        if (Y::a[tmp] > best) {
            best = Y::a[tmp];
            best_id = tmp;
        }
        best *= X::a[*it];
        const static ll INF = 1e9;
        if (best > INF) {
            break;
        }
        last = *it;
    }
    if (X::a[0] == 1) s.erase(0);
    return Y::a[best_id] * X::query(best_id) % MOD;
}

int init(int N, int X[], int Y[]) {
    n=N;
    X::init(X);
    Y::init(Y);
    return solve();
}

int updateX(int pos, int val) {
    X::update(pos,val);
    return solve();
}

int updateY(int pos, int val) {
    Y::update(pos, val);
    return solve();
}

Compilation message

horses.cpp: In function 'void Y::update(ll, ll, ll, ll)':
horses.cpp:104:43: error: 'id' was not declared in this scope; did you mean 'mid'?
  104 |         tree[v] = better(tree[v<<1], tree[id<<1|1]);
      |                                           ^~
      |                                           mid
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:156:13: error: cannot convert 'int*' to 'll*' {aka 'long long int*'}
  156 |     X::init(X);
      |             ^
      |             |
      |             int*
horses.cpp:56:18: note:   initializing argument 1 of 'void X::init(ll*)'
   56 |     void init(ll X[]) {
      |               ~~~^~~
horses.cpp:157:13: error: cannot convert 'int*' to 'll*' {aka 'long long int*'}
  157 |     Y::init(Y);
      |             ^
      |             |
      |             int*
horses.cpp:117:18: note:   initializing argument 1 of 'void Y::init(ll*)'
  117 |     void init(ll Y[]) {
      |               ~~~^~~
horses.cpp:158:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  158 |     return solve();
      |            ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:163:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  163 |     return solve();
      |            ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:168:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  168 |     return solve();
      |            ~~~~~^~