Submission #393437

#TimeUsernameProblemLanguageResultExecution timeMemory
393437Kenzo_1114Horses (IOI15_horses)C++17
17 / 100
543 ms45432 KiB
#include<bits/stdc++.h> #include "horses.h" using namespace std; const int MAXN = 500010; const long long int MOD = 1e9 + 7; int n; long long int x[MAXN], y[MAXN]; long long int seg[4 * MAXN], lz[4 * MAXN]; void refresh(int pos, int bg, int ed) { if(lz[pos] == 1) return; long long int Lz = lz[pos]; lz[pos] = 1; seg[pos] = (seg[pos] * Lz) % MOD; if(bg == ed) return; int mid = (bg + ed) >> 1, l = 2 * pos, r = l + 1; lz[l] = (lz[l] * Lz) % MOD; lz[r] = (lz[r] * Lz) % MOD; } void upd(int pos, int bg, int ed, int p, int q, long long int val) { refresh(pos, bg, ed); if(q < p || q < bg || ed < p) return; if(p <= bg && ed <= q) { lz[pos] = (lz[pos] * val) % MOD; refresh(pos, bg, ed); return; } int mid = (bg + ed) >> 1, l = 2 * pos, r = l + 1; upd(l, bg, mid, p, q, val); upd(r, mid + 1, ed, p, q, val); seg[pos] = max(seg[l], seg[r]); } long long int fe(long long int a, long long int p) { if(p == 0) return 1; if(p == 1) return a; long long int b = fe(a, p / 2); b = (b * b) % MOD; if(p & 1) b = (b * a) % MOD; return b; } int updateX(int pos, int val) { pos++; upd(1, 1, n, pos, n, fe(x[pos], MOD - 2)); x[pos] = val; upd(1, 1, n, pos, n, x[pos]); refresh(1, 1, n); return (int) seg[1]; } int updateY(int pos, int val) { pos++; upd(1, 1, n, pos, pos, fe(y[pos], MOD - 2)); y[pos] = val; upd(1, 1, n, pos, pos, y[pos]); refresh(1, 1, n); return (int) seg[1]; } int init(int N, int X[], int Y[]) { n = N; for(int i = n; i > 0; i--) x[i] = X[i - 1]; for(int i = n; i > 0; i--) y[i] = Y[i - 1]; for(int i = 1; i < 4 * MAXN; i++) lz[i] = 1, seg[i] = 1; for(int i = 1; i <= n; i++) { upd(1, 1, n, i, n, x[i]); upd(1, 1, n, i, i, y[i]); } refresh(1, 1, n); return (int) seg[1]; } /* int N; long long int X[MAXN], Y[MAXN]; int main () { scanf("%d", &N); for(int i = 0; i < N; i++) scanf("%lld", &X[i]); for(int i = 0; i < N; i++) scanf("%lld", &Y[i]); printf("%d\n", init(N, X, Y)); printf("%d\n", updateY(1, 2)); } 3 2 1 3 3 4 1 */

Compilation message (stderr)

horses.cpp: In function 'void refresh(int, int, int)':
horses.cpp:20:6: warning: unused variable 'mid' [-Wunused-variable]
   20 |  int mid = (bg + ed) >> 1, l = 2 * pos, r = l + 1;
      |      ^~~
#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...