답안 #869916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869916 2023-11-06T10:24:04 Z qin 말 (IOI15_horses) C++17
100 / 100
142 ms 71944 KB
#ifdef LOCAL
#else
#include "horses.h"
#endif
#include <bits/stdc++.h>
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double db;
int inf = 2e09; ll infll = 2e18; ll mod = 1e09+7;
vector<ll> X, Y; // UWAGA - GLOBALNIE ZADEKLAROWANE
int base = 1;
struct seg{
		struct Node{
				int opt; ll mul, mulp, muls; bool o, op, os;
				Node() : opt(0), mul(1), mulp(1), muls(1), o(0), op(0), os(0) {}
		};
		vector<Node> t;
		ll mulTmp; bool ovTmp; db proportionTmp;
		void merge(int i){
				t[i].mul = t[i<<1].mul*t[i<<1|1].mul; t[i].o = t[i].mul >= mod ? 1 : (t[i<<1].o|t[i<<1|1].o), t[i].mul %= mod;
				mulTmp = t[i<<1].muls*t[i<<1|1].mulp; ovTmp = mulTmp >= mod ? 1 : (t[i<<1].os|t[i<<1|1].op), mulTmp %= mod;
				if(!Y[t[i<<1|1].opt]) proportionTmp = -1;
				else proportionTmp = db(Y[t[i<<1].opt])/db(Y[t[i<<1|1].opt]);
				if((db(mulTmp) >= proportionTmp || ovTmp) && proportionTmp > 0){ //zwycieża późniejszy
						t[i].opt = t[i<<1|1].opt; 
						t[i].mulp = t[i<<1].mul*t[i<<1|1].mulp, t[i].op = t[i].mulp >= mod ? 1 : (t[i<<1].o|t[i<<1|1].op), t[i].mulp %= mod;
						t[i].muls = t[i<<1|1].muls, t[i].os = t[i<<1|1].os;
				}
				else{ // zwycięża wcześniejszy
						t[i].opt = t[i<<1].opt; 
						t[i].muls = t[i<<1].muls*t[i<<1|1].mul, t[i].os = t[i].muls >= mod ? 1 : (t[i<<1].os|t[i<<1|1].o), t[i].muls %= mod;
						t[i].mulp = t[i<<1].mulp, t[i].op = t[i<<1].op;
				}
		}
		void init(int n){
				while(base < n) base <<= 1;
				t.resize(base<<1);
				X.resize(base+1); Y.resize(base+1);
				//printf("%d\n", base);
				for(int i = 1; i <= n; ++i) t[i+base-1].opt = i, t[i+base-1].mul = X[i], t[i+base-1].mulp = X[i], t[i+base-1].muls = 1; //muls daje na 1, bo miedzy elementami obchodzi mnie tylko przedzial pomiedzy nimi
				for(int i = n+1; i <= base; ++i) X[i] = 1, Y[i] = 0, t[i+base-1].opt = i, t[i+base-1].mul = X[i], t[i+base-1].mulp = X[i], t[i+base-1].muls = 1;
				//exit(0);
				for(int i = base-1; i; --i) merge(i);
				
		}
		void update(int i){
				t[i+base-1].mul = X[i], t[i+base-1].mulp = X[i], t[i+base-1].muls = 1;
				for(i += base-1, i >>= 1; i; i >>= 1) merge(i);
		}
		int query(){ return int(Y[t[1].opt]*t[1].mulp % mod); }
		void print(){
				for(int i = 1; i < base<<1; ++i) printf("%d: %d, %lld %lld %lld\n", i, t[i].opt, t[i].mul, t[i].mulp, t[i].muls);
		}
} seg;
int updateX(int i, int val){ X[i+1] = val; seg.update(i+1); return seg.query(); }
int updateY(int i, int val){ Y[i+1] = val; seg.update(i+1); return seg.query(); }
int init(int n, int x[], int y[]){
		X.resize(n+1), Y.resize(n+1);
		for(int i = 1; i <= n; ++i) X[i] = x[i-1], Y[i] = y[i-1];
		seg.init(n);
		//seg.print();
		return seg.query();
}
#ifdef LOCAL
int main(){
		int T = 1;
		for(++T; --T; ){
				int n = 3, x[3] = {2, 1, 3}, y[3] = {3, 2, 1};
				printf("%d\n", init(n, x, y));
		}
		return 0;
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 58140 KB Output is correct
2 Correct 142 ms 57872 KB Output is correct
3 Correct 107 ms 59416 KB Output is correct
4 Correct 119 ms 64448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 584 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 500 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 46 ms 59172 KB Output is correct
34 Correct 51 ms 61968 KB Output is correct
35 Correct 66 ms 70368 KB Output is correct
36 Correct 65 ms 70924 KB Output is correct
37 Correct 36 ms 61712 KB Output is correct
38 Correct 37 ms 62220 KB Output is correct
39 Correct 31 ms 61636 KB Output is correct
40 Correct 51 ms 64584 KB Output is correct
41 Correct 33 ms 62220 KB Output is correct
42 Correct 32 ms 61824 KB Output is correct
43 Correct 46 ms 65812 KB Output is correct
44 Correct 46 ms 64484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 560 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 71 ms 59520 KB Output is correct
34 Correct 138 ms 71228 KB Output is correct
35 Correct 113 ms 61712 KB Output is correct
36 Correct 119 ms 66708 KB Output is correct
37 Correct 47 ms 63756 KB Output is correct
38 Correct 47 ms 62224 KB Output is correct
39 Correct 66 ms 70512 KB Output is correct
40 Correct 68 ms 71112 KB Output is correct
41 Correct 36 ms 61636 KB Output is correct
42 Correct 38 ms 60940 KB Output is correct
43 Correct 32 ms 60768 KB Output is correct
44 Correct 51 ms 66716 KB Output is correct
45 Correct 32 ms 61208 KB Output is correct
46 Correct 32 ms 61708 KB Output is correct
47 Correct 49 ms 65780 KB Output is correct
48 Correct 50 ms 64504 KB Output is correct
49 Correct 114 ms 63248 KB Output is correct
50 Correct 115 ms 62096 KB Output is correct
51 Correct 122 ms 71944 KB Output is correct
52 Correct 107 ms 69900 KB Output is correct
53 Correct 104 ms 61640 KB Output is correct
54 Correct 85 ms 63532 KB Output is correct
55 Correct 65 ms 61976 KB Output is correct
56 Correct 93 ms 66576 KB Output is correct
57 Correct 64 ms 60172 KB Output is correct
58 Correct 68 ms 62148 KB Output is correct
59 Correct 48 ms 65660 KB Output is correct