Submission #1191972

#TimeUsernameProblemLanguageResultExecution timeMemory
1191972lrnnzHorses (IOI15_horses)C++17
100 / 100
162 ms129756 KiB
#include <bits/stdc++.h> #include <iostream> #include <vector> #include <algorithm> #include <cmath> #include "horses.h" using namespace std; #define all(a) (a).begin(), (a).end() #define sz(a) (int)(a).size() #define pb push_back #define ll long long #define ld long double #define ui uint64_t #define ar array #define us unordered_set #define cont(set, element) ((set).find(element) != (set).end()) /********* DEBUG *********/ template <typename T> void outvec(const vector<T>& Z){ for (const T& x : Z) cout << x << ' '; cout << "\n"; } void printVariable(const any& var) { if (!var.has_value()) { cout << "null"; return; } if (var.type() == typeid(int)) { cout << any_cast<int>(var); } else if (var.type() == typeid(double)) { cout << any_cast<double>(var); } else if (var.type() == typeid(float)) { cout << any_cast<float>(var); } else if (var.type() == typeid(char)) { cout << any_cast<char>(var); } else if (var.type() == typeid(bool)) { cout << (any_cast<bool>(var) ? "true" : "false"); } else if (var.type() == typeid(string)) { cout << any_cast<string>(var); } else if (var.type() == typeid(const char*)) { cout << any_cast<const char*>(var); } else if (var.type() == typeid(long long)) { cout << any_cast<long long>(var); } else if (var.type() == typeid(long double)) { cout << any_cast<long double>(var); } else { cout << "[unknown type]"; } } template<typename... Args> void outval(Args... args) { vector<any> variables = {args...}; for (size_t i = 0; i < variables.size(); ++i) { printVariable(variables[i]); if (i != variables.size() - 1) { cout << " "; } } cout << "\n"; } #define nl "\n" #define sp << " " << /********* DEBUG *********/ const int MOD = 1000000007; const ll MOD2 = 998244353; const ll MOD3 = 1000000000; const ll needMOD = 987654321; const ll mxN = 500005; const ll inf = 1e18; /* Idea Segtree, point update, for each node keep track of C[i], cumuluative product of X[i], and highest Y[i] * C[i]. Use logarithms to change multiplication into addition, but keep track of original values. */ vector<ll> x(mxN),y(mxN); struct info { ld realProd, realHi; ll modProd, modHi; void create(ll idx){ realProd = log10(x[idx]); realHi = log10(y[idx]) + realProd; modProd = x[idx] % MOD; modHi = (x[idx] * y[idx]) % MOD; } }; vector<info> tree(mxN); ll n; info merge(info a, info b){ info temp; temp.realProd = a.realProd + b.realProd; temp.modProd = (a.modProd * b.modProd) % MOD; if (a.realHi > a.realProd + b.realHi){ // take left temp.realHi = a.realHi; temp.modHi = a.modHi; } else{ // take right temp.realHi = a.realProd + b.realHi; temp.modHi = (a.modProd*b.modHi)%MOD; } return temp; } void build(ll node, ll start, ll end){ if (start == end){ tree[node].create(start); return; } ll m = (start+end)/2; build(2 * node + 1, start, m); build(2 * node + 2, m + 1, end); tree[node] = merge(tree[2 * node + 1], tree[2 * node + 2]); } void upd(ll idx, ll node, ll start, ll end){ if (start == end){ tree[node].create(idx); return; } ll m = (start + end) / 2; if (m >= idx){ upd(idx, 2 * node + 1, start, m); } else{ upd(idx, 2 * node + 2, m + 1, end); } tree[node] = merge(tree[2*node+1], tree[2*node+2]); } int init(int N, int X[], int Y[]){ tree.resize(4*N, {0,0,0,0}); n=N; for (int i = 0; i < N; i++){ x[i] = X[i]; y[i] = Y[i]; } build(0, 0, N-1); return tree[0].modHi; } int updateX(int pos, int val){ x[pos]=val; upd(pos,0,0,n-1); return tree[0].modHi; } int updateY(int pos, int val){ y[pos]=val; upd(pos,0,0,n-1); return tree[0].modHi; }
#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...