Submission #583786

# Submission time Handle Problem Language Result Execution time Memory
583786 2022-06-26T08:05:14 Z M_W Horses (IOI15_horses) C++17
17 / 100
510 ms 29652 KB
#include <bits/stdc++.h>
using namespace std;
long long tp[500001 << 2], tmd[500001 << 2];
const long long md = 1e9 + 7;
int N;

void upd_product(int v, int tl, int tr, int pos, int val){
	if(tl == pos && tl == tr){
		tp[v] = tmd[v] = val * 1ll;
		return;
	}
	int tm = (tl + tr) >> 1;
	if(pos <= tm) upd_product(v * 2, tl, tm, pos, val);
	else upd_product(v * 2 + 1, tm + 1, tr, pos, val);
	
	tmd[v] = (tmd[v * 2] * tmd[v * 2 + 1]) % md;
	tp[v] = tp[v * 2] * tp[v * 2 + 1];
	if(tp[v] > 1000000000 * 1ll || tp[v * 2] == -1 || tp[v * 2 + 1] == -1) tp[v] = -1;
}

long long query_product(int v, int tl, int tr, int l, int r){
	if(l > r) return 1ll;
	if(tl == l && tr == r) return tp[v];
	int tm = (tl + tr) >> 1;
	
	long long left = query_product(v * 2, tl, tm, l, min(r, tm));
	long long right = query_product(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	
	if(left == -1 || right == -1 || left * right > 1000000000 * 1ll) return -1;
	return left * right;
}


long long query_md(int v, int tl, int tr, int l, int r){
	if(l > r) return 1ll;
	if(tl == l && tr == r) return tmd[v];
	int tm = (tl + tr) >> 1;
	
	long long left = query_product(v * 2, tl, tm, l, min(r, tm));
	long long right = query_product(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
	
	return (left * right) % md;
}

// Actual query tree
int t[500001 << 2];
long long Y[500001];

void build(int v, int tl, int tr){
	if(tl == tr){
		t[v] = tl;
		return;
	}
	int tm = (tl + tr) >> 1;
	build(v * 2, tl, tm);
	build(v * 2 + 1, tm + 1, tr);
	
	long long Yl = Y[t[v * 2]], Yr = Y[t[v * 2 + 1]];
	long long prod = query_product(1, 0, N - 1, t[v * 2] + 1, t[v * 2 + 1]);
	
	if(prod == -1 || prod * Yr > Yl) t[v] = t[v * 2 + 1];
	else t[v] = t[v * 2];
}

void ins(int v, int tl, int tr, int pos){
	if(tl == pos && tl == tr) return;
	int tm = (tl + tr) >> 1;
	
	if(pos <= tm) ins(v * 2, tl, tm, pos);
	else ins(v * 2 + 1, tm + 1, tr, pos);
	
	long long Yl = Y[t[v * 2]], Yr = Y[t[v * 2 + 1]];
	long long prod = query_product(1, 0, N - 1, t[v * 2] + 1, t[v * 2 + 1]);
	
	if(prod == -1 || prod * Yr > Yl) t[v] = t[v * 2 + 1];
	else t[v] = t[v * 2];
}

int init(int N_tmp, int X[], int Y_tmp[]){
	N = N_tmp;
	for(int i = 0; i < N; i++) upd_product(1, 0, N - 1, i, X[i]);
	for(int i = 0; i < N; i++) Y[i] = Y_tmp[i] * 1ll;
	build(1, 0, N - 1);
	
	return int((query_md(1, 0, N - 1, 0, t[1]) * Y[t[1]]) % md);
}

int updateX(int pos, int val){
	upd_product(1, 0, N - 1, pos, val);
	ins(1, 0, N - 1, pos);
	return int((query_md(1, 0, N - 1, 0, t[1]) * Y[t[1]]) % md);
}

int updateY(int pos, int val){
	Y[pos] = val;
	ins(1, 0, N - 1, pos);
	return int((query_md(1, 0, N - 1, 0, t[1]) * Y[t[1]]) % md);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 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 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Incorrect 1 ms 212 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 510 ms 29652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Incorrect 0 ms 212 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 260 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Incorrect 0 ms 276 KB Output isn't correct
23 Halted 0 ms 0 KB -