# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
649936 | 2022-10-11T15:53:15 Z | PoonYaPat | Horses (IOI15_horses) | C++14 | 867 ms | 50148 KB |
#include "horses.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; int n; const ll mod=1e9+7; pll ms[1<<21]; //-1,mod ll x[500001],y[500001]; void build_ms(int l, int r, int idx) { if (l>r) return; if (l==r) ms[idx]={x[l],x[l]}; else { int mid=(l+r)/2; build_ms(l,mid,2*idx); build_ms(mid+1,r,2*idx+1); if (ms[2*idx].first==-1 || ms[2*idx+1].first==-1) ms[idx].first=-1; else { if (ms[2*idx].first*ms[2*idx+1].first>1e9) ms[idx].first=-1; else ms[idx].first=ms[2*idx].first*ms[2*idx+1].first; } ms[idx].second=(ms[2*idx].second*ms[2*idx+1].second)%mod; } } void update_ms(int l, int r, int idx, int k, ll val) { if (l>k || k>r) return; if (l==r) ms[idx]={val,val}; else { int mid=(l+r)/2; update_ms(l,mid,2*idx,k,val); update_ms(mid+1,r,2*idx+1,k,val); if (ms[2*idx].first==-1 || ms[2*idx+1].first==-1) ms[idx].first=-1; else { if (ms[2*idx].first*ms[2*idx+1].first>1e9) ms[idx].first=-1; else ms[idx].first=ms[2*idx].first*ms[2*idx+1].first; } ms[idx].second=(ms[2*idx].second*ms[2*idx+1].second)%mod; } } ll query_ms(int l, int r, int idx, int x, int y) { if (l>y || r<x) return 1; if (x<=l && r<=y) return ms[idx].first; int mid=(l+r)/2; ll ml=query_ms(l,mid,2*idx,x,y), mr=query_ms(mid+1,r,2*idx+1,x,y); if (ml==-1 || mr==-1) return -1; else { if (ml*mr>1e9) return -1; else return ml*mr; } } ll query_ms2(int l, int r, int idx, int x, int y) { if (l>y || r<x) return 1; if (x<=l && r<=y) return ms[idx].second; int mid=(l+r)/2; return (query_ms2(l,mid,2*idx,x,y)*query_ms2(mid+1,r,2*idx+1,x,y))%mod; } ll h; int check(int a, int b) { //whether who is bigger between s[a] and a[b] h=query_ms(0,n-1,1,a+1,b); if (h==-1) return b; if (y[a]>y[b]*h) return a; else return b; } ll s[1<<21]; void update(int l, int r, int idx) { if (l>r) return; if (l==r) s[idx]=l; else { int mid=(l+r)/2; update(l,mid,2*idx); update(mid+1,r,2*idx+1); s[idx]=check(s[2*idx],s[2*idx+1]); } } void update2(int l, int r, int idx, int x, int y) { if (l>y || r<x) return; if (x<=l && r<=y) return; else { int mid=(l+r)/2; update2(l,mid,2*idx,x,y); update2(mid+1,r,2*idx+1,x,y); s[idx]=check(s[2*idx],s[2*idx+1]); } } void update3(int l, int r, int idx, int x) { if (l>x || x>r) return; if (l==r) return; else { int mid=(l+r)/2; update3(l,mid,2*idx,x); update3(mid+1,r,2*idx+1,x); s[idx]=check(s[2*idx],s[2*idx+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]; build_ms(0,n-1,1); update(0,n-1,1); return (query_ms2(0,n-1,1,0,s[1])*y[s[1]])%mod; } int updateX(int pos, int val) { x[pos]=val; update_ms(0,n-1,1,pos,val); update2(0,n-1,1,pos,n-1); return (query_ms2(0,n-1,1,0,s[1])*y[s[1]])%mod; } int updateY(int pos, int val) { y[pos]=val; update3(0,n-1,1,pos); return (query_ms2(0,n-1,1,0,s[1])*y[s[1]])%mod; }
Compilation message
# | Verdict | Execution time | Memory | 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 | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 340 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 | 340 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 | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 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 | 340 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 | 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 | 0 ms | 340 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 | 1 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 3 ms | 320 KB | Output is correct |
24 | Correct | 2 ms | 340 KB | Output is correct |
25 | Correct | 2 ms | 340 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 2 ms | 340 KB | Output is correct |
28 | Correct | 2 ms | 340 KB | Output is correct |
29 | Correct | 1 ms | 312 KB | Output is correct |
30 | Correct | 2 ms | 340 KB | Output is correct |
31 | Correct | 2 ms | 340 KB | Output is correct |
32 | Correct | 2 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 490 ms | 37648 KB | Output is correct |
2 | Correct | 458 ms | 40980 KB | Output is correct |
3 | Correct | 587 ms | 41548 KB | Output is correct |
4 | Correct | 537 ms | 41968 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 1 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 | 0 ms | 340 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 340 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 | 340 KB | Output is correct |
17 | Correct | 0 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 | 1 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 2 ms | 340 KB | Output is correct |
24 | Correct | 3 ms | 324 KB | Output is correct |
25 | Correct | 3 ms | 340 KB | Output is correct |
26 | Correct | 2 ms | 340 KB | Output is correct |
27 | Correct | 2 ms | 340 KB | Output is correct |
28 | Correct | 2 ms | 324 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 2 ms | 340 KB | Output is correct |
31 | Correct | 2 ms | 340 KB | Output is correct |
32 | Correct | 2 ms | 328 KB | Output is correct |
33 | Correct | 227 ms | 40696 KB | Output is correct |
34 | Correct | 215 ms | 40748 KB | Output is correct |
35 | Correct | 202 ms | 47620 KB | Output is correct |
36 | Correct | 176 ms | 47468 KB | Output is correct |
37 | Correct | 180 ms | 38832 KB | Output is correct |
38 | Correct | 171 ms | 39764 KB | Output is correct |
39 | Correct | 166 ms | 38776 KB | Output is correct |
40 | Correct | 159 ms | 42848 KB | Output is correct |
41 | Correct | 169 ms | 38884 KB | Output is correct |
42 | Correct | 164 ms | 38808 KB | Output is correct |
43 | Correct | 155 ms | 42976 KB | Output is correct |
44 | Correct | 141 ms | 43032 KB | Output is correct |
# | Verdict | Execution time | Memory | 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 | 0 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 | 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 | 1 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 | 1 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 | 1 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 | 1 ms | 212 KB | Output is correct |
23 | Correct | 3 ms | 340 KB | Output is correct |
24 | Correct | 3 ms | 340 KB | Output is correct |
25 | Correct | 2 ms | 340 KB | Output is correct |
26 | Correct | 2 ms | 340 KB | Output is correct |
27 | Correct | 2 ms | 340 KB | Output is correct |
28 | Correct | 3 ms | 320 KB | Output is correct |
29 | Correct | 2 ms | 340 KB | Output is correct |
30 | Correct | 2 ms | 340 KB | Output is correct |
31 | Correct | 2 ms | 340 KB | Output is correct |
32 | Correct | 2 ms | 340 KB | Output is correct |
33 | Correct | 489 ms | 41428 KB | Output is correct |
34 | Correct | 456 ms | 50148 KB | Output is correct |
35 | Correct | 605 ms | 41380 KB | Output is correct |
36 | Correct | 554 ms | 45280 KB | Output is correct |
37 | Correct | 244 ms | 40800 KB | Output is correct |
38 | Correct | 228 ms | 40596 KB | Output is correct |
39 | Correct | 197 ms | 47524 KB | Output is correct |
40 | Correct | 187 ms | 47648 KB | Output is correct |
41 | Correct | 203 ms | 38796 KB | Output is correct |
42 | Correct | 168 ms | 39708 KB | Output is correct |
43 | Correct | 152 ms | 38720 KB | Output is correct |
44 | Correct | 161 ms | 42632 KB | Output is correct |
45 | Correct | 170 ms | 38732 KB | Output is correct |
46 | Correct | 161 ms | 38812 KB | Output is correct |
47 | Correct | 144 ms | 43008 KB | Output is correct |
48 | Correct | 160 ms | 43100 KB | Output is correct |
49 | Correct | 867 ms | 42672 KB | Output is correct |
50 | Correct | 811 ms | 42812 KB | Output is correct |
51 | Correct | 531 ms | 49420 KB | Output is correct |
52 | Correct | 355 ms | 48956 KB | Output is correct |
53 | Correct | 651 ms | 41036 KB | Output is correct |
54 | Correct | 487 ms | 41712 KB | Output is correct |
55 | Correct | 349 ms | 39724 KB | Output is correct |
56 | Correct | 355 ms | 44528 KB | Output is correct |
57 | Correct | 567 ms | 40504 KB | Output is correct |
58 | Correct | 502 ms | 40860 KB | Output is correct |
59 | Correct | 140 ms | 42948 KB | Output is correct |