Submission #1049881

# Submission time Handle Problem Language Result Execution time Memory
1049881 2024-08-09T05:53:55 Z TAhmed33 Horses (IOI15_horses) C++
57 / 100
1500 ms 106156 KB
#include "horses.h"
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 25;
#define mid ((l + r) >> 1)
#define tl (node << 1)
#define tr (node << 1 | 1)
typedef long double ld;
int add (int a, int b) {
	a += b; if (a >= MOD) a -= MOD;
	return a;
}
int sub (int a, int b) {
	a -= b; if (a < 0) a += MOD;
	return a;
}
int mul (int a, int b) {
	return (a * 1ll * b) % MOD;
}
int power (int a, int b) {
	if (!b) return 1;
	int u = power(a, b >> 1);
	u = mul(u, u);
	if (b & 1) u = mul(u, a);
	return u;
}
int inv (int x) {
	return power(x, MOD - 2);
}
int x[MAXN], y[MAXN], n;
struct SegmentTree {
	pair <ld, int> tree[MAXN << 2];
	ld lazy[MAXN << 2];
	void init (int l, int r, int node) {
		lazy[node] = 0; tree[node] = {ld(0), l};
		if (l == r) {
			return;
		}
		init(l, mid, tl); init(mid + 1, r, tr);
	}
	void prop (int l, int r, int node) {
		if (l != r) {
			lazy[tl] += lazy[node];
			lazy[tr] += lazy[node];
		}
		tree[node].first += lazy[node];
		lazy[node] = 0;
	}
	void update (int l, int r, int a, int b, ld c, int node) {
		prop(l, r, node);
		if (l > b || r < a) return;
		if (l >= a && r <= b) {
			lazy[node] += c;
			prop(l, r, node);
			return;
		}
		update(l, mid, a, b, c, tl); update(mid + 1, r, a, b, c, tr);
		tree[node] = max(tree[tl], tree[tr]);
	}
	pair <ld, int> get (int l, int r, int a, int b, int node) {
		prop(l, r, node);
		if (l > b || r < a) return {ld(0), n + 1};
		if (l >= a && r <= b) return tree[node];
		return max(get(l, mid, a, b, tl), get(mid + 1, r, a, b, tr));
	}
} cur;
struct SegmentTree2 {
	int tree[MAXN << 2], lazy[MAXN << 2];
	void init (int l, int r, int node) {
		tree[node] = 1; lazy[node] = 1;
		if (l == r) return;
		init(l, mid, tl); init(mid + 1, r, tr);
	}
	void prop (int l, int r, int node) {
		if (l != r) {
			lazy[tl] = mul(lazy[tl], lazy[node]);
			lazy[tr] = mul(lazy[tr], lazy[node]);
		}
		tree[node] = mul(tree[node], lazy[node]);
		lazy[node] = 1;
	}
	void update (int l, int r, int a, int b, int c, int node) {
		prop(l, r, node);
		if (l > b || r < a) return;
		if (l >= a && r <= b) {
			lazy[node] = mul(lazy[node], c);
			prop(l, r, node);
			return;
		}
		update(l, mid ,a, b, c, tl);
		update(mid + 1, r, a, b, c, tr);
	}
	int get (int l, int r, int a, int node) {
		prop(l, r, node);
		if (l == r) return tree[node];
		if (a <= mid) return get(l, mid, a, tl);
		else return get(mid + 1, r, a, tr);
	}
} cur2;
int ans () {
	auto z = cur.get(0, n - 1, 0, n - 1, 1);
	return cur2.get(0, n - 1, z.second, 1);
}
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];
	}
	cur.init(0, n - 1, 1);
	cur2.init(0, n - 1, 1);
	for (int i = 0; i < n; i++) {
		cur.update(0, n - 1, i, n - 1, log2(x[i]), 1);
		cur2.update(0, n - 1, i, n - 1, x[i], 1);
		cur.update(0, n - 1, i, i, log2(y[i]), 1);
		cur2.update(0, n - 1, i, i, y[i], 1);
	}
	return ans();
}

int updateX (int pos, int val) {	
	cur.update(0, n - 1, pos, n - 1, log2(val) - log2(x[pos]), 1);
	cur2.update(0, n - 1, pos, n - 1, mul(val, inv(x[pos])), 1);
	x[pos] = val;
	return ans();
}

int updateY (int pos, int val) {
	cur.update(0, n - 1, pos, pos, log2(val) - log2(y[pos]), 1);
	cur2.update(0, n - 1, pos, pos, mul(val, inv(y[pos])), 1);
	y[pos] = val;
	return ans();
}

Compilation message

horses.cpp: In function 'int mul(int, int)':
horses.cpp:20:23: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   20 |  return (a * 1ll * b) % MOD;
      |         ~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 72028 KB Output is correct
2 Correct 7 ms 72028 KB Output is correct
3 Correct 7 ms 72120 KB Output is correct
4 Correct 7 ms 72028 KB Output is correct
5 Correct 7 ms 72028 KB Output is correct
6 Correct 7 ms 72028 KB Output is correct
7 Correct 7 ms 72028 KB Output is correct
8 Correct 7 ms 72140 KB Output is correct
9 Correct 8 ms 72028 KB Output is correct
10 Correct 7 ms 72160 KB Output is correct
11 Correct 7 ms 72028 KB Output is correct
12 Correct 8 ms 72176 KB Output is correct
13 Correct 7 ms 72028 KB Output is correct
14 Correct 8 ms 72168 KB Output is correct
15 Correct 7 ms 72024 KB Output is correct
16 Correct 7 ms 72028 KB Output is correct
17 Correct 7 ms 72028 KB Output is correct
18 Correct 7 ms 72140 KB Output is correct
19 Correct 8 ms 72028 KB Output is correct
20 Correct 7 ms 72028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 72028 KB Output is correct
2 Correct 7 ms 72028 KB Output is correct
3 Correct 7 ms 72232 KB Output is correct
4 Correct 7 ms 72028 KB Output is correct
5 Correct 7 ms 72028 KB Output is correct
6 Correct 7 ms 72284 KB Output is correct
7 Correct 7 ms 72028 KB Output is correct
8 Correct 7 ms 72028 KB Output is correct
9 Correct 7 ms 72028 KB Output is correct
10 Correct 7 ms 72208 KB Output is correct
11 Correct 7 ms 72028 KB Output is correct
12 Correct 8 ms 72192 KB Output is correct
13 Correct 7 ms 72240 KB Output is correct
14 Correct 7 ms 72028 KB Output is correct
15 Correct 8 ms 72024 KB Output is correct
16 Correct 7 ms 72028 KB Output is correct
17 Correct 7 ms 72028 KB Output is correct
18 Correct 8 ms 72028 KB Output is correct
19 Correct 7 ms 72028 KB Output is correct
20 Correct 7 ms 72124 KB Output is correct
21 Correct 8 ms 72028 KB Output is correct
22 Correct 7 ms 72028 KB Output is correct
23 Correct 10 ms 72280 KB Output is correct
24 Correct 10 ms 72280 KB Output is correct
25 Correct 9 ms 72284 KB Output is correct
26 Correct 11 ms 72284 KB Output is correct
27 Correct 9 ms 72172 KB Output is correct
28 Correct 9 ms 72284 KB Output is correct
29 Correct 9 ms 72184 KB Output is correct
30 Correct 9 ms 72284 KB Output is correct
31 Correct 9 ms 72280 KB Output is correct
32 Correct 9 ms 72284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1376 ms 104024 KB Output is correct
2 Correct 1484 ms 102332 KB Output is correct
3 Execution timed out 1528 ms 106156 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 72160 KB Output is correct
2 Correct 8 ms 72028 KB Output is correct
3 Correct 7 ms 72248 KB Output is correct
4 Correct 7 ms 72028 KB Output is correct
5 Correct 8 ms 72028 KB Output is correct
6 Correct 7 ms 72028 KB Output is correct
7 Correct 7 ms 72028 KB Output is correct
8 Correct 8 ms 72028 KB Output is correct
9 Correct 7 ms 72028 KB Output is correct
10 Correct 8 ms 72028 KB Output is correct
11 Correct 8 ms 72028 KB Output is correct
12 Correct 9 ms 72144 KB Output is correct
13 Correct 8 ms 72028 KB Output is correct
14 Correct 7 ms 72124 KB Output is correct
15 Correct 7 ms 72024 KB Output is correct
16 Correct 7 ms 72028 KB Output is correct
17 Correct 8 ms 72024 KB Output is correct
18 Correct 11 ms 72124 KB Output is correct
19 Correct 8 ms 72024 KB Output is correct
20 Correct 7 ms 72024 KB Output is correct
21 Correct 7 ms 72028 KB Output is correct
22 Correct 7 ms 72028 KB Output is correct
23 Correct 10 ms 72284 KB Output is correct
24 Correct 9 ms 72284 KB Output is correct
25 Correct 9 ms 72120 KB Output is correct
26 Correct 11 ms 72284 KB Output is correct
27 Correct 9 ms 72140 KB Output is correct
28 Correct 9 ms 72284 KB Output is correct
29 Correct 8 ms 72284 KB Output is correct
30 Correct 9 ms 72164 KB Output is correct
31 Correct 11 ms 72284 KB Output is correct
32 Correct 9 ms 72128 KB Output is correct
33 Correct 1268 ms 105360 KB Output is correct
34 Correct 1281 ms 99228 KB Output is correct
35 Correct 1237 ms 101480 KB Output is correct
36 Correct 1237 ms 101448 KB Output is correct
37 Correct 1247 ms 101456 KB Output is correct
38 Correct 1230 ms 101440 KB Output is correct
39 Correct 1212 ms 101212 KB Output is correct
40 Correct 1209 ms 101432 KB Output is correct
41 Correct 1263 ms 101440 KB Output is correct
42 Correct 1239 ms 101432 KB Output is correct
43 Correct 1254 ms 101200 KB Output is correct
44 Correct 1222 ms 101436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 72248 KB Output is correct
2 Correct 7 ms 72028 KB Output is correct
3 Correct 7 ms 72156 KB Output is correct
4 Correct 7 ms 72028 KB Output is correct
5 Correct 7 ms 72028 KB Output is correct
6 Correct 8 ms 72028 KB Output is correct
7 Correct 8 ms 72028 KB Output is correct
8 Correct 8 ms 72168 KB Output is correct
9 Correct 7 ms 72028 KB Output is correct
10 Correct 9 ms 72228 KB Output is correct
11 Correct 7 ms 72180 KB Output is correct
12 Correct 8 ms 72028 KB Output is correct
13 Correct 7 ms 72116 KB Output is correct
14 Correct 7 ms 72160 KB Output is correct
15 Correct 7 ms 72028 KB Output is correct
16 Correct 7 ms 72028 KB Output is correct
17 Correct 7 ms 72148 KB Output is correct
18 Correct 7 ms 72028 KB Output is correct
19 Correct 7 ms 72140 KB Output is correct
20 Correct 7 ms 72204 KB Output is correct
21 Correct 7 ms 72028 KB Output is correct
22 Correct 7 ms 72196 KB Output is correct
23 Correct 9 ms 72144 KB Output is correct
24 Correct 9 ms 72284 KB Output is correct
25 Correct 9 ms 72300 KB Output is correct
26 Correct 10 ms 72300 KB Output is correct
27 Correct 10 ms 72128 KB Output is correct
28 Correct 9 ms 72156 KB Output is correct
29 Correct 9 ms 72280 KB Output is correct
30 Correct 9 ms 72284 KB Output is correct
31 Correct 10 ms 72300 KB Output is correct
32 Correct 10 ms 72228 KB Output is correct
33 Correct 1432 ms 104360 KB Output is correct
34 Execution timed out 1515 ms 102368 KB Time limit exceeded
35 Halted 0 ms 0 KB -