Submission #1312850

#TimeUsernameProblemLanguageResultExecution timeMemory
1312850nikaa123Horses (IOI15_horses)C++20
17 / 100
152 ms26612 KiB
#include <bits/stdc++.h> #include "horses.h" using namespace std; const int inf = INT_MAX; const int mod = 1000000007; const int S = 5e5+5; int n; int x[S],y[S]; int pref[S]; int t[4*S]; int lazy[4*S]; void applay(int x, int val) { t[x] = (t[x] * val) % mod; lazy[x] = (lazy[x] * val) % mod; } void push(int x) { if (lazy[x] != 1) { applay(x*2,lazy[x]); applay(x*2+1,lazy[x]); lazy[x] = 1; } } void update(int node, int l, int r, int L, int R, int val) { if (r < L || l > R) return; if (l >= L && r <= R) { applay(node,val); return; } push(node); int mid = (l+r)/2; update(node*2,l,mid,L,R,val); update(node*2+1,mid+1,r,L,R,val); t[node] = max(t[node*2],t[node*2+1]); } int getans(int node, int l, int r, int L, int R) { if (r < L || l > R) return -inf; if (l >= L && r <= R) return t[node]; push(node); int mid = (l+r)/2; return max(getans(node*2,l,mid,L,R),getans(node*2+1,mid+1,r,L,R)); } int inv(int x, int k = mod - 2) { int res = 1; while (k) { if (k&1) { res = (res * x) % mod; } x = (x * x) % mod; k >>= 1; } return res; } 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]; } pref[0] = X[0]; for (int i = 1; i < n; i++) { pref[i] = (pref[i-1] * x[i]) % mod; } for (int i = 0; i < n; i++) { pref[i] = (pref[i] * y[i]) % mod; } for (int i = 1; i <= 4*n; i++) { lazy[i] = 1; t[i] = 1; } for (int i = 1; i <= n; i++) { update(1,1,n,i,i,pref[i-1]); } return getans(1,1,n,1,n); } int updateX(int pos, int val) { update(1,1,n,pos+1,n,inv(x[pos])); x[pos] = val; update(1,1,n,pos+1,n,x[pos]); return getans(1,1,n,1,n); } int updateY(int pos, int val) { update(1,1,n,pos+1,pos+1,inv(y[pos])); y[pos] = val; update(1,1,n,pos+1,pos+1,y[pos]); return getans(1,1,n,1,n); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...