Submission #785427

#TimeUsernameProblemLanguageResultExecution timeMemory
785427NothingXDHorses (IOI15_horses)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef complex<ld> point; typedef __uint128_t L; struct FastMod { ull b, m; FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {} ull reduce(ull a) { ull q = (ull)((L(m) * a) >> 64); ull r = a - q * b; // can be proven that 0 <= r < 2*b return r >= b ? r - b : r; } }; FastMod FM(1e9+7); void debug_out(){cerr << endl;} template<typename Head, typename... Tail> void debug_out(Head H, Tail... T){ cout << H << " "; debug_out(T...); } #define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__) #define F first #define S second #define all(x) x.begin(), x.end() #define MP(x, y) make_pair(x, y) const int maxn = 5e5 + 10; const int mod = 1e9 + 7; int n; int x[maxn], y[maxn]; ll dp[maxn << 2][2]; bool of[maxn << 2]; int find(int v, int l, int r, int tmp){ if (!of[v] && 1ll * tmp * dp[v][1] < mod) return -1; if (l + 1 == r) return l; int mid = (l + r) >> 1; int lc = v << 1; int rc = lc | 1; int res = find(rc, mid, r, tmp); if (res == -1){ tmp *= dp[rc][1]; res = find(lc, l, mid, tmp); } return res; } void build2(int v, int l, int r){ if (l + 1 == r){ dp[v][0] = x[l] * y[l]; dp[v][1] = x[l]; return; } int mid = (l + r) >> 1; int lc = v << 1; int rc = lc | 1; build2(lc, l, mid); build2(rc, mid, r); dp[v][0] = max(dp[lc][0], dp[lc][1] * dp[rc][0]); dp[v][1] = dp[lc][1] * dp[rc][1]; if (dp[v][1] >= mod || of[lc] || of[rc]) of[v] = true; dp[v][1] = FM.reduce(dp[v][1]); } void change2(int v, int l, int r, int idx){ if (l + 1 == r){ dp[v][0] = x[l] * y[l]; dp[v][1] = x[l]; return; } int mid = (l + r) >> 1; int lc = v << 1; int rc = lc | 1; if (idx < mid) change2(lc, l, mid, idx); else change2(rc, mid, r, idx); dp[v][0] = max(dp[lc][0], dp[lc][1] * dp[rc][0]); dp[v][1] = dp[lc][1] * dp[rc][1]; if (dp[v][1] >= mod || of[lc] || of[rc]) of[v] = true; dp[v][1] = FM.reduce(dp[v][1]); } pll get2(int v, int l, int r, int ql, int qr){ if (ql <= l && r <= qr) return MP(dp[v][0], dp[v][1]); int mid = (l + r) >> 1; int lc = v << 1; int rc = lc | 1; pll a = {0, 1}; pll b = {0, 1}; if (qr > l && ql < mid) a = get2(lc, l, mid, ql, qr); if (qr > mid && ql < r) b = get2(rc, mid, r, ql, qr); return MP(max(a.F, a.S * b.F), FM.reduce(a.S * b.S)); } int Calc(){ int idx = find(1, 0, n, 1); if (idx == -1) idx = 0; assert(idx < n-1); int tmp = get2(1, 0, n, 0, idx+1).S; ll tmp2 = FM.reduce(max(y[idx], get2(1, 0, n, idx+1, n).F)); return FM.reduce(1ll * tmp * tmp2); } 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]; } build2(1, 0, n); return Calc(); } int updateX(int pos, int val) { x[pos] = val; change2(1, 0, n, pos); return Calc(); } int updateY(int pos, int val) { y[pos] = val; change2(1, 0, n, pos); return Calc(); }

Compilation message (stderr)

horses.cpp: In constructor 'FastMod::FastMod(ull)':
horses.cpp:15:14: warning: declaration of 'b' shadows a member of 'FastMod' [-Wshadow]
   15 |  FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
      |          ~~~~^
horses.cpp:14:6: note: shadowed declaration is here
   14 |  ull b, m;
      |      ^
horses.cpp: In constructor 'FastMod::FastMod(ull)':
horses.cpp:15:14: warning: declaration of 'b' shadows a member of 'FastMod' [-Wshadow]
   15 |  FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
      |          ~~~~^
horses.cpp:14:6: note: shadowed declaration is here
   14 |  ull b, m;
      |      ^
horses.cpp: In constructor 'FastMod::FastMod(ull)':
horses.cpp:15:14: warning: declaration of 'b' shadows a member of 'FastMod' [-Wshadow]
   15 |  FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
      |          ~~~~^
horses.cpp:14:6: note: shadowed declaration is here
   14 |  ull b, m;
      |      ^
horses.cpp: In function 'int find(int, int, int, int)':
horses.cpp:55:7: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   55 |   tmp *= dp[rc][1];
      |   ~~~~^~~~~~~~~~~~
horses.cpp: In function 'int Calc()':
horses.cpp:35:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   35 | #define S second
      |           ^
horses.cpp:111:36: note: in expansion of macro 'S'
  111 |  int tmp = get2(1, 0, n, 0, idx+1).S;
      |                                    ^
horses.cpp:112:59: error: no matching function for call to 'max(int&, long long int)'
  112 |  ll tmp2 = FM.reduce(max(y[idx], get2(1, 0, n, idx+1, n).F));
      |                                                           ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from horses.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
horses.cpp:112:59: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
  112 |  ll tmp2 = FM.reduce(max(y[idx], get2(1, 0, n, idx+1, n).F));
      |                                                           ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from horses.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
horses.cpp:112:59: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
  112 |  ll tmp2 = FM.reduce(max(y[idx], get2(1, 0, n, idx+1, n).F));
      |                                                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from horses.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
horses.cpp:112:59: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  112 |  ll tmp2 = FM.reduce(max(y[idx], get2(1, 0, n, idx+1, n).F));
      |                                                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from horses.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
horses.cpp:112:59: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  112 |  ll tmp2 = FM.reduce(max(y[idx], get2(1, 0, n, idx+1, n).F));
      |                                                           ^
horses.cpp:113:18: warning: conversion from 'ull' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
  113 |  return FM.reduce(1ll * tmp * tmp2);
      |         ~~~~~~~~~^~~~~~~~~~~~~~~~~~