Submission #365016

#TimeUsernameProblemLanguageResultExecution timeMemory
365016BartolMHorses (IOI15_horses)C++17
17 / 100
1145 ms46188 KiB
#include "horses.h"
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
const int OFF=(1<<19);
const int MAXN=5e5+5;

int n;
pll T[2*OFF];
int Tmax[2*OFF];
ll x[MAXN], y[MAXN];

ll mul(ll a, ll b) {
    return a*b%MOD;
}

pll f(pll a, pll b) {
    return mp(mul(a.X, b.X), min((ll)MOD, a.Y*b.Y));
}

pll umn(int a, int b, int pos=1, int lo=0, int hi=OFF) {
    if (lo>=a && hi<=b) return T[pos];
    if (lo>=b || hi<=a) return mp(1, 1);
    int mid=(lo+hi)/2;
    return f(umn(a, b, pos*2, lo, mid), umn(a, b, pos*2+1, mid, hi));
}

int mrg(int a, int b) {
    if (a==n) return b;
    if (b==n) return a;
    ll bb=f(umn(a+1, b+1), mp(y[b], y[b])).Y;
    return bb>=y[a] ? b : a;
}

int query(int a, int b, int pos=1, int lo=0, int hi=OFF) {
    if (lo>=a && hi<=b) return Tmax[pos];
    if (lo>=b || hi<=a) return n;
    int mid=(lo+hi)/2;
    return mrg(query(a, b, pos*2, lo, mid), query(a, b, pos*2+1, mid, hi));
}

ll answer() {
    int res=query(0, n);
    return mul(umn(0, res+1).X, y[res]);
}

int init(int N, int XX[], int YY[]) {
    n=N;
    for (int i=0; i<n; ++i) x[i]=XX[i], y[i]=YY[i];

    fill(Tmax, Tmax+2*OFF, n);
    fill(T, T+2*OFF, mp(1, 1));
    for (int i=0; i<n; ++i) Tmax[OFF+i]=i, T[OFF+i].X=T[OFF+i].Y=x[i];
    for (int i=OFF-1; i>0; --i) Tmax[i]=mrg(Tmax[i*2], Tmax[i*2+1]), T[i]=f(T[i*2], T[i*2+1]);

    return answer();
}


int updateY(int pos, int val) {
    y[pos]=val;
    pos=(pos+OFF)/2;
    while (pos) {
        Tmax[pos]=mrg(Tmax[pos*2], Tmax[pos*2+1]);
        pos/=2;
    }
    return answer();
}

int updateX(int pos, int val) {
    x[pos]=val;
    pos+=OFF;
    T[pos].X=T[pos].Y=val;
    pos/=2;
    while (pos) {
        T[pos]=f(T[pos*2], T[pos*2+1]);
        pos/=2;
    }
    return updateY(pos, y[pos]);
}

Compilation message (stderr)

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:69:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   69 |     return answer();
      |            ~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:80:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   80 |     return answer();
      |            ~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:92:30: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   92 |     return updateY(pos, y[pos]);
      |                         ~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...