# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
99641 | 2019-03-06T02:31:11 Z | Retro3014 | 말 (IOI15_horses) | C++17 | 1018 ms | 61864 KB |
#include "horses.h" #include <bits/stdc++.h> typedef long long ll; const ll DIV = 1000000007; using namespace std; vector<int> x, y; struct SEG{ int l, r; ll data; }; vector<SEG> seg1, seg2; void inits1(int idx, int s, int e){ seg1.push_back({-1, -1, 1}); if(s==e){ seg1[idx].data = x[s]%DIV; return; } seg1[idx].l = seg1.size(); inits1(seg1[idx].l, s, (s+e)/2); seg1[idx].r = seg1.size(); inits1(seg1[idx].r, (s+e)/2+1, e); seg1[idx].data = (seg1[seg1[idx].l].data * seg1[seg1[idx].r].data)%DIV; } void inits2(int idx, int s, int e){ seg2.push_back({-1, -1, 0}); if(s==e){ seg2[idx].data = y[s]; return; } seg2[idx].l = seg2.size(); inits2(seg2[idx].l, s, (s+e)/2); seg2[idx].r = seg2.size(); inits2(seg2[idx].r, (s+e)/2+1, e); seg2[idx].data = max(seg2[seg2[idx].l].data, seg2[seg2[idx].r].data); } ll calc1(int idx, int s, int e, int x, int y){ if(idx==-1) return 1; if(x<=s && e<=y) return seg1[idx].data; if(x>e || s>y) return 1; return (calc1(seg1[idx].l, s, (s+e)/2, x, y) * calc1(seg1[idx].r, (s+e)/2+1, e, x, y))%DIV; } ll calc2(int idx, int s, int e, int x, int y){ if(idx==-1) return 0; if(x<=s && e<=y) return seg2[idx].data; if(x>e || s>y) return 0; return max(calc2(seg2[idx].l, s, (s+e)/2, x, y), calc2(seg2[idx].r, (s+e)/2+1, e, x, y)); } void update1(int idx, int s, int e, int x, int y){ if(idx==-1) return; if(s==e) { seg1[idx].data = y%DIV; return; } if(x<=(s+e)/2){ update1(seg1[idx].l, s, (s+e)/2, x, y); }else{ update1(seg1[idx].r, (s+e)/2+1, e, x, y); } seg1[idx].data = (seg1[seg1[idx].l].data * seg1[seg1[idx].r].data)%DIV; return; } void update2(int idx, int s, int e, int x, int y){ if(idx==-1) return; if(s==e){ seg2[idx].data = y; return; } if(x<=(s+e)/2){ update2(seg2[idx].l, s, (s+e)/2, x, y); }else{ update2(seg2[idx].r, (s+e)/2+1, e, x, y); } seg2[idx].data = max(seg2[seg2[idx].l].data, seg2[seg2[idx].r].data); return; } priority_queue<int> pq; vector<int> t; int calc_ans(){ ll m = 1; ll ans = 0; t.push_back(x.size()); while(!pq.empty()){ int k = pq.top(); pq.pop(); if(x[k]==1) continue; t.push_back(k); m *= x[k]; //cout<<k<<' '; if(m>1000000000LL) break; } if(m<=1000000000LL) t.push_back(0); //cout<<endl; m = 1; ll nowy, prvy; int idx = t.size()-1; prvy = calc2(0, 0, x.size()-1, t[idx], t[idx-1]-1); for(int i=t.size()-2; i>=1; i--){ m*=x[t[i]]; nowy = calc2(0, 0, x.size()-1, t[i], t[i-1]-1); //cout<<idx<<' '<<prvy<<' '<<m<<' '<<nowy<<' '<<i<<endl; if(m*nowy>prvy){ idx = i; prvy = nowy; m = 1; } } //cout<<t[idx]<<endl; ans = (calc1(0, 0, x.size()-1, 0, t[idx]) * prvy)%DIV; while(t.size()>1){ pq.push(t.back()); t.pop_back(); }t.pop_back(); return ans; } int init(int N, int X[], int Y[]){ for(int i=0; i<N; i++){ x.push_back(X[i]); y.push_back(Y[i]); if(X[i]!=1){ pq.push(i); } } inits1(0, 0, N-1); inits2(0, 0, N-1); return calc_ans(); } int updateX(int pos, int val){ if(x[pos]==1 && val!=1){ pq.push(pos); } x[pos] = val; update1(0, 0, x.size()-1, pos, val); return calc_ans(); } int updateY(int pos, int val){ y[pos] = val; update2(0, 0, x.size()-1, pos, val); return calc_ans(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 3 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 4 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 3 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 3 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 3 ms | 384 KB | Output is correct |
16 | Correct | 3 ms | 384 KB | Output is correct |
17 | Correct | 2 ms | 384 KB | Output is correct |
18 | Correct | 3 ms | 256 KB | Output is correct |
19 | Correct | 2 ms | 256 KB | Output is correct |
20 | Correct | 3 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 3 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 3 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 256 KB | Output is correct |
16 | Correct | 3 ms | 256 KB | Output is correct |
17 | Correct | 3 ms | 384 KB | Output is correct |
18 | Correct | 4 ms | 384 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 256 KB | Output is correct |
21 | Correct | 2 ms | 256 KB | Output is correct |
22 | Correct | 2 ms | 384 KB | Output is correct |
23 | Correct | 4 ms | 384 KB | Output is correct |
24 | Correct | 3 ms | 384 KB | Output is correct |
25 | Correct | 4 ms | 384 KB | Output is correct |
26 | Correct | 3 ms | 640 KB | Output is correct |
27 | Correct | 6 ms | 384 KB | Output is correct |
28 | Correct | 4 ms | 384 KB | Output is correct |
29 | Correct | 3 ms | 384 KB | Output is correct |
30 | Correct | 3 ms | 384 KB | Output is correct |
31 | Correct | 5 ms | 512 KB | Output is correct |
32 | Correct | 6 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 935 ms | 50344 KB | Output is correct |
2 | Correct | 309 ms | 50468 KB | Output is correct |
3 | Correct | 385 ms | 50492 KB | Output is correct |
4 | Correct | 415 ms | 50468 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 23 ms | 512 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 392 KB | Output is correct |
6 | Correct | 3 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 3 ms | 512 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 256 KB | Output is correct |
16 | Correct | 3 ms | 384 KB | Output is correct |
17 | Correct | 2 ms | 256 KB | Output is correct |
18 | Correct | 2 ms | 256 KB | Output is correct |
19 | Correct | 2 ms | 256 KB | Output is correct |
20 | Correct | 2 ms | 256 KB | Output is correct |
21 | Correct | 2 ms | 256 KB | Output is correct |
22 | Correct | 2 ms | 256 KB | Output is correct |
23 | Correct | 3 ms | 512 KB | Output is correct |
24 | Correct | 3 ms | 384 KB | Output is correct |
25 | Correct | 4 ms | 640 KB | Output is correct |
26 | Correct | 3 ms | 512 KB | Output is correct |
27 | Correct | 6 ms | 640 KB | Output is correct |
28 | Correct | 5 ms | 384 KB | Output is correct |
29 | Correct | 4 ms | 384 KB | Output is correct |
30 | Correct | 4 ms | 512 KB | Output is correct |
31 | Correct | 6 ms | 384 KB | Output is correct |
32 | Correct | 6 ms | 512 KB | Output is correct |
33 | Correct | 128 ms | 52396 KB | Output is correct |
34 | Correct | 145 ms | 52428 KB | Output is correct |
35 | Correct | 192 ms | 61320 KB | Output is correct |
36 | Correct | 160 ms | 61140 KB | Output is correct |
37 | Correct | 241 ms | 50592 KB | Output is correct |
38 | Correct | 138 ms | 59980 KB | Output is correct |
39 | Correct | 102 ms | 50488 KB | Output is correct |
40 | Correct | 144 ms | 56232 KB | Output is correct |
41 | Correct | 140 ms | 50488 KB | Output is correct |
42 | Correct | 172 ms | 50468 KB | Output is correct |
43 | Correct | 128 ms | 56836 KB | Output is correct |
44 | Correct | 134 ms | 56744 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 3 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 256 KB | Output is correct |
16 | Correct | 2 ms | 384 KB | Output is correct |
17 | Correct | 2 ms | 256 KB | Output is correct |
18 | Correct | 2 ms | 256 KB | Output is correct |
19 | Correct | 2 ms | 256 KB | Output is correct |
20 | Correct | 2 ms | 256 KB | Output is correct |
21 | Correct | 2 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 256 KB | Output is correct |
23 | Correct | 3 ms | 384 KB | Output is correct |
24 | Correct | 3 ms | 512 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 3 ms | 512 KB | Output is correct |
27 | Correct | 8 ms | 384 KB | Output is correct |
28 | Correct | 6 ms | 384 KB | Output is correct |
29 | Correct | 3 ms | 384 KB | Output is correct |
30 | Correct | 4 ms | 384 KB | Output is correct |
31 | Correct | 5 ms | 384 KB | Output is correct |
32 | Correct | 5 ms | 384 KB | Output is correct |
33 | Correct | 915 ms | 52648 KB | Output is correct |
34 | Correct | 296 ms | 61388 KB | Output is correct |
35 | Correct | 370 ms | 52648 KB | Output is correct |
36 | Correct | 430 ms | 56456 KB | Output is correct |
37 | Correct | 131 ms | 52320 KB | Output is correct |
38 | Correct | 113 ms | 52408 KB | Output is correct |
39 | Correct | 170 ms | 61220 KB | Output is correct |
40 | Correct | 145 ms | 61184 KB | Output is correct |
41 | Correct | 224 ms | 50504 KB | Output is correct |
42 | Correct | 139 ms | 59972 KB | Output is correct |
43 | Correct | 97 ms | 50448 KB | Output is correct |
44 | Correct | 123 ms | 56348 KB | Output is correct |
45 | Correct | 145 ms | 50480 KB | Output is correct |
46 | Correct | 160 ms | 50572 KB | Output is correct |
47 | Correct | 126 ms | 56740 KB | Output is correct |
48 | Correct | 127 ms | 56752 KB | Output is correct |
49 | Correct | 331 ms | 52588 KB | Output is correct |
50 | Correct | 282 ms | 52536 KB | Output is correct |
51 | Correct | 365 ms | 61352 KB | Output is correct |
52 | Correct | 226 ms | 61348 KB | Output is correct |
53 | Correct | 1018 ms | 50620 KB | Output is correct |
54 | Correct | 410 ms | 61864 KB | Output is correct |
55 | Correct | 268 ms | 50616 KB | Output is correct |
56 | Correct | 272 ms | 56436 KB | Output is correct |
57 | Correct | 645 ms | 50776 KB | Output is correct |
58 | Correct | 809 ms | 50616 KB | Output is correct |
59 | Correct | 134 ms | 56744 KB | Output is correct |