답안 #785209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
785209 2023-07-17T07:10:49 Z NothingXD 말 (IOI15_horses) C++17
77 / 100
1500 ms 61680 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);
	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;
}

void change(int v, int l, int r, int idx){
	if (idx < l || r <= idx) return;
	if (l + 1 == r){
		seg[v] = x[l];
		return;
	}
	int mid = (l + r) >> 1;
	change(v << 1, l, mid, idx);
	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 (idx < l || r <= idx) return;
	if (l + 1 == r){
		dp[v][0] = x[l] * y[l];
		dp[v][1] = x[l];
		return;
	}
	int mid = (l + r) >> 1;
	change2(v << 1, l, mid, idx);
	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);
}

set<int> st;

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];
		if (x[i] > 1) st.insert(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:68:7: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   68 |   tmp *= seg[v << 1 | 1];
      |   ~~~~^~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int get(int, int, int, int, int)':
horses.cpp:76:38: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   76 |  if (ql <= l && r <= qr) return seg[v];
      |                                 ~~~~~^
horses.cpp:78:77: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   78 |  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:124:26: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  124 |  return 1ll * tmp * tmp2 % mod;
      |         ~~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 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 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 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 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 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 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 340 KB Output is correct
7 Correct 0 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 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 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 468 KB Output is correct
26 Correct 1 ms 468 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 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 61164 KB Output is correct
2 Correct 287 ms 61680 KB Output is correct
3 Correct 241 ms 61632 KB Output is correct
4 Correct 301 ms 61576 KB Output is correct
# 결과 실행 시간 메모리 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 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 212 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 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 1 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 468 KB Output is correct
26 Correct 1 ms 476 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 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 55 ms 36800 KB Output is correct
34 Correct 49 ms 36800 KB Output is correct
35 Correct 160 ms 60828 KB Output is correct
36 Correct 158 ms 60784 KB Output is correct
37 Correct 41 ms 36764 KB Output is correct
38 Correct 86 ms 48564 KB Output is correct
39 Correct 35 ms 36692 KB Output is correct
40 Correct 283 ms 60820 KB Output is correct
41 Correct 34 ms 36700 KB Output is correct
42 Correct 35 ms 36748 KB Output is correct
43 Correct 137 ms 60660 KB Output is correct
44 Correct 135 ms 60604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 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 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 1 ms 340 KB Output is correct
13 Correct 0 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 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 296 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 468 KB Output is correct
26 Correct 1 ms 468 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 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 183 ms 61200 KB Output is correct
34 Correct 264 ms 61592 KB Output is correct
35 Correct 248 ms 61652 KB Output is correct
36 Correct 281 ms 61616 KB Output is correct
37 Correct 48 ms 36856 KB Output is correct
38 Correct 51 ms 36836 KB Output is correct
39 Correct 159 ms 60804 KB Output is correct
40 Correct 155 ms 60800 KB Output is correct
41 Correct 42 ms 36768 KB Output is correct
42 Correct 100 ms 48516 KB Output is correct
43 Correct 40 ms 36708 KB Output is correct
44 Correct 247 ms 60736 KB Output is correct
45 Correct 34 ms 36684 KB Output is correct
46 Correct 42 ms 36784 KB Output is correct
47 Correct 136 ms 60636 KB Output is correct
48 Correct 140 ms 60656 KB Output is correct
49 Correct 154 ms 38148 KB Output is correct
50 Correct 168 ms 38040 KB Output is correct
51 Correct 238 ms 61640 KB Output is correct
52 Correct 215 ms 61656 KB Output is correct
53 Correct 152 ms 37608 KB Output is correct
54 Correct 171 ms 49324 KB Output is correct
55 Correct 94 ms 36860 KB Output is correct
56 Execution timed out 1594 ms 60976 KB Time limit exceeded
57 Halted 0 ms 0 KB -