Submission #438539

# Submission time Handle Problem Language Result Execution time Memory
438539 2021-06-28T08:03:34 Z dutch Horses (IOI15_horses) C++17
100 / 100
373 ms 88616 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#include "horses.h"
 
const int MOD = 1e9+7;
 
struct mint{
	ll v = 0; bool b = 0;
	mint(int V=0, bool B=0) : v(V), b(B) {};
	friend mint operator*(mint x, mint y){
		return mint((x.v * y.v) % MOD, x.b || y.b || x.v * y.v >= MOD);
	}
};
 
template<class T> struct SegmentTree{
	const T ID = {1, 0, 1, 0}; // product of X[i]s, best, suffix after best, Y[at best]
	T comb(T &x, T &y){
		mint z = x[2] * y[1];
		if(z.b || z.v > x[3].v) return {
			x[0] * y[0],
			x[0] * y[1],
			y[2],
			y[3]
		};
		else return {
			x[0] * y[0],
			x[1],
			x[2] * y[0],
			x[3]
		};
	}
	int n = 1, i; vector<T> a;
	void init(int N){ while((n+=n) < N); a.assign(2*n, ID); }
	SegmentTree& operator[](int j){ i=j+n; return *this; }
	void operator=(T v){
		for(a[i]=v; i/=2; ) a[i] = comb(a[2*i], a[2*i+1]); }
	int operator()(){ return a[1][1].v; }
};
 
ll N; mint X[1<<19], Y[1<<19];
SegmentTree<array<mint, 4>> st;
 
int init(int n, int x[], int y[]){
	st.init(N=n);
	for(int i=0; i<n; ++i){
		X[i] = x[i], Y[i] = y[i];
		st[i] = st.a[0] = {X[i], X[i] * Y[i], 1, Y[i]};
	}
	return st();
}
 
int updateX(int i, int v){
	X[i] = v;
	st[i] = st.a[0] = {X[i], X[i] * Y[i], 1, Y[i]};
	return st();
}
 
int updateY(int i, int v){
	Y[i] = v;
	st[i] = st.a[0] = {X[i], X[i] * Y[i], 1, Y[i]};
	return st();
}

Compilation message

horses.cpp: In function 'mint operator*(mint, mint)':
horses.cpp:12:27: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   12 |   return mint((x.v * y.v) % MOD, x.b || y.b || x.v * y.v >= MOD);
      |               ~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:45:11: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   45 |  st.init(N=n);
      |          ~^~
horses.cpp: In instantiation of 'int SegmentTree<T>::operator()() [with T = std::array<mint, 4>]':
horses.cpp:50:12:   required from here
horses.cpp:38:35: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   38 |  int operator()(){ return a[1][1].v; }
      |                           ~~~~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16588 KB Output is correct
2 Correct 8 ms 16596 KB Output is correct
3 Correct 10 ms 16716 KB Output is correct
4 Correct 8 ms 16688 KB Output is correct
5 Correct 8 ms 16672 KB Output is correct
6 Correct 8 ms 16636 KB Output is correct
7 Correct 8 ms 16716 KB Output is correct
8 Correct 8 ms 16716 KB Output is correct
9 Correct 8 ms 16588 KB Output is correct
10 Correct 8 ms 16716 KB Output is correct
11 Correct 8 ms 16588 KB Output is correct
12 Correct 8 ms 16588 KB Output is correct
13 Correct 9 ms 16588 KB Output is correct
14 Correct 8 ms 16588 KB Output is correct
15 Correct 9 ms 16588 KB Output is correct
16 Correct 9 ms 16588 KB Output is correct
17 Correct 9 ms 16588 KB Output is correct
18 Correct 10 ms 16588 KB Output is correct
19 Correct 8 ms 16588 KB Output is correct
20 Correct 8 ms 16640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16588 KB Output is correct
2 Correct 8 ms 16588 KB Output is correct
3 Correct 8 ms 16716 KB Output is correct
4 Correct 10 ms 16588 KB Output is correct
5 Correct 8 ms 16600 KB Output is correct
6 Correct 8 ms 16600 KB Output is correct
7 Correct 9 ms 16716 KB Output is correct
8 Correct 9 ms 16588 KB Output is correct
9 Correct 9 ms 16588 KB Output is correct
10 Correct 9 ms 16588 KB Output is correct
11 Correct 8 ms 16588 KB Output is correct
12 Correct 10 ms 16588 KB Output is correct
13 Correct 8 ms 16588 KB Output is correct
14 Correct 8 ms 16700 KB Output is correct
15 Correct 9 ms 16624 KB Output is correct
16 Correct 9 ms 16716 KB Output is correct
17 Correct 9 ms 16588 KB Output is correct
18 Correct 8 ms 16688 KB Output is correct
19 Correct 11 ms 16588 KB Output is correct
20 Correct 8 ms 16716 KB Output is correct
21 Correct 8 ms 16592 KB Output is correct
22 Correct 9 ms 16628 KB Output is correct
23 Correct 12 ms 16844 KB Output is correct
24 Correct 10 ms 16844 KB Output is correct
25 Correct 10 ms 16844 KB Output is correct
26 Correct 9 ms 16844 KB Output is correct
27 Correct 9 ms 16844 KB Output is correct
28 Correct 10 ms 16844 KB Output is correct
29 Correct 10 ms 16844 KB Output is correct
30 Correct 10 ms 16844 KB Output is correct
31 Correct 10 ms 16844 KB Output is correct
32 Correct 10 ms 16768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 234 ms 87184 KB Output is correct
2 Correct 350 ms 88616 KB Output is correct
3 Correct 316 ms 87852 KB Output is correct
4 Correct 347 ms 88180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16588 KB Output is correct
2 Correct 8 ms 16688 KB Output is correct
3 Correct 8 ms 16588 KB Output is correct
4 Correct 9 ms 16716 KB Output is correct
5 Correct 9 ms 16588 KB Output is correct
6 Correct 9 ms 16588 KB Output is correct
7 Correct 11 ms 16644 KB Output is correct
8 Correct 9 ms 16588 KB Output is correct
9 Correct 8 ms 16588 KB Output is correct
10 Correct 10 ms 16588 KB Output is correct
11 Correct 8 ms 16588 KB Output is correct
12 Correct 8 ms 16588 KB Output is correct
13 Correct 9 ms 16648 KB Output is correct
14 Correct 9 ms 16588 KB Output is correct
15 Correct 8 ms 16588 KB Output is correct
16 Correct 8 ms 16588 KB Output is correct
17 Correct 9 ms 16588 KB Output is correct
18 Correct 8 ms 16720 KB Output is correct
19 Correct 9 ms 16588 KB Output is correct
20 Correct 8 ms 16588 KB Output is correct
21 Correct 8 ms 16700 KB Output is correct
22 Correct 11 ms 16608 KB Output is correct
23 Correct 10 ms 16772 KB Output is correct
24 Correct 9 ms 16844 KB Output is correct
25 Correct 9 ms 16844 KB Output is correct
26 Correct 10 ms 16892 KB Output is correct
27 Correct 9 ms 16844 KB Output is correct
28 Correct 9 ms 16844 KB Output is correct
29 Correct 9 ms 16844 KB Output is correct
30 Correct 9 ms 16844 KB Output is correct
31 Correct 9 ms 16868 KB Output is correct
32 Correct 10 ms 16844 KB Output is correct
33 Correct 213 ms 87156 KB Output is correct
34 Correct 267 ms 86980 KB Output is correct
35 Correct 248 ms 87580 KB Output is correct
36 Correct 229 ms 87568 KB Output is correct
37 Correct 197 ms 86936 KB Output is correct
38 Correct 205 ms 86920 KB Output is correct
39 Correct 193 ms 86856 KB Output is correct
40 Correct 216 ms 86980 KB Output is correct
41 Correct 187 ms 87144 KB Output is correct
42 Correct 188 ms 87108 KB Output is correct
43 Correct 218 ms 86960 KB Output is correct
44 Correct 220 ms 87112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16588 KB Output is correct
2 Correct 10 ms 16588 KB Output is correct
3 Correct 8 ms 16588 KB Output is correct
4 Correct 8 ms 16588 KB Output is correct
5 Correct 9 ms 16688 KB Output is correct
6 Correct 9 ms 16588 KB Output is correct
7 Correct 8 ms 16588 KB Output is correct
8 Correct 9 ms 16608 KB Output is correct
9 Correct 12 ms 16588 KB Output is correct
10 Correct 9 ms 16588 KB Output is correct
11 Correct 9 ms 16588 KB Output is correct
12 Correct 10 ms 16588 KB Output is correct
13 Correct 9 ms 16588 KB Output is correct
14 Correct 10 ms 16588 KB Output is correct
15 Correct 10 ms 16588 KB Output is correct
16 Correct 9 ms 16588 KB Output is correct
17 Correct 8 ms 16628 KB Output is correct
18 Correct 9 ms 16588 KB Output is correct
19 Correct 9 ms 16716 KB Output is correct
20 Correct 9 ms 16588 KB Output is correct
21 Correct 10 ms 16716 KB Output is correct
22 Correct 11 ms 16588 KB Output is correct
23 Correct 12 ms 16848 KB Output is correct
24 Correct 10 ms 16848 KB Output is correct
25 Correct 9 ms 16844 KB Output is correct
26 Correct 9 ms 16848 KB Output is correct
27 Correct 14 ms 16764 KB Output is correct
28 Correct 10 ms 16844 KB Output is correct
29 Correct 10 ms 16844 KB Output is correct
30 Correct 11 ms 16844 KB Output is correct
31 Correct 11 ms 16844 KB Output is correct
32 Correct 9 ms 16840 KB Output is correct
33 Correct 243 ms 87944 KB Output is correct
34 Correct 373 ms 88288 KB Output is correct
35 Correct 303 ms 87596 KB Output is correct
36 Correct 365 ms 87672 KB Output is correct
37 Correct 210 ms 86664 KB Output is correct
38 Correct 213 ms 86664 KB Output is correct
39 Correct 253 ms 87108 KB Output is correct
40 Correct 223 ms 87184 KB Output is correct
41 Correct 200 ms 86748 KB Output is correct
42 Correct 205 ms 86672 KB Output is correct
43 Correct 188 ms 86740 KB Output is correct
44 Correct 209 ms 86724 KB Output is correct
45 Correct 190 ms 86804 KB Output is correct
46 Correct 222 ms 86796 KB Output is correct
47 Correct 238 ms 86848 KB Output is correct
48 Correct 209 ms 86804 KB Output is correct
49 Correct 319 ms 87692 KB Output is correct
50 Correct 325 ms 87692 KB Output is correct
51 Correct 275 ms 88072 KB Output is correct
52 Correct 297 ms 88076 KB Output is correct
53 Correct 363 ms 87756 KB Output is correct
54 Correct 253 ms 87656 KB Output is correct
55 Correct 226 ms 86996 KB Output is correct
56 Correct 256 ms 87688 KB Output is correct
57 Correct 229 ms 87688 KB Output is correct
58 Correct 240 ms 87788 KB Output is correct
59 Correct 238 ms 86832 KB Output is correct