답안 #1099504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099504 2024-10-11T13:30:29 Z Tymond 말 (IOI15_horses) C++17
0 / 100
145 ms 99412 KB
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 7;
const int BASE = (1 << 19);
int x[MAXN];
int y[MAXN];
int n;
set<int> ok;
pll tree[2 * BASE + 7];//.fi -> mnożenie .se -> max y

pll merge(pll a, pll b){
    return mp((ll)a.fi * b.fi % MOD, (ll)max(a.se, b.se));
}

pll query(int v, int l, int p, int a, int b){
    if(b < l || p < a){
        return mp(1LL, 0LL);
    }

    if(a <= l && p <= b){
        return tree[v];
    }

    int mid = (l + p) / 2;
    return merge(query(2 * v, l, mid, a, b), query(2 * v + 1, mid + 1, p, a, b));
}

void upd(int ind){
    tree[ind + BASE] = {x[ind], y[ind]};
    ind += BASE;
    ind /= 2;
    while(ind > 0){
        tree[ind] = merge(tree[2 * ind], tree[2 * ind + 1]);
        ind /= 2;
    }
}

//get result
ll solve(){
    vi usu;
    while(sz(ok) && sz(usu) < 30){
        usu.pb(*(--ok.end()));
        ok.erase(--ok.end());
    }
    if(sz(usu) == 0 || usu.back() != 0){
        usu.pb(0);
    }
    reverse(all(usu));

    ll mul = 1LL;
    int yBest = 0;
    int best = n - 1;
    for(int i = 0; i < sz(usu); i++){
        int nxt = (i == sz(usu) - 1 ? n - 1 : usu[i + 1] - 1);
        int aktY = (int)query(1, 0, BASE - 1, usu[i], usu[nxt]).se;
        mul = (ll)mul * x[usu[i]];
        if(mul > MOD){
            mul = 1LL;
            yBest = aktY;
            best = usu[i];
        }else if((ll)mul * aktY > yBest){
            mul = 1LL;
            yBest = aktY;
            best = usu[i];
        }
    }

    return (ll)yBest * query(1, 0, BASE - 1, 0, best).fi % MOD;
}

int init(int N, int Xn[], int Yn[]){
    n = N;
    for(int i = 0; i < n; i++){
        x[i] = Xn[i];
        y[i] = Yn[i];
    }

    for(int i = 1; i < 2 * BASE + 7; i++){
        tree[i] = mp(1LL, 0LL);
    }

    for(int i = 0; i < n; i++){
        tree[i + BASE] = {x[i], y[i]};
    }

    for(int i = BASE - 1; i >= 1; i--){
        tree[i] = merge(tree[2 * i], tree[2 * i + 1]);
    }

    for(int i = 0; i < n; i++){
        if(x[i] > 1){
            ok.insert(i);
            continue;
        }
    }

    return (int)solve();
}

int updateX(int pos, int val){
    if(x[pos] > 1){
        ok.erase(pos);
    }
    x[pos] = val;
    if(x[pos] > 1){
        ok.insert(pos);
    }
    upd(pos);

    return (int)solve();
}

int updateY(int pos, int val){
    y[pos] = val;
    upd(pos);

    return (int)solve();
}

/*int main(){
    int p[3] = {2, 1, 3};
    int d[3] = {3, 4, 1};
    cout << init(3, p, d) << '\n';
    cout << updateY(1, 2) << '\n';

    return 0;
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16732 KB Output is correct
2 Incorrect 8 ms 16844 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16732 KB Output is correct
2 Incorrect 9 ms 16732 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 145 ms 99412 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 16732 KB Output is correct
2 Incorrect 7 ms 16732 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16848 KB Output is correct
2 Incorrect 7 ms 16732 KB Output isn't correct
3 Halted 0 ms 0 KB -