제출 #222257

#제출 시각아이디문제언어결과실행 시간메모리
222257mode149256말 (IOI15_horses)C++14
17 / 100
868 ms130592 KiB
/*input */ #include "horses.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<vl> vll; typedef vector<pi> vpi; typedef vector<vpi> vpii; typedef vector<pl> vpl; typedef vector<cd> vcd; typedef vector<pd> vpd; typedef vector<bool> vb; typedef vector<vb> vbb; typedef std::string str; typedef std::vector<str> vs; #define x first #define y second #define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n" const ll MOD = 1000000007; const ll INF = std::numeric_limits<ll>::max(); const int MX = 100101; const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L; template<typename T> pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); } template<typename T> pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); } template<typename T> T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); } template<typename T> T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); } template<typename T> void print(vector<T> vec, string name = "") { cout << name; for (auto u : vec) cout << u << ' '; cout << '\n'; } vl x, y; int n; struct maxNode { int l, r; pl did; maxNode *left = nullptr; maxNode *right = nullptr; maxNode(int a, int b): l(a), r(b) { if (l != r) { left = new maxNode(l, (l + r) / 2); right = new maxNode((l + r) / 2 + 1, r); did = max(left->did, right->did); } else did = {y[l], l}; } void upd(int pos, int val) { if (l == r) { did.x = val; return; } else if (pos <= (l + r) / 2) left->upd(pos, val); else right->upd(pos, val); did = max(left->did, right->did); } pl gauk(int a, int b) { if (r < a or b < l) return pi(-MOD, -MOD); else if (a <= l and r <= b) return did; else return max(left->gauk(a, b), right->gauk(a, b)); } }; struct prodNode { int l, r; ll prod; prodNode *left = nullptr; prodNode *right = nullptr; prodNode(int a, int b): l(a), r(b) { if (l != r) { left = new prodNode(l, (l + r) / 2); right = new prodNode((l + r) / 2 + 1, r); prod = (left->prod * right->prod) % MOD; } else prod = x[l]; } void upd(int pos, ll val) { if (l == r) { prod = val; return; } else if (pos <= (l + r) / 2) left->upd(pos, val); else right->upd(pos, val); prod = (left->prod * right->prod) % MOD; } ll gauk(int a, int b) { if (r < a or b < l) return 1; else if (a <= l and r <= b) return prod; else return (left->gauk(a, b) * right->gauk(a, b)) % MOD; } }; maxNode *yg; prodNode *xs; set<int, greater<int> > indes; int compute() { if (indes.empty()) { pi ans = yg->did; return ans.x; } int last = n; ll currProd = 1; int currBest = -1; int cn = 0; for (auto it = indes.begin(); it != indes.end() and cn < 60; it++, cn++) { pi dabY = yg->gauk(*it, last - 1); // printf("ind = %d, dabY = %d %d\n", *it, dabY.x, dabY.y); if (currBest == -1 or dabY.x > currProd * y[currBest]) { currBest = dabY.y; currProd = x[*it]; } else { currProd *= x[*it]; if (currProd > MOD) break; } // printf("currBest = %lld, currProd = %lld\n", currBest, currProd); last = *it; } if (last != 0 and currProd <= MOD) { pi dabY = yg->gauk(0, last - 1); if (dabY.x > currProd * y[currBest]) { currBest = dabY.y; currProd = x[dabY.y]; } } return (int)((ll)xs->gauk(0, currBest) * y[currBest]) % MOD; } int init(int N, int X[], int Y[]) { n = N; for (int i = 0; i < N; ++i) { x.emplace_back(X[i]); y.emplace_back(Y[i]); if (X[i] != 1) indes.insert(i); } yg = new maxNode(0, N - 1); xs = new prodNode(0, N - 1); return compute(); } int updateX(int pos, int val) { if (val != 1) indes.insert(pos); else if (val == 1) indes.erase(pos); xs->upd(pos, val); return compute(); } int updateY(int pos, int val) { yg->upd(pos, val); return compute(); }
#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...