# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
624593 | 2022-08-08T14:07:57 Z | NicolaAbusaad2014 | 말 (IOI15_horses) | C++14 | 436 ms | 97296 KB |
#include "horses.h" #include <bits/stdc++.h> using namespace std; #define REP(i,l,r) for(long long i=(l);i<(r);i++) #define PER(i,l,r) for(long long i=(r)-1;i>=(l);i--) const long long mod=1e9+7; long long p(long long x){while(x&(x-1)){x=x&(x-1);}return x;} long long squared(long long x){return (x*x)%mod;} long long power(long long x,long long p){if(p==0){return 1;}if(p%2==1){return (power(x,p-1)*x)%mod;}return squared(power(x,p/2));} long long inv(long long x){return power(x,mod-2);} struct segment_tree { struct node { long double value; long pos,left,right; }; node dum; vector<node>tree; vector<long double>upd; node operation(node x,node z) { node ret; if(x.value>=z.value){ ret.value=x.value; ret.pos=x.pos; } else{ ret.value=z.value; ret.pos=z.pos; } ret.left=min(x.left,z.left); ret.right=max(x.right,z.right); return ret; } void push(long node) { tree[node].value+=upd[node]; if(node<tree.size()){ upd[node*2]+=upd[node]; upd[(node*2)+1]+=upd[node]; } upd[node]=0; } void build(vector<long double>v) { tree.clear(); upd.clear(); int x=((v.size())*2)-1; while(x&(x-1)){ x=x&(x-1); } tree.resize(x*2); upd.resize(x*2); dum.value=-1e9; dum.left=-1e9; dum.right=1e9; for(long i=0;i<v.size();i++){ tree[i+x].value=v[i]; tree[i+x].pos=i; tree[i+x].left=i; tree[i+x].right=i; } for(long i=v.size();i<x;i++){ tree[i+x].value=-1e9; tree[i+x].pos=i; tree[i+x].left=i; tree[i+x].right=i; } for(long i=x-1;i>0;i--){ tree[i]=operation(tree[i*2],tree[(i*2)+1]); } } node get(int l,int r,int node=1) { push(node); if(tree[node].left>r||tree[node].right<l){ return dum; } if(tree[node].left>=l&&tree[node].right<=r){ return tree[node]; } return operation(get(l,r,node*2),get(l,r,(node*2)+1)); } void update(int l,int r,long double z,int node=1) { push(node); if(tree[node].left>r||tree[node].right<l){ return; } if(tree[node].left>=l&&tree[node].right<=r){ upd[node]+=z; push(node); return; } update(l,r,z,node*2); update(l,r,z,(node*2)+1); tree[node]=operation(tree[node*2],tree[(node*2)+1]); } }; segment_tree st; long n; vector<long long>x,y,tot; vector<long double>v; int init(int N, int X[], int Y[]) { n=N; x.resize(n); y.resize(n); tot.resize(n); v.resize(n); REP(i,0,n){ x[i]=X[i]; y[i]=Y[i]; } v[0]=log(x[0])+log(y[0]); tot[0]=(x[0]*y[0])%mod; REP(i,1,n){ v[i]=v[i-1]+log(x[i])+log(y[i])-log(y[i-1]); tot[i]=(((tot[i-1]*x[i])%mod)*((y[i]*inv(y[i-1]))%mod))%mod; } st.build(v); N=st.get(0,n-1).pos; return tot[N]; } int updateX(int pos, int val) { st.update(pos,n-1,log(val)-log(x[pos])); tot[pos]*=val; tot[pos]%=mod; tot[pos]*=inv(x[pos]); tot[pos]%=mod; x[pos]=val; pos=st.get(0,n-1).pos; return tot[pos]; } int updateY(int pos, int val) { st.update(pos,pos,log(val)-log(y[pos])); tot[pos]*=val; tot[pos]%=mod; tot[pos]*=inv(y[pos]); tot[pos]%=mod; y[pos]=val; pos=st.get(0,n-1).pos; return tot[pos]; }
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 | 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 | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 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 | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 1 ms | 256 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 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 | 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 | 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 | 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 | Incorrect | 0 ms | 212 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 384 ms | 97296 KB | Output is correct |
2 | Incorrect | 436 ms | 97264 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | 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 | 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 | 1 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 | Incorrect | 0 ms | 212 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | 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 | 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 | 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 | 0 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 | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Incorrect | 0 ms | 212 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |