Submission #299329

#TimeUsernameProblemLanguageResultExecution timeMemory
299329Haunted_CppHorses (IOI15_horses)C++17
20 / 100
317 ms40064 KiB
#include "horses.h" #include <bits/stdc++.h> using namespace std; const int MAX_N = 5e5 + 5; const int MAX_K = 34; const int MOD = 1e9 + 7; int _N; vector<int> _X(MAX_N), _Y(MAX_N); set<int> non_one; int mult(int a, int b) { long long res = 1LL * a * b; if (res >= MOD) res %= MOD; return res; } class SegmentTree { private: struct Node { int product; int opt; Node() { product = 1; opt = -1; } void merge(Node l, Node r) { product = mult(l.product, r.product); opt = l.opt; if (l.opt == -1) { opt = r.opt; return; } if (r.opt == -1) { opt = l.opt; return; } //~ auto start_location = opt; long long best_multiplier = _Y[opt]; long long road = 1; for (int i = opt + 1; i <= r.opt && i < opt + MAX_K && i < _N; i++) { long long cur = _X[i]; assert(cur >= 2); long long nxt = 1LL * road * cur; if (nxt >= best_multiplier || (1LL * nxt * _Y[i] >= best_multiplier)) { opt = r.opt; return; } //~ start_location = next(start_location); road = nxt; } if (1LL * road * _Y[r.opt] >= best_multiplier) { opt = r.opt; } } }; const int LO, HI; vector<Node> seg; void update(int where, int delta, int l, int r, int node) { if (l > where || r < where) { return; } if (l >= where && r <= where) { seg[node].opt = l; seg[node].product = delta; return; } const int mid = l + (r - l) / 2; update(where, delta, l, mid, 2 * node + 1); update(where, delta, mid + 1, r, 2 * node + 2); seg[node].merge(seg[2 * node + 1], seg[2 * node + 2]); } int query(int ql, int qr, int l, int r, int node) { if (l > qr || r < ql) { return 1; } if (l >= ql && r <= qr) { return seg[node].product; } const int mid = l + (r - l) / 2; return mult(query(ql, qr, l, mid, 2 * node + 1), query(ql, qr, mid + 1, r, 2 * node + 2)); } public: SegmentTree(int n) : LO(0), HI(n - 1) { seg = vector<Node>(4 * n); } void update(int where, int delta) { update(where, delta, LO, HI, 0); } int solve() { return mult(query(0, seg[0].opt, LO, HI, 0), _Y[seg[0].opt]); } }; SegmentTree seg(MAX_N); int init(int N, int X[], int Y[]) { _N = N; for (int i = 0; i < N; i++) { _X[i] = X[i]; _Y[i] = Y[i]; //~ if (_X[i] > 1) { //~ non_one.insert(i); //~ } } for (int i = 0; i < N; i++) { seg.update(i, _X[i]); } return seg.solve(); } int updateX(int pos, int val) { //~ if (non_one.find(pos) != non_one.end()) { //~ non_one.erase(pos); //~ } _X[pos] = val; //~ if (_X[pos] > 1) { //~ non_one.insert(pos); //~ } seg.update(pos, val); return seg.solve(); } int updateY(int pos, int val) { _Y[pos] = val; seg.update(pos, _X[pos]); return seg.solve(); }

Compilation message (stderr)

horses.cpp: In function 'int mult(int, int)':
horses.cpp:16:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   16 |   return res;
      |          ^~~
#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...