제출 #248487

#제출 시각아이디문제언어결과실행 시간메모리
248487ernestvw말 (IOI15_horses)C++11
17 / 100
1584 ms53624 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; int n; vector<ll> C, P; set<int> indices; ll treeProd[4000000],treeMax[4000000]; void updateProd(int l, int r, int idx, int i, ll val) { if(idx < l || r < idx || r < l) return; if(l == r) { treeProd[i] = val; return; } updateProd(l, (l+r)/2, idx, 2*i+1, val); updateProd((l+r)/2+1, r, idx, 2*i+2, val); treeProd[i] = treeProd[2*i+1] * treeProd[2*i+2]; treeProd[i] %= mod; } ll getProd(int l, int r, int L, int R, int i) { if(R < l || L > r || r < l) return 1; if(L <= l && r <= R) return treeProd[i]; return (getProd(l, (l+r)/2, L, R, 2*i+1) * getProd((l+r)/2+1, r, L, R, 2*i+2)) % mod; } void updateMax(int l, int r, int idx, int i, ll val) { if(idx < l || r < idx || r < l) return; if(l == r) { treeMax[i] = val; return; } updateMax(l, (l+r)/2, idx, 2*i+1, val); updateMax((l+r)/2+1, r, idx, 2*i+2, val); treeMax[i] = max(treeMax[2*i+1], treeMax[2*i+2]); } ll getMax(int l, int r, int L, int R, int i) { if(R < l || L > r || r < l) return 0; if(L <= l && r <= R) return treeMax[i]; return max(getMax(l, (l+r)/2, L, R, 2*i+1), getMax((l+r)/2+1, r, L, R, 2*i+2)); } int solve() { ll prod = 1; int best = n-1; ll pbest = 1; int der = n; for(auto it = indices.rbegin(); it != indices.rend(); it++) { int i = *it; prod *= C[i]; ll p = getMax(0, n-1, i, der-1, 0); if(prod * pbest <= C[i] * p) { best = i; prod = C[i]; pbest = p; } if(prod > 1e9) break; der = i; } prod = getProd(0, n-1, 0, best, 0); prod *= pbest; prod %= mod; return int(prod); } int init(int N, int X[], int Y[]) { n = N; C.resize(n); P.resize(n); for(int i = 0; i < n; ++i) C[i] = X[i]; for(int i = 0; i < n; ++i) P[i] = Y[i]; memset(treeProd, 1, sizeof(P)); memset(treeMax, 0, sizeof(P)); for(int i = 0; i < n; ++i) { updateProd(0, n - 1, i, 0, C[i]); updateMax(0, n - 1, i, 0, P[i]); } for(int i = 0; i < n; ++i) if(C[i] > 1 || i == 0) indices.insert(i); return solve(); } int updateX(int pos, int val) { updateProd(0, n-1, pos, 0, val); if(indices.find(pos) != indices.end()) indices.erase(pos); if(pos == 0 || val > 1) indices.insert(pos); C[pos] = val; return solve(); } int updateY(int pos, int val) { updateMax(0, n-1, pos, 0, val); P[pos] = val; return solve(); }

컴파일 시 표준 에러 (stderr) 메시지

horses.cpp: In function 'int solve()':
horses.cpp:63:13: warning: conversion to 'double' from 'll {aka long long int}' may alter its value [-Wconversion]
   if(prod > 1e9) break;
             ^~~
#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...