답안 #832634

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832634 2023-08-21T12:49:33 Z AkramElOmrani 말 (IOI15_horses) C++17
100 / 100
240 ms 46520 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
 
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);


const int N = 5e5, mod = 1e9 + 7;
struct Node {
	int ans, x, y; // ans is the answer, x is the value of x, y is the value of y
	double X, Y, m; // X = sum of logs of X
};

Node tree[2000010];

int mul(int a, int b) {
	a = (ll)a * b % mod;
	return a;
}

void upd(int node, int l, int r, int p, int x, int y) {
	if(r < p || p < l) return;
	if(l == r) {
		if(x > 0) {
			tree[node].X = log10(x); tree[node].x = x; tree[node].m = tree[node].X + tree[node].Y;
		}
		if(y > 0) {
			tree[node].Y = log10(y); tree[node].y = y; tree[node].m = tree[node].X + tree[node].Y;
		}
		tree[node].ans = mul(tree[node].x, tree[node].y);
		// dbg(node, tree[node].x)
		return;
	}
	int mid = (l + r) / 2;
	upd(node * 2, l, mid, p, x, y);
	// dbg(node * 2, tree[node * 2].x)
	upd(node * 2 + 1, mid + 1, r, p, x, y);
	tree[node].X = tree[node * 2 + 1].X + tree[node * 2].X;
	tree[node].x = mul(tree[node * 2 + 1].x, tree[node * 2].x);

	// check if the answer is on the left or on the right
	if(tree[node * 2].m < tree[node * 2 + 1].m + tree[node * 2].X) {
		tree[node].m = tree[node * 2 + 1].m + tree[node * 2].X;
		tree[node].ans = mul(tree[node * 2 + 1].ans, tree[node * 2].x);
	} else {
		tree[node].m = tree[node * 2].m;
		tree[node].ans = tree[node * 2].ans;
	}
}

int n;
int init(int n_, int x[], int y[]) {
	n = n_;
	for(int i = 0; i < n; ++i) {
		upd(1, 0, n - 1, i, x[i], y[i]);
	}

	// dbg(tree[1].m, tree[1].x, tree[1].ans, tree[1].X);
	return tree[1].ans;
}
int updateX(int pos, int val) {
	upd(1, 0, n - 1, pos, val, 0);
	return tree[1].ans;
}
int updateY(int pos, int val) {
	upd(1, 0, n - 1, pos, 0, val);
	return tree[1].ans;
}

Compilation message

horses.cpp: In function 'int mul(int, int)':
horses.cpp:23:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   23 |  a = (ll)a * b % mod;
      |      ~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 0 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 1 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 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 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 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 0 ms 212 KB Output is correct
12 Correct 1 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 1 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 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 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 344 KB Output is correct
30 Correct 1 ms 340 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 177 ms 46136 KB Output is correct
2 Correct 234 ms 46200 KB Output is correct
3 Correct 205 ms 46312 KB Output is correct
4 Correct 222 ms 46248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 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 0 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 1 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 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 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 340 KB Output is correct
26 Correct 1 ms 340 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 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 159 ms 45344 KB Output is correct
34 Correct 161 ms 45292 KB Output is correct
35 Correct 174 ms 45312 KB Output is correct
36 Correct 175 ms 45344 KB Output is correct
37 Correct 144 ms 45284 KB Output is correct
38 Correct 152 ms 45324 KB Output is correct
39 Correct 136 ms 45252 KB Output is correct
40 Correct 160 ms 45308 KB Output is correct
41 Correct 138 ms 45276 KB Output is correct
42 Correct 137 ms 45244 KB Output is correct
43 Correct 153 ms 45208 KB Output is correct
44 Correct 154 ms 45236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 0 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 212 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 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 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 340 KB Output is correct
26 Correct 1 ms 340 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 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 173 ms 46196 KB Output is correct
34 Correct 237 ms 46216 KB Output is correct
35 Correct 212 ms 46232 KB Output is correct
36 Correct 217 ms 46196 KB Output is correct
37 Correct 161 ms 45240 KB Output is correct
38 Correct 165 ms 45364 KB Output is correct
39 Correct 178 ms 45308 KB Output is correct
40 Correct 178 ms 45292 KB Output is correct
41 Correct 140 ms 45280 KB Output is correct
42 Correct 155 ms 45272 KB Output is correct
43 Correct 136 ms 45276 KB Output is correct
44 Correct 154 ms 45276 KB Output is correct
45 Correct 140 ms 45260 KB Output is correct
46 Correct 162 ms 45308 KB Output is correct
47 Correct 152 ms 45224 KB Output is correct
48 Correct 153 ms 45236 KB Output is correct
49 Correct 214 ms 46240 KB Output is correct
50 Correct 240 ms 46132 KB Output is correct
51 Correct 217 ms 46252 KB Output is correct
52 Correct 206 ms 46212 KB Output is correct
53 Correct 210 ms 46228 KB Output is correct
54 Correct 218 ms 46128 KB Output is correct
55 Correct 169 ms 45364 KB Output is correct
56 Correct 192 ms 46236 KB Output is correct
57 Correct 169 ms 46208 KB Output is correct
58 Correct 178 ms 46520 KB Output is correct
59 Correct 176 ms 45480 KB Output is correct