Submission #1286513

#TimeUsernameProblemLanguageResultExecution timeMemory
1286513tschav_Horses (IOI15_horses)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> x, y;
int n;
int m;
ll prod = 1;
int idx = -1;
vector<int> st;
static const ll MOD = 1e9+7;

ll binpow(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll gety(int id){
	int lim = n;
	if(id < m-1) {
		lim = st[id+1];
	}
	int mx = 0;
	for(int i = st[id]; i < lim; ++i){
		mx = max(mx, y[i]);
	}
}

ll solve() {
	ll mx = (idx == -1 ? 0 : y[st[idx]]);
	ll curr = 1;
	for(int i = idx+1; i < m; ++i){
		curr *= x[st[i]];
		int G = gety(i);
		if(curr * G > mx) {
			mx = curr * G;
		}
	}
	return (mx%MOD * prod%MOD) % MOD;
}

void ind() {
	idx = -1;
	ll P = 1ll;
	for(int i = m-1; i >= 0; --i) {
		if(P * x[st[i]] > 1e9) {
			idx=i;
			break;
		} else P *= x[st[i]];
	}
}

void getprod() {
	prod = 1ll;
	for(int i = 0; i <= idx; ++i){
		prod = (prod * x[st[i]]) % MOD;
	}
}

int init(int N, int X[], int Y[]) {
	n = N;
	x.resize(n,0ll);
	y.resize(n,0ll);
	for(int i = 0; i < n; ++i) {
		x[i] = X[i];
		y[i] = Y[i];
		if(x[i] >= 2){
			st.push_back(i);
		}
	}
	m = st.size();

	ind();
	getprod();
	return int(solve());
}

int updateX(int pos, int val) {
	ll old = x[pos];
	x[pos] = val;
	ind();
	if(pos <= idx) {
        prod = (prod * binpow(old, MOD-2,MOD)) % MOD;
        prod = (prod * val) % MOD;
	}
	
	if(val == 1 and old != 1) {
		st.erase(st.begin()+pos,1);
	}
	return int(solve());
}

int updateY(int pos, int val) {
	y[pos] = val;
	ind();
	return int(solve());
}

Compilation message (stderr)

horses.cpp: In function 'll gety(int)':
horses.cpp:31:25: error: no matching function for call to 'max(int&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
   31 |                 mx = max(mx, y[i]);
      |                      ~~~^~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from horses.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
horses.cpp:31:25: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   31 |                 mx = max(mx, y[i]);
      |                      ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
horses.cpp:31:25: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   31 |                 mx = max(mx, y[i]);
      |                      ~~~^~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
horses.cpp:31:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   31 |                 mx = max(mx, y[i]);
      |                      ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
horses.cpp:31:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   31 |                 mx = max(mx, y[i]);
      |                      ~~~^~~~~~~~~~
horses.cpp:33:1: warning: no return statement in function returning non-void [-Wreturn-type]
   33 | }
      | ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:94:25: error: no matching function for call to 'std::vector<int>::erase(__gnu_cxx::__normal_iterator<int*, std::vector<int> >, int)'
   94 |                 st.erase(st.begin()+pos,1);
      |                 ~~~~~~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_vector.h:1534:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::vector<int>::iterator; const_iterator = std::vector<int>::const_iterator]'
 1534 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/13/bits/stl_vector.h:1534:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/13/bits/stl_vector.h:1562:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator, const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::vector<int>::iterator; const_iterator = std::vector<int>::const_iterator]'
 1562 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/13/bits/stl_vector.h:1562:52: note:   no known conversion for argument 2 from 'int' to 'std::vector<int>::const_iterator'
 1562 |       erase(const_iterator __first, const_iterator __last)
      |                                     ~~~~~~~~~~~~~~~^~~~~~