# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
790970 | 2023-07-23T10:10:24 Z | Khizri | Horses (IOI15_horses) | C++17 | 965 ms | 52884 KB |
#include "horses.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second #define INF 1e18 #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define pii pair<int,int> #define pll pair<ll,ll> #define OK cout<<"Ok"<<endl; #define MOD (ll)(1e9+7) const int mxn=5e5+5; ll n,idx[mxn],arr[mxn],tree2[mxn*4]; ll tree[4*mxn]; set<int>st; void build(int node,int l,int r){ if(l==r){ tree[node]=idx[l]; return; } int m=(l+r)/2; build(2*node,l,m); build(2*node+1,m+1,r); tree[node]=(tree[2*node]*tree[2*node+1])%MOD; } void build2(int node,int l,int r){ if(l==r){ tree2[node]=arr[l]; return; } int m=(l+r)/2; build2(2*node,l,m); build2(2*node+1,m+1,r); tree2[node]=max(tree2[2*node],tree2[2*node+1]); } void update(int node,int l,int r,int pos,int val){ if(l>pos||r<pos) return; if(l==r){ tree[node]=val; return; } int m=(l+r)/2; update(2*node,l,m,pos,val); update(2*node+1,m+1,r,pos,val); tree[node]=(tree[2*node]*tree[2*node+1])%MOD; } void update2(int node,int l,int r,int pos,int val){ if(l>pos||r<pos) return; if(l==r){ tree2[node]=val; return; } int m=(l+r)/2; update2(2*node,l,m,pos,val); update2(2*node+1,m+1,r,pos,val); tree2[node]=max(tree2[2*node],tree2[2*node+1]); } ll query(int node,int l,int r,int ql,int qr){ if(l>qr||r<ql) return 1; if(ql<=l&&r<=qr) return tree[node]; int m=(l+r)/2; return (query(2*node,l,m,ql,qr)*query(2*node+1,m+1,r,ql,qr))%MOD; } int query2(int node,int l,int r,int ql,int qr){ if(l>qr||r<ql) return 0; if(ql<=l&&r<=qr) return tree2[node]; int m=(l+r)/2; return max(query2(2*node,l,m,ql,qr),query2(2*node+1,m+1,r,ql,qr)); } int init(int N, int X[], int Y[]) { n=N; for(int i=0;i<n;i++){ arr[i+1]=Y[i]; idx[i+1]=X[i]; if(idx[i+1]>1){ st.insert(i+1); } } build(1,1,n); build2(1,1,n); int k=min(32,(int)st.size()); auto it=st.end(); if(st.size()){ it=--st.end(); } ll res=query2(1,1,n,1,n); while(k--){ int x=*it; ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n)); res=max(res,ans); if(k>0) it--; } return res%MOD; } int updateX(int pos, int val) { pos++; if(idx[pos]>1){ st.erase(pos); } idx[pos]=val; if(idx[pos]>1){ st.insert(pos); } update(1,1,n,pos,val); int k=min(33,(int)st.size()); auto it=--st.end(); int res=query2(1,1,n,1,n); while(k--){ int x=*it; ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n))%MOD; res=max(res,(int)ans); it--; } return res; } int updateY(int pos, int val) { pos++; arr[pos]=val; update2(1,1,n,pos,val); int k=min(33,(int)st.size()); auto it=--st.end(); int res=query2(1,1,n,1,n); while(k--){ int x=*it; ll ans=(query(1,1,n,1,x)*query2(1,1,n,x,n))%MOD; res=max(res,(int)ans); it--; } return res; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 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 | 1 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 | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 308 KB | Output is correct |
13 | Correct | 1 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 | 1 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 308 KB | Output is correct |
20 | Correct | 0 ms | 212 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 | 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 | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 340 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 | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 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 | 340 KB | Output is correct |
21 | Incorrect | 0 ms | 212 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 965 ms | 52884 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 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 | 304 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 308 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 308 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 | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 308 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 | 340 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Incorrect | 1 ms | 284 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 224 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 | 244 KB | Output is correct |
6 | Correct | 1 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 | 1 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 | 1 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 | 0 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 312 KB | Output is correct |
20 | Correct | 1 ms | 308 KB | Output is correct |
21 | Incorrect | 0 ms | 212 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |