#include <bits/stdc++.h>
#include "horses.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define pf push_front
using namespace std;
using namespace __gnu_pbds;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 1e5 + 100, M = 2 * 1e6 + 100, len = 21, inf = 1e18;
const ll mod = 1e9 + 7;
ll um(ll a, ll b){
return (1LL * a * b) % mod;
}
ll subr(ll a, ll b){
return ((1LL * a - b) % mod + mod) % mod;
}
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>o_set;
int init(int n, int x[], int p[]) {
vector <pll> vec;
for(int i = 0; i < n; i++){
while((ll)vec.size() != 0){
pll v = vec.back();
if(p[i] >= v.F){
x[i] = um(x[i], v.S);
vec.pop_back();
}else break;
}
vec.pb({p[i], x[i]});
}
ll ans = 0, j = 1, i = 0;
for(; j < (int)vec.size();j++){
if(vec[i].F > vec[i + 1].F * vec[i + 1].S){
vec[j + 1].S = um(vec[j + 1].S, vec[j].S);
} else{
vec[j].S = um(vec[j].S, vec[i].S);
i = j;
}
}
ans += um(vec[i].F, vec[i].S);
ans %= mod;
return ans;
}
int updateX(int pos, int val) {
return 0;
}
int updateY(int pos, int val) {
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |