Submission #285079

#TimeUsernameProblemLanguageResultExecution timeMemory
285079Shafin666Horses (IOI15_horses)C++14
100 / 100
238 ms58488 KiB
#include "horses.h" #include <bits/stdc++.h> #define pb push_back #define pii pair<ll, ll> #define nyan "(=^・ω・^=)" #define read_input freopen("in.txt","r", stdin) #define print_output freopen("out.txt","w", stdout) typedef long long ll; typedef long double ld; using namespace std; const int maxn = 5e5+10, mod = 1e9+7; ll x[maxn], y[maxn], n; struct node { double lg; // log x0 + log x1 + ... double mxlg; // max log (x0 x1 x2 .... xi * yi) ll mul; // x0 x1 x2 ... % mod ll mxmul; // max x0 x1 ... xi * yi } tree[4 * maxn]; node merge(node a, node b) { node ret; ret.lg = a.lg + b.lg; ret.mul = (a.mul * b.mul) % mod; if(a.mxlg <= a.lg + b.mxlg) { ret.mxlg = a.lg + b.mxlg; ret.mxmul = (a.mul * b.mxmul) % mod; } else { ret.mxlg = a.mxlg; ret.mxmul = a.mxmul; } return ret; } void build(int at, int L, int R) { if(L == R) { node now; now.lg = log(x[L]); now.mxlg = log(x[L] * y[L]); now.mul = x[L]; now.mxmul = (x[L] * y[L]) % mod; tree[at] = now; return; } int mid = L + R >> 1; build(at<<1, L, mid); build(at<<1|1, mid+1, R); tree[at] = merge(tree[at<<1], tree[at<<1|1]); } void update(int at, int L, int R, int idx) { if(L == R) { node now; now.lg = log(x[L]); now.mxlg = log(x[L] * y[L]); now.mul = x[L]; now.mxmul = (x[L] * y[L]) % mod; tree[at] = now; return; } int mid = L + R >> 1; if(idx <= mid) update(at<<1, L, mid, idx); else update(at<<1|1, mid+1, R, idx); tree[at] = merge(tree[at<<1], tree[at<<1|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(1, 0, n-1); return tree[1].mxmul; } int updateX(int pos, int val) { x[pos] = val; update(1, 0, n-1, pos); return tree[1].mxmul; } int updateY(int pos, int val) { y[pos] = val; update(1, 0, n-1, pos); return tree[1].mxmul; }

Compilation message (stderr)

horses.cpp: In function 'void build(int, int, int)':
horses.cpp:47:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |  int mid = L + R >> 1;
      |            ~~^~~
horses.cpp: In function 'void update(int, int, int, int)':
horses.cpp:62:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |  int mid = L + R >> 1;
      |            ~~^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:73:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   73 |  build(1, 0, n-1);
      |              ~^~
horses.cpp:74:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   74 |  return tree[1].mxmul;
      |         ~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:80:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   80 |  update(1, 0, n-1, pos);
      |               ~^~
horses.cpp:81:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   81 |  return tree[1].mxmul;
      |         ~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:87:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   87 |  update(1, 0, n-1, pos);
      |               ~^~
horses.cpp:88:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   88 |  return tree[1].mxmul;
      |         ~~~~~~~~^~~~~
#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...