# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
802297 | 2023-08-02T11:29:11 Z | jlallas384 | 말 (IOI15_horses) | C++17 | 785 ms | 84252 KB |
#include "horses.h" #include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1e9 + 7; vector<int> x, y; int n; struct tree{ tree *lc, *rc; int mx, l, r; tree(){} tree(int i, int j){ l = i, r = j; if(l != r){ int m = (l + r) / 2; lc = new tree(l, m); rc = new tree(m + 1, r); } } void upd(int i, int x){ if(l == r) mx = x; else{ if(i <= lc->r) lc->upd(i, x); else rc->upd(i, x); mx = max(lc->mx, rc->mx); } }; int qry(int i, int j){ if(r < i || j < l) return 0; if(i <= l && r <= j) return mx; return max(lc->qry(i, j), rc->qry(i, j)); }; }; struct FT{ vector<ll> ft; int n; FT(){} FT(int n): n(n), ft(n + 1, 1){} void upd(int i, ll x){ for(; i <= n; i += i & -i){ ft[i] = ft[i] * x % mod; } } ll qry(int i){ ll res = 1; for(; i > 0; i -= i & -i){ res = res * ft[i] % mod; } return res; } }; ll pwr(ll x, ll y){ ll res = 1; while(y){ if(y % 2){ res = res * x % mod; } x = x * x % mod; y /= 2; } return res; } tree *st; FT ft; set<int> big; int solve(){ auto it = big.begin(); vector<int> hv; while(it != big.end() && hv.size() < 30){ hv.push_back(-(*it)); it = next(it); } hv.push_back(-1); reverse(hv.begin(), hv.end()); ll cur = 1; if(hv.size() != 1) cur = ft.qry(hv[1]); hv.push_back(n); vector<pair<int,int>> a; for(int i = 0; i < (int) hv.size() - 1; i++){ if(hv[i] != -1) a.emplace_back(x[hv[i]], y[hv[i]]); if(hv[i] + 1 != hv[i + 1]){ a.emplace_back(1, st->qry(hv[i] + 1, hv[i + 1] - 1)); } } for(int i = 0; i < a.size(); i++){ ll pre = 1; ll bst = 0; cur = cur * a[i].first % mod; for(int j = i + 1; j < a.size(); j++){ pre *= a[j].first; if(pre > 1e9){ bst = -1; break; } bst = max(bst, pre * a[j].second); } if(bst != -1 && bst < a[i].second){ return cur * a[i].second % mod; } } return -1; } int init(int N, int X[], int Y[]) { n = N; x.resize(n), y.resize(n); st = new tree(0, n - 1); ft = FT(n); for(int i = 0; i < n; i++){ x[i] = X[i]; y[i] = Y[i]; st->upd(i, y[i]); ft.upd(i + 1, x[i]); if(x[i] > 1) big.insert(-i); } return solve(); } int updateX(int pos, int val) { if(x[pos] > 1 && val == 1){ big.erase(-pos); }else if(x[pos] == 1 && val > 1){ big.insert(-pos); } ft.upd(pos + 1, pwr(x[pos], mod - 2) * val % mod); x[pos] = val; return solve(); } int updateY(int pos, int val) { st->upd(pos, val); y[pos] = val; return solve(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 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 | 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 | 0 ms | 212 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 | 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 | 1 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 | 1 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 | 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 | 0 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 264 KB | Output is correct |
23 | Correct | 3 ms | 340 KB | Output is correct |
24 | Correct | 2 ms | 340 KB | Output is correct |
25 | Correct | 2 ms | 468 KB | Output is correct |
26 | Correct | 2 ms | 488 KB | Output is correct |
27 | Correct | 4 ms | 440 KB | Output is correct |
28 | Correct | 3 ms | 456 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 2 ms | 468 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 3 ms | 444 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 316 ms | 83468 KB | Output is correct |
2 | Correct | 387 ms | 83864 KB | Output is correct |
3 | Correct | 435 ms | 83944 KB | Output is correct |
4 | Correct | 387 ms | 84000 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 | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 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 | 1 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 | 1 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 1 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 | 4 ms | 340 KB | Output is correct |
24 | Correct | 2 ms | 340 KB | Output is correct |
25 | Correct | 2 ms | 468 KB | Output is correct |
26 | Correct | 2 ms | 468 KB | Output is correct |
27 | Correct | 6 ms | 340 KB | Output is correct |
28 | Correct | 3 ms | 468 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 3 ms | 512 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 4 ms | 340 KB | Output is correct |
33 | Correct | 175 ms | 59740 KB | Output is correct |
34 | Correct | 153 ms | 59636 KB | Output is correct |
35 | Correct | 262 ms | 82984 KB | Output is correct |
36 | Correct | 254 ms | 83008 KB | Output is correct |
37 | Correct | 221 ms | 59652 KB | Output is correct |
38 | Correct | 198 ms | 71584 KB | Output is correct |
39 | Correct | 126 ms | 59472 KB | Output is correct |
40 | Correct | 240 ms | 83068 KB | Output is correct |
41 | Correct | 129 ms | 59532 KB | Output is correct |
42 | Correct | 152 ms | 59620 KB | Output is correct |
43 | Correct | 230 ms | 83052 KB | Output is correct |
44 | Correct | 231 ms | 82960 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 | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 256 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 | 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 | 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 | 3 ms | 432 KB | Output is correct |
24 | Correct | 2 ms | 340 KB | Output is correct |
25 | Correct | 2 ms | 468 KB | Output is correct |
26 | Correct | 2 ms | 468 KB | Output is correct |
27 | Correct | 5 ms | 444 KB | Output is correct |
28 | Correct | 3 ms | 468 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 2 ms | 468 KB | Output is correct |
31 | Correct | 2 ms | 340 KB | Output is correct |
32 | Correct | 3 ms | 340 KB | Output is correct |
33 | Correct | 336 ms | 83960 KB | Output is correct |
34 | Correct | 411 ms | 83968 KB | Output is correct |
35 | Correct | 371 ms | 83984 KB | Output is correct |
36 | Correct | 400 ms | 83976 KB | Output is correct |
37 | Correct | 185 ms | 59632 KB | Output is correct |
38 | Correct | 142 ms | 59728 KB | Output is correct |
39 | Correct | 256 ms | 82936 KB | Output is correct |
40 | Correct | 252 ms | 82876 KB | Output is correct |
41 | Correct | 194 ms | 59700 KB | Output is correct |
42 | Correct | 202 ms | 71564 KB | Output is correct |
43 | Correct | 124 ms | 59508 KB | Output is correct |
44 | Correct | 254 ms | 83104 KB | Output is correct |
45 | Correct | 120 ms | 59504 KB | Output is correct |
46 | Correct | 154 ms | 59544 KB | Output is correct |
47 | Correct | 237 ms | 83008 KB | Output is correct |
48 | Correct | 233 ms | 82936 KB | Output is correct |
49 | Correct | 583 ms | 61632 KB | Output is correct |
50 | Correct | 311 ms | 61612 KB | Output is correct |
51 | Correct | 392 ms | 84252 KB | Output is correct |
52 | Correct | 342 ms | 83880 KB | Output is correct |
53 | Correct | 785 ms | 61540 KB | Output is correct |
54 | Correct | 469 ms | 74488 KB | Output is correct |
55 | Correct | 205 ms | 59732 KB | Output is correct |
56 | Correct | 403 ms | 83884 KB | Output is correct |
57 | Correct | 200 ms | 60464 KB | Output is correct |
58 | Correct | 473 ms | 60484 KB | Output is correct |
59 | Correct | 241 ms | 82972 KB | Output is correct |