Submission #785212

# Submission time Handle Problem Language Result Execution time Memory
785212 2023-07-17T07:15:21 Z NothingXD Horses (IOI15_horses) C++17
77 / 100
1500 ms 38276 KB
#include "horses.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef complex<ld> point;

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;
ll x[maxn], y[maxn];
ll seg[maxn << 2], dp[maxn << 2][2];
bool of[maxn << 2];

void build(int v, int l, int r){
	if (l + 1 == r){
		seg[v] = x[l];
		return;
	}
	int mid = (l + r) >> 1;
	build(v << 1, l, mid);
	build(v << 1 | 1, mid, r);
	seg[v] = 1ll * seg[v << 1] * seg[v << 1 | 1];
	if (seg[v] >= mod || of[v << 1] || of[v << 1 | 1]) of[v] = true;
	seg[v] %= mod;
}

void change(int v, int l, int r, int idx){
	if (l + 1 == r){
		seg[v] = x[l];
		return;
	}
	int mid = (l + r) >> 1;
	if (idx < mid) change(v << 1, l, mid, idx);
	else change(v << 1 | 1, mid, r, idx);
	ll tmp = 1ll * seg[v << 1] * seg[v << 1 | 1];
	if (tmp >= mod || of[v << 1] || of[v << 1 | 1]) of[v] = true;
	seg[v] = tmp % mod;
}

int find(int v, int l, int r, int tmp){
	if (!of[v] && 1ll * tmp * seg[v] < mod) return -1;
	if (l + 1 == r) return l;
	int mid = (l + r) >> 1;
	int res = find(v << 1 | 1, mid, r, tmp);
	if (res == -1){
		tmp *= seg[v << 1 | 1];
		res = find(v << 1, l, mid, tmp);
	}
	return res;
}

int get(int v, int l, int r, int ql, int qr){
	if (qr <= l || r <= ql) return 1;
	if (ql <= l && r <= qr) return seg[v];
	int mid = (l + r) >> 1;
	return 1ll * get(v << 1, l, mid, ql, qr) * get(v << 1 | 1, mid, r, ql, qr) % mod;
}

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;
	build2(v << 1, l, mid);
	build2(v << 1 | 1, mid, r);
	dp[v][0] = max(dp[v << 1][0], dp[v << 1][1] * dp[v << 1 | 1][0]);
	dp[v][1] = dp[v << 1][1] * dp[v << 1 | 1][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;
	if (idx < mid) change2(v << 1, l, mid, idx);
	else change2(v << 1 | 1, mid, r, idx);
	dp[v][0] = max(dp[v << 1][0], dp[v << 1][1] * dp[v << 1 | 1][0]);
	dp[v][1] = dp[v << 1][1] * dp[v << 1 | 1][1];
}

pll get2(int v, int l, int r, int ql, int qr){
	if (qr <= l || r <= ql) return {1, 1};
	if (ql <= l && r <= qr) return MP(dp[v][0], dp[v][1]);
	int mid = (l + r) >> 1;
	pll a = get2(v << 1, l, mid, ql, qr);
	pll b = get2(v << 1 | 1, mid, r, ql, qr);
	return MP(max(a.F, a.S * b.F), a.S * b.S);
}

int Calc(){
	int idx = find(1, 0, n, 1);
	if (idx == -1) idx = 0;
	int tmp = get(1, 0, n, 0, idx+1);
	ll tmp2 = max(y[idx], get2(1, 0, n+1, idx+1, n+1).F) % mod;
	return 1ll * tmp * tmp2 % mod;
}

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];
	}
	build(1, 0, n);
	build2(1, 0, n+1);
	return Calc();
}

int updateX(int pos, int val) {
	x[pos] = val;
	change(1, 0, n, pos);
	change2(1, 0, n+1, pos);
	return Calc();
}

int updateY(int pos, int val) {
	y[pos] = val;
	change2(1, 0, n+1, pos);
	return Calc();
}

Compilation message

horses.cpp: In function 'int find(int, int, int, int)':
horses.cpp:66:7: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   66 |   tmp *= seg[v << 1 | 1];
      |   ~~~~^~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int get(int, int, int, int, int)':
horses.cpp:74:38: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   74 |  if (ql <= l && r <= qr) return seg[v];
      |                                 ~~~~~^
horses.cpp:76:77: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   76 |  return 1ll * get(v << 1, l, mid, ql, qr) * get(v << 1 | 1, mid, r, ql, qr) % mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int Calc()':
horses.cpp:119:26: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  119 |  return 1ll * tmp * tmp2 % mod;
      |         ~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 416 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 37672 KB Output is correct
2 Correct 175 ms 38188 KB Output is correct
3 Correct 141 ms 38084 KB Output is correct
4 Correct 177 ms 38112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 416 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 47 ms 36848 KB Output is correct
34 Correct 48 ms 36848 KB Output is correct
35 Correct 66 ms 37244 KB Output is correct
36 Correct 68 ms 37224 KB Output is correct
37 Correct 46 ms 36756 KB Output is correct
38 Correct 42 ms 36708 KB Output is correct
39 Correct 34 ms 36692 KB Output is correct
40 Correct 160 ms 37264 KB Output is correct
41 Correct 32 ms 36724 KB Output is correct
42 Correct 40 ms 36796 KB Output is correct
43 Correct 45 ms 37176 KB Output is correct
44 Correct 45 ms 37196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 352 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 86 ms 37640 KB Output is correct
34 Correct 168 ms 38164 KB Output is correct
35 Correct 137 ms 38168 KB Output is correct
36 Correct 172 ms 38176 KB Output is correct
37 Correct 47 ms 36816 KB Output is correct
38 Correct 48 ms 36856 KB Output is correct
39 Correct 64 ms 37212 KB Output is correct
40 Correct 66 ms 37224 KB Output is correct
41 Correct 40 ms 36748 KB Output is correct
42 Correct 41 ms 36780 KB Output is correct
43 Correct 42 ms 36696 KB Output is correct
44 Correct 176 ms 37368 KB Output is correct
45 Correct 43 ms 36724 KB Output is correct
46 Correct 38 ms 36812 KB Output is correct
47 Correct 54 ms 37200 KB Output is correct
48 Correct 49 ms 37224 KB Output is correct
49 Correct 173 ms 38276 KB Output is correct
50 Correct 190 ms 38036 KB Output is correct
51 Correct 125 ms 38120 KB Output is correct
52 Correct 121 ms 38112 KB Output is correct
53 Correct 146 ms 37676 KB Output is correct
54 Correct 116 ms 37620 KB Output is correct
55 Correct 106 ms 36884 KB Output is correct
56 Execution timed out 1583 ms 37556 KB Time limit exceeded
57 Halted 0 ms 0 KB -