Submission #1049860

# Submission time Handle Problem Language Result Execution time Memory
1049860 2024-08-09T05:48:30 Z TAhmed33 Horses (IOI15_horses) C++
57 / 100
1500 ms 114876 KB
#include "horses.h"
#include <bits/stdc++.h>
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:19:23: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   19 |  return (a * 1ll * b) % MOD;
      |         ~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 72028 KB Output is correct
2 Correct 7 ms 72204 KB Output is correct
3 Correct 7 ms 72028 KB Output is correct
4 Correct 6 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 7 ms 72024 KB Output is correct
8 Correct 8 ms 72028 KB Output is correct
9 Correct 7 ms 72028 KB Output is correct
10 Correct 7 ms 72120 KB Output is correct
11 Correct 7 ms 72024 KB Output is correct
12 Correct 7 ms 72028 KB Output is correct
13 Correct 7 ms 72236 KB Output is correct
14 Correct 6 ms 72028 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 72024 KB Output is correct
18 Correct 7 ms 72028 KB Output is correct
19 Correct 7 ms 72152 KB Output is correct
20 Correct 7 ms 72028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 72028 KB Output is correct
2 Correct 6 ms 72184 KB Output is correct
3 Correct 7 ms 72212 KB Output is correct
4 Correct 7 ms 72028 KB Output is correct
5 Correct 7 ms 72120 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 72028 KB Output is correct
9 Correct 8 ms 72228 KB Output is correct
10 Correct 7 ms 72188 KB Output is correct
11 Correct 7 ms 72028 KB Output is correct
12 Correct 7 ms 72116 KB Output is correct
13 Correct 9 ms 72148 KB Output is correct
14 Correct 7 ms 72028 KB Output is correct
15 Correct 7 ms 72028 KB Output is correct
16 Correct 7 ms 72028 KB Output is correct
17 Correct 6 ms 72168 KB Output is correct
18 Correct 8 ms 72028 KB Output is correct
19 Correct 6 ms 72028 KB Output is correct
20 Correct 7 ms 72024 KB Output is correct
21 Correct 6 ms 72120 KB Output is correct
22 Correct 7 ms 72028 KB Output is correct
23 Correct 9 ms 72188 KB Output is correct
24 Correct 9 ms 72280 KB Output is correct
25 Correct 9 ms 72284 KB Output is correct
26 Correct 9 ms 72284 KB Output is correct
27 Correct 9 ms 72284 KB Output is correct
28 Correct 9 ms 72284 KB Output is correct
29 Correct 9 ms 72284 KB Output is correct
30 Correct 9 ms 72284 KB Output is correct
31 Correct 9 ms 72284 KB Output is correct
32 Correct 9 ms 72184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1444 ms 103736 KB Output is correct
2 Execution timed out 1517 ms 112136 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 72028 KB Output is correct
2 Correct 6 ms 72184 KB Output is correct
3 Correct 6 ms 72028 KB Output is correct
4 Correct 6 ms 72248 KB Output is correct
5 Correct 8 ms 72228 KB Output is correct
6 Correct 8 ms 72116 KB Output is correct
7 Correct 7 ms 72028 KB Output is correct
8 Correct 7 ms 72160 KB Output is correct
9 Correct 7 ms 72024 KB Output is correct
10 Correct 7 ms 72028 KB Output is correct
11 Correct 7 ms 72120 KB Output is correct
12 Correct 7 ms 72200 KB Output is correct
13 Correct 9 ms 72024 KB Output is correct
14 Correct 7 ms 72204 KB Output is correct
15 Correct 7 ms 72164 KB Output is correct
16 Correct 6 ms 72140 KB Output is correct
17 Correct 7 ms 72028 KB Output is correct
18 Correct 6 ms 72028 KB Output is correct
19 Correct 6 ms 72028 KB Output is correct
20 Correct 7 ms 72140 KB Output is correct
21 Correct 7 ms 72028 KB Output is correct
22 Correct 7 ms 72188 KB Output is correct
23 Correct 9 ms 72136 KB Output is correct
24 Correct 9 ms 72284 KB Output is correct
25 Correct 9 ms 72284 KB Output is correct
26 Correct 9 ms 72284 KB Output is correct
27 Correct 9 ms 72136 KB Output is correct
28 Correct 9 ms 72284 KB Output is correct
29 Correct 9 ms 72028 KB Output is correct
30 Correct 9 ms 72196 KB Output is correct
31 Correct 9 ms 72284 KB Output is correct
32 Correct 9 ms 72284 KB Output is correct
33 Correct 1294 ms 101436 KB Output is correct
34 Correct 1293 ms 105296 KB Output is correct
35 Correct 1325 ms 112296 KB Output is correct
36 Correct 1322 ms 112236 KB Output is correct
37 Correct 1282 ms 103536 KB Output is correct
38 Correct 1283 ms 104444 KB Output is correct
39 Correct 1305 ms 103492 KB Output is correct
40 Correct 1334 ms 107340 KB Output is correct
41 Correct 1320 ms 103488 KB Output is correct
42 Correct 1320 ms 103524 KB Output is correct
43 Correct 1357 ms 107804 KB Output is correct
44 Correct 1303 ms 107800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 72024 KB Output is correct
2 Correct 7 ms 72028 KB Output is correct
3 Correct 7 ms 72028 KB Output is correct
4 Correct 7 ms 72024 KB Output is correct
5 Correct 7 ms 72028 KB Output is correct
6 Correct 6 ms 72204 KB Output is correct
7 Correct 8 ms 72220 KB Output is correct
8 Correct 7 ms 72192 KB Output is correct
9 Correct 6 ms 72144 KB Output is correct
10 Correct 7 ms 72164 KB Output is correct
11 Correct 7 ms 72028 KB Output is correct
12 Correct 7 ms 72028 KB Output is correct
13 Correct 7 ms 72028 KB Output is correct
14 Correct 7 ms 72028 KB Output is correct
15 Correct 6 ms 72028 KB Output is correct
16 Correct 7 ms 72220 KB Output is correct
17 Correct 6 ms 72028 KB Output is correct
18 Correct 7 ms 72160 KB Output is correct
19 Correct 7 ms 72028 KB Output is correct
20 Correct 6 ms 72152 KB Output is correct
21 Correct 7 ms 72024 KB Output is correct
22 Correct 7 ms 72220 KB Output is correct
23 Correct 10 ms 72272 KB Output is correct
24 Correct 10 ms 72156 KB Output is correct
25 Correct 10 ms 72280 KB Output is correct
26 Correct 10 ms 72284 KB Output is correct
27 Correct 12 ms 72156 KB Output is correct
28 Correct 10 ms 72280 KB Output is correct
29 Correct 11 ms 72284 KB Output is correct
30 Correct 10 ms 72276 KB Output is correct
31 Correct 9 ms 72284 KB Output is correct
32 Correct 9 ms 72284 KB Output is correct
33 Correct 1438 ms 103992 KB Output is correct
34 Execution timed out 1505 ms 114876 KB Time limit exceeded
35 Halted 0 ms 0 KB -