Submission #615391

#TimeUsernameProblemLanguageResultExecution timeMemory
6153918e7Horses (IOI15_horses)C++17
100 / 100
610 ms51328 KiB
//Challenge: Accepted #include <bits/stdc++.h> using namespace std; #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r){ while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif #define ll long long #define maxn 500005 #define mod 1000000007 #define pii pair<int, int> #define ff first #define ss second #include "horses.h" struct segtree{ int seg[4*maxn]; void init(int cur, int l, int r, int a[]) { if (r <= l) return; if (r - l == 1){ seg[cur] = a[l]; return; } int m = (l + r) / 2; init(cur*2, l, m, a), init(cur*2+1, m, r, a); seg[cur] = max(seg[cur*2], seg[cur*2+1]); } void modify(int cur, int l, int r, int ind, int x){ if (r <= l) return; if (r - l == 1){ seg[cur] = x; return; } int m = (l + r) / 2; if (ind < m) modify(cur*2, l, m, ind, x); else modify(cur*2+1, m, r, ind, x); seg[cur] = max(seg[cur*2], seg[cur*2+1]); } int query(int cur, int l, int r, int ql, int qr){ if (r <= l || ql >= r || qr <= l) return 0; if (ql <= l && qr >= r) return seg[cur]; int m = (l + r) / 2; return max(query(cur*2, l, m, ql, qr), query(cur*2+1, m, r, ql, qr)); } } tr; struct BIT{ ll bit[maxn]; void init(int n){ for (int i = 0;i <= n;i++) bit[i] = 1; } void modify(int ind, ll val) { ind++; for (;ind < maxn;ind += ind & (-ind)) bit[ind] = bit[ind] * val % mod; } ll query(int ind) { ind++; ll ret = 1; for (;ind > 0;ind -= ind & (-ind)) ret = ret * bit[ind] % mod; return ret; } } bit; ll modpow(ll x, ll p){ ll ret = 1; while (p) { if (p & 1) ret = ret * x % mod; p >>= 1, x = x * x % mod; } return ret; } const ll inf = 1e9; int n; int a[maxn]; set<int> se; int query() { pary(se.begin(), se.end()); ll ret = 0; ll suf = 1; auto it = prev(se.end()); vector<ll> v, mul; while (true) { bool fi = it == se.begin(); int lef = (fi ? 0 : *prev(it)), rig = *it; //[lef, rig) ll val = max(suf, (ll)tr.query(1, 0, n, lef, rig)); v.push_back(val); ll m = fi ? 1 : a[*prev(it)]; mul.push_back(m); suf *= m; if (fi || suf >= inf) { mul.pop_back(); reverse(v.begin(), v.end()); reverse(mul.begin(), mul.end()); pary(v.begin(), v.end()); pary(mul.begin(), mul.end()); ll pref = fi ? 1: bit.query(*prev(it)); ll best = 0, p = 1; for (int i = 0;i < v.size();i++) { best = max(best, p * v[i]); if (i < (int)v.size() - 1)p *= mul[i]; } ret = (best % mod) * pref % mod; return ret; } it = prev(it); } } int init(int N, int X[], int Y[]) { n = N; bit.init(n); for (int i = 0;i < n;i++) { a[i] = X[i]; if (a[i] > 1) se.insert(i); bit.modify(i, X[i]); } se.insert(n); tr.init(1, 0, n, Y); return query(); } int updateX(int pos, int val) { bit.modify(pos, modpow(a[pos], mod - 2)); if (a[pos] > 1) { se.erase(se.find(pos)); } a[pos] = val; if (a[pos] > 1) { se.insert(pos); } bit.modify(pos, val); return query(); } int updateY(int pos, int val) { tr.modify(1, 0, n, pos, val); return query(); }

Compilation message (stderr)

horses.cpp: In function 'int query()':
horses.cpp:13:19: warning: statement has no effect [-Wunused-value]
   13 | #define pary(...) 0
      |                   ^
horses.cpp:83:2: note: in expansion of macro 'pary'
   83 |  pary(se.begin(), se.end());
      |  ^~~~
horses.cpp:13:19: warning: statement has no effect [-Wunused-value]
   13 | #define pary(...) 0
      |                   ^
horses.cpp:100:4: note: in expansion of macro 'pary'
  100 |    pary(v.begin(), v.end());
      |    ^~~~
horses.cpp:13:19: warning: statement has no effect [-Wunused-value]
   13 | #define pary(...) 0
      |                   ^
horses.cpp:101:4: note: in expansion of macro 'pary'
  101 |    pary(mul.begin(), mul.end());
      |    ^~~~
horses.cpp:104:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |    for (int i = 0;i < v.size();i++) {
      |                   ~~^~~~~~~~~~
horses.cpp:109:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  109 |    return ret;
      |           ^~~
#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...