답안 #1049894

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1049894 2024-08-09T05:57:24 Z TAhmed33 말 (IOI15_horses) C++
100 / 100
1022 ms 114116 KB
#include "horses.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
#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 (lazy[node] == 0) return;
		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]);
	}
} 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.tree[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:21:23: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   21 |  return (a * 1ll * b) % MOD;
      |         ~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 72028 KB Output is correct
2 Correct 6 ms 72028 KB Output is correct
3 Correct 6 ms 72028 KB Output is correct
4 Correct 7 ms 72028 KB Output is correct
5 Correct 7 ms 72216 KB Output is correct
6 Correct 7 ms 72148 KB Output is correct
7 Correct 7 ms 72124 KB Output is correct
8 Correct 6 ms 72028 KB Output is correct
9 Correct 7 ms 72024 KB Output is correct
10 Correct 7 ms 72024 KB Output is correct
11 Correct 7 ms 72024 KB Output is correct
12 Correct 7 ms 72028 KB Output is correct
13 Correct 6 ms 72216 KB Output is correct
14 Correct 7 ms 72088 KB Output is correct
15 Correct 7 ms 72024 KB Output is correct
16 Correct 7 ms 72028 KB Output is correct
17 Correct 6 ms 72028 KB Output is correct
18 Correct 7 ms 72028 KB Output is correct
19 Correct 6 ms 72028 KB Output is correct
20 Correct 6 ms 72028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 72024 KB Output is correct
2 Correct 6 ms 72028 KB Output is correct
3 Correct 7 ms 72028 KB Output is correct
4 Correct 7 ms 72224 KB Output is correct
5 Correct 7 ms 72252 KB Output is correct
6 Correct 7 ms 72028 KB Output is correct
7 Correct 7 ms 72192 KB Output is correct
8 Correct 7 ms 72028 KB Output is correct
9 Correct 7 ms 72224 KB Output is correct
10 Correct 7 ms 72184 KB Output is correct
11 Correct 6 ms 72208 KB Output is correct
12 Correct 6 ms 72028 KB Output is correct
13 Correct 6 ms 72192 KB Output is correct
14 Correct 6 ms 72160 KB Output is correct
15 Correct 7 ms 72028 KB Output is correct
16 Correct 7 ms 72124 KB Output is correct
17 Correct 7 ms 72028 KB Output is correct
18 Correct 7 ms 72024 KB Output is correct
19 Correct 6 ms 72152 KB Output is correct
20 Correct 8 ms 72184 KB Output is correct
21 Correct 7 ms 72028 KB Output is correct
22 Correct 7 ms 72228 KB Output is correct
23 Correct 9 ms 72284 KB Output is correct
24 Correct 9 ms 72272 KB Output is correct
25 Correct 8 ms 72284 KB Output is correct
26 Correct 8 ms 72284 KB Output is correct
27 Correct 8 ms 72284 KB Output is correct
28 Correct 8 ms 72284 KB Output is correct
29 Correct 8 ms 72272 KB Output is correct
30 Correct 8 ms 72284 KB Output is correct
31 Correct 9 ms 72284 KB Output is correct
32 Correct 8 ms 72284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 818 ms 103060 KB Output is correct
2 Correct 924 ms 105108 KB Output is correct
3 Correct 889 ms 102200 KB Output is correct
4 Correct 910 ms 109960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 72028 KB Output is correct
2 Correct 6 ms 72028 KB Output is correct
3 Correct 7 ms 72220 KB Output is correct
4 Correct 7 ms 72028 KB Output is correct
5 Correct 7 ms 72224 KB Output is correct
6 Correct 7 ms 72028 KB Output is correct
7 Correct 7 ms 72228 KB Output is correct
8 Correct 7 ms 72172 KB Output is correct
9 Correct 7 ms 72152 KB Output is correct
10 Correct 7 ms 72028 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 72212 KB Output is correct
14 Correct 7 ms 72028 KB Output is correct
15 Correct 7 ms 72028 KB Output is correct
16 Correct 6 ms 72184 KB Output is correct
17 Correct 7 ms 72024 KB Output is correct
18 Correct 7 ms 72024 KB Output is correct
19 Correct 7 ms 72028 KB Output is correct
20 Correct 7 ms 72132 KB Output is correct
21 Correct 7 ms 72156 KB Output is correct
22 Correct 7 ms 72028 KB Output is correct
23 Correct 9 ms 72276 KB Output is correct
24 Correct 8 ms 72132 KB Output is correct
25 Correct 8 ms 72284 KB Output is correct
26 Correct 8 ms 72284 KB Output is correct
27 Correct 8 ms 72280 KB Output is correct
28 Correct 9 ms 72284 KB Output is correct
29 Correct 8 ms 72180 KB Output is correct
30 Correct 8 ms 72284 KB Output is correct
31 Correct 8 ms 72284 KB Output is correct
32 Correct 8 ms 72216 KB Output is correct
33 Correct 700 ms 100904 KB Output is correct
34 Correct 699 ms 101436 KB Output is correct
35 Correct 746 ms 101428 KB Output is correct
36 Correct 758 ms 101436 KB Output is correct
37 Correct 689 ms 101440 KB Output is correct
38 Correct 709 ms 101460 KB Output is correct
39 Correct 634 ms 101204 KB Output is correct
40 Correct 709 ms 101460 KB Output is correct
41 Correct 627 ms 101432 KB Output is correct
42 Correct 625 ms 101436 KB Output is correct
43 Correct 707 ms 101204 KB Output is correct
44 Correct 693 ms 101200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 72024 KB Output is correct
2 Correct 7 ms 72028 KB Output is correct
3 Correct 6 ms 72028 KB Output is correct
4 Correct 7 ms 72028 KB Output is correct
5 Correct 7 ms 72024 KB Output is correct
6 Correct 7 ms 72188 KB Output is correct
7 Correct 7 ms 72216 KB Output is correct
8 Correct 7 ms 72176 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 72216 KB Output is correct
12 Correct 8 ms 72028 KB Output is correct
13 Correct 8 ms 72028 KB Output is correct
14 Correct 8 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 72028 KB Output is correct
18 Correct 7 ms 72028 KB Output is correct
19 Correct 7 ms 72028 KB Output is correct
20 Correct 7 ms 72028 KB Output is correct
21 Correct 8 ms 72232 KB Output is correct
22 Correct 7 ms 72212 KB Output is correct
23 Correct 10 ms 72280 KB Output is correct
24 Correct 8 ms 72284 KB Output is correct
25 Correct 8 ms 72144 KB Output is correct
26 Correct 8 ms 72028 KB Output is correct
27 Correct 8 ms 72284 KB Output is correct
28 Correct 9 ms 72284 KB Output is correct
29 Correct 10 ms 72284 KB Output is correct
30 Correct 12 ms 72284 KB Output is correct
31 Correct 9 ms 72284 KB Output is correct
32 Correct 8 ms 72204 KB Output is correct
33 Correct 796 ms 101516 KB Output is correct
34 Correct 1022 ms 102480 KB Output is correct
35 Correct 932 ms 106148 KB Output is correct
36 Correct 919 ms 109908 KB Output is correct
37 Correct 672 ms 105360 KB Output is correct
38 Correct 658 ms 103252 KB Output is correct
39 Correct 734 ms 108116 KB Output is correct
40 Correct 733 ms 112220 KB Output is correct
41 Correct 655 ms 103560 KB Output is correct
42 Correct 730 ms 104528 KB Output is correct
43 Correct 644 ms 103484 KB Output is correct
44 Correct 739 ms 106804 KB Output is correct
45 Correct 712 ms 103468 KB Output is correct
46 Correct 665 ms 103572 KB Output is correct
47 Correct 697 ms 107604 KB Output is correct
48 Correct 715 ms 107600 KB Output is correct
49 Correct 837 ms 106908 KB Output is correct
50 Correct 879 ms 107432 KB Output is correct
51 Correct 839 ms 114116 KB Output is correct
52 Correct 833 ms 113760 KB Output is correct
53 Correct 779 ms 105812 KB Output is correct
54 Correct 813 ms 106120 KB Output is correct
55 Correct 736 ms 104368 KB Output is correct
56 Correct 884 ms 109228 KB Output is correct
57 Correct 720 ms 105040 KB Output is correct
58 Correct 733 ms 105672 KB Output is correct
59 Correct 709 ms 107840 KB Output is correct