Submission #160265

# Submission time Handle Problem Language Result Execution time Memory
160265 2019-10-26T15:32:53 Z bortoz Horses (IOI15_horses) C++17
100 / 100
383 ms 31864 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second

constexpr int MAXN = 1 << 19;
constexpr int MOD = 1e9 + 7;

pair<int, bool> segX[2 * MAXN];
int segM[2 * MAXN];
int Y[MAXN];

pair<int, bool> joinX(pair<int, bool>& a, pair<int, bool>& b) {
	ll r = 1ll * a.fi * b.fi;
	bool o = (r >= MOD) || a.se || b.se;
	return make_pair(r % MOD, o);
}

pair<int, bool> queryX(int l, int r) {
	pair<int, bool> ans{1, false};
	for (l += MAXN, r += MAXN; l < r; l /= 2, r /= 2) {
		if (l & 1) ans = joinX(ans, segX[l++]);
		if (r & 1) ans = joinX(ans, segX[--r]);
	}
	return ans;
}

int joinM(int a, int b) {
	pair<int, bool> mulX = queryX(a + 1, b + 1);
	if (mulX.se) return b;
	return Y[a] > 1ll * mulX.fi * Y[b] ? a : b;
}

int init(int N, int* X, int*_Y) {
	copy(_Y, _Y + N, Y);
	for (int i = 0; i < N; i++) {
		segX[i + MAXN] = make_pair(X[i], false);
	}
	iota(segM + MAXN, segM + 2 * MAXN, 0);
	for (int i = MAXN - 1; i > 0; i--) {
		segX[i] = joinX(segX[2 * i], segX[2 * i + 1]);
		segM[i] = joinM(segM[2 * i], segM[2 * i + 1]);
	}
	return 1ll * queryX(0, segM[1] + 1).fi * Y[segM[1]] % MOD;
}

int updateX(int pos, int val) {
	for (segX[pos += MAXN] = make_pair(val, false); pos > 1; pos /= 2) {
		segX[pos / 2] = joinX(segX[pos & -2], segX[pos | 1]);
		segM[pos / 2] = joinM(segM[pos & -2], segM[pos | 1]);
	}
	return 1ll * queryX(0, segM[1] + 1).fi * Y[segM[1]] % MOD;
}

int updateY(int pos, int val) {
	for (Y[pos] = val, pos += MAXN; pos > 1; pos /= 2) {
		segX[pos / 2] = joinX(segX[pos & -2], segX[pos | 1]);
		segM[pos / 2] = joinM(segM[pos & -2], segM[pos | 1]);
	}
	return 1ll * queryX(0, segM[1] + 1).fi * Y[segM[1]] % MOD;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:46:54: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return 1ll * queryX(0, segM[1] + 1).fi * Y[segM[1]] % MOD;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:54:54: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return 1ll * queryX(0, segM[1] + 1).fi * Y[segM[1]] % MOD;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:62:54: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return 1ll * queryX(0, segM[1] + 1).fi * Y[segM[1]] % MOD;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 35 ms 8568 KB Output is correct
2 Correct 18 ms 8568 KB Output is correct
3 Correct 18 ms 8540 KB Output is correct
4 Correct 18 ms 8568 KB Output is correct
5 Correct 18 ms 8568 KB Output is correct
6 Correct 18 ms 8592 KB Output is correct
7 Correct 18 ms 8568 KB Output is correct
8 Correct 18 ms 8568 KB Output is correct
9 Correct 18 ms 8568 KB Output is correct
10 Correct 18 ms 8568 KB Output is correct
11 Correct 18 ms 8496 KB Output is correct
12 Correct 18 ms 8568 KB Output is correct
13 Correct 18 ms 8572 KB Output is correct
14 Correct 18 ms 8596 KB Output is correct
15 Correct 18 ms 8568 KB Output is correct
16 Correct 18 ms 8496 KB Output is correct
17 Correct 18 ms 8532 KB Output is correct
18 Correct 23 ms 8568 KB Output is correct
19 Correct 18 ms 8540 KB Output is correct
20 Correct 18 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 8568 KB Output is correct
2 Correct 18 ms 8568 KB Output is correct
3 Correct 19 ms 8568 KB Output is correct
4 Correct 18 ms 8568 KB Output is correct
5 Correct 18 ms 8568 KB Output is correct
6 Correct 18 ms 8568 KB Output is correct
7 Correct 18 ms 8568 KB Output is correct
8 Correct 18 ms 8568 KB Output is correct
9 Correct 19 ms 8568 KB Output is correct
10 Correct 18 ms 8568 KB Output is correct
11 Correct 18 ms 8568 KB Output is correct
12 Correct 21 ms 8568 KB Output is correct
13 Correct 18 ms 8568 KB Output is correct
14 Correct 18 ms 8568 KB Output is correct
15 Correct 18 ms 8568 KB Output is correct
16 Correct 18 ms 8568 KB Output is correct
17 Correct 18 ms 8568 KB Output is correct
18 Correct 18 ms 8480 KB Output is correct
19 Correct 18 ms 8568 KB Output is correct
20 Correct 18 ms 8568 KB Output is correct
21 Correct 18 ms 8568 KB Output is correct
22 Correct 18 ms 8568 KB Output is correct
23 Correct 20 ms 8628 KB Output is correct
24 Correct 20 ms 8568 KB Output is correct
25 Correct 20 ms 8696 KB Output is correct
26 Correct 19 ms 8568 KB Output is correct
27 Correct 19 ms 8568 KB Output is correct
28 Correct 19 ms 8572 KB Output is correct
29 Correct 19 ms 8568 KB Output is correct
30 Correct 19 ms 8568 KB Output is correct
31 Correct 29 ms 8696 KB Output is correct
32 Correct 19 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 19640 KB Output is correct
2 Correct 190 ms 19584 KB Output is correct
3 Correct 223 ms 19448 KB Output is correct
4 Correct 225 ms 19448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 8568 KB Output is correct
2 Correct 18 ms 8568 KB Output is correct
3 Correct 18 ms 8540 KB Output is correct
4 Correct 18 ms 8544 KB Output is correct
5 Correct 18 ms 8568 KB Output is correct
6 Correct 18 ms 8568 KB Output is correct
7 Correct 18 ms 8568 KB Output is correct
8 Correct 18 ms 8568 KB Output is correct
9 Correct 18 ms 8572 KB Output is correct
10 Correct 18 ms 8568 KB Output is correct
11 Correct 18 ms 8568 KB Output is correct
12 Correct 18 ms 8568 KB Output is correct
13 Correct 18 ms 8568 KB Output is correct
14 Correct 18 ms 8568 KB Output is correct
15 Correct 18 ms 8568 KB Output is correct
16 Correct 18 ms 8568 KB Output is correct
17 Correct 19 ms 8696 KB Output is correct
18 Correct 18 ms 8568 KB Output is correct
19 Correct 18 ms 8568 KB Output is correct
20 Correct 18 ms 8568 KB Output is correct
21 Correct 25 ms 8568 KB Output is correct
22 Correct 18 ms 8568 KB Output is correct
23 Correct 20 ms 8696 KB Output is correct
24 Correct 20 ms 8560 KB Output is correct
25 Correct 20 ms 8696 KB Output is correct
26 Correct 19 ms 8696 KB Output is correct
27 Correct 20 ms 8568 KB Output is correct
28 Correct 20 ms 8824 KB Output is correct
29 Correct 19 ms 8568 KB Output is correct
30 Correct 19 ms 8568 KB Output is correct
31 Correct 19 ms 8568 KB Output is correct
32 Correct 20 ms 8568 KB Output is correct
33 Correct 73 ms 22392 KB Output is correct
34 Correct 77 ms 22392 KB Output is correct
35 Correct 79 ms 29304 KB Output is correct
36 Correct 76 ms 29432 KB Output is correct
37 Correct 51 ms 20600 KB Output is correct
38 Correct 47 ms 21496 KB Output is correct
39 Correct 42 ms 20492 KB Output is correct
40 Correct 57 ms 24440 KB Output is correct
41 Correct 47 ms 20444 KB Output is correct
42 Correct 44 ms 20600 KB Output is correct
43 Correct 50 ms 24696 KB Output is correct
44 Correct 51 ms 24696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 8568 KB Output is correct
2 Correct 18 ms 8568 KB Output is correct
3 Correct 17 ms 8568 KB Output is correct
4 Correct 18 ms 8568 KB Output is correct
5 Correct 18 ms 8568 KB Output is correct
6 Correct 18 ms 8568 KB Output is correct
7 Correct 18 ms 8568 KB Output is correct
8 Correct 18 ms 8568 KB Output is correct
9 Correct 18 ms 8568 KB Output is correct
10 Correct 18 ms 8492 KB Output is correct
11 Correct 18 ms 8568 KB Output is correct
12 Correct 18 ms 8568 KB Output is correct
13 Correct 18 ms 8568 KB Output is correct
14 Correct 18 ms 8568 KB Output is correct
15 Correct 18 ms 8568 KB Output is correct
16 Correct 18 ms 8568 KB Output is correct
17 Correct 18 ms 8568 KB Output is correct
18 Correct 18 ms 8696 KB Output is correct
19 Correct 18 ms 8568 KB Output is correct
20 Correct 18 ms 8568 KB Output is correct
21 Correct 18 ms 8568 KB Output is correct
22 Correct 18 ms 8568 KB Output is correct
23 Correct 19 ms 8568 KB Output is correct
24 Correct 20 ms 8724 KB Output is correct
25 Correct 19 ms 8696 KB Output is correct
26 Correct 20 ms 8700 KB Output is correct
27 Correct 19 ms 8568 KB Output is correct
28 Correct 19 ms 8568 KB Output is correct
29 Correct 19 ms 8568 KB Output is correct
30 Correct 19 ms 8568 KB Output is correct
31 Correct 19 ms 8568 KB Output is correct
32 Correct 20 ms 8568 KB Output is correct
33 Correct 142 ms 23312 KB Output is correct
34 Correct 192 ms 31864 KB Output is correct
35 Correct 221 ms 23288 KB Output is correct
36 Correct 222 ms 27092 KB Output is correct
37 Correct 80 ms 22392 KB Output is correct
38 Correct 82 ms 22328 KB Output is correct
39 Correct 80 ms 29304 KB Output is correct
40 Correct 78 ms 29432 KB Output is correct
41 Correct 53 ms 20600 KB Output is correct
42 Correct 49 ms 21492 KB Output is correct
43 Correct 44 ms 20412 KB Output is correct
44 Correct 58 ms 24360 KB Output is correct
45 Correct 47 ms 20472 KB Output is correct
46 Correct 44 ms 20572 KB Output is correct
47 Correct 51 ms 24700 KB Output is correct
48 Correct 51 ms 24696 KB Output is correct
49 Correct 323 ms 24568 KB Output is correct
50 Correct 315 ms 24440 KB Output is correct
51 Correct 173 ms 31380 KB Output is correct
52 Correct 151 ms 30780 KB Output is correct
53 Correct 383 ms 22776 KB Output is correct
54 Correct 135 ms 23288 KB Output is correct
55 Correct 121 ms 21556 KB Output is correct
56 Correct 138 ms 26232 KB Output is correct
57 Correct 184 ms 22264 KB Output is correct
58 Correct 151 ms 22648 KB Output is correct
59 Correct 53 ms 24708 KB Output is correct