Submission #795796

#TimeUsernameProblemLanguageResultExecution timeMemory
795796Username4132Horses (IOI15_horses)C++14
0 / 100
1543 ms31828 KiB
#include "horses.h" #include<iostream> #include<vector> #include<algorithm> #include<set> using namespace std; using ll = long long; using pii = pair<int, int>; using pli = pair<ll, int>; #define forn(i, n) for(int i=0; i<(int)n; ++i) #define forsn(i, s, n) for(int i=s; i<(int)n; ++i) #define PB push_back #define F first #define S second const int MAXN = 500010, MOD = 1000000007; int n, arr[MAXN], brr[MAXN]; set<int> ones; pii query(int l, int r){ //cerr << l << ' ' << r << endl; pii mx={0, -1}; forsn(i, l, r) mx=max(mx, {brr[i], i}); return mx; } int pro(int r){ ll ret=1; forn(i, r+1) ret=(ret*arr[i])%MOD; return (ret*brr[r])%MOD; } int solve(){ ll prod=1; vector<int> lis; int sz = ones.size(), pos = n-1; auto itr = ones.end(); forn(i, sz){ itr = prev(itr); prod*=arr[*itr]; lis.PB(*itr); if(prod>1000000000) break; } reverse(lis.begin(), lis.end()); ll p=1; pli mx = {0, 0}; for(int el:lis){ if(el!=lis.back()) p*=arr[el]; pli opt = query(el, n); opt.F*=p; mx = max(mx, opt); } pli aa = query(0, n); if(lis.empty() || ((aa.F / mx.F) >= arr[lis.back()])) mx=aa; return pro(mx.S); } int init(int N, int X[], int Y[]) { n=N; forn(i, n){ arr[i]=X[i]; if(arr[i]!=1) ones.insert(i); } forn(i, n) brr[i]=Y[i]; return solve(); } int updateX(int pos, int val) { if(arr[pos]==1 && val!=1) ones.insert(pos); if(arr[pos]!=1 && val==1) ones.erase(pos); arr[pos]=val; return solve(); } int updateY(int pos, int val) { brr[pos]=val; return solve(); }

Compilation message (stderr)

horses.cpp: In function 'int pro(int)':
horses.cpp:30:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   30 |  return (ret*brr[r])%MOD;
      |         ~~~~~~~~~~~~^~~~
horses.cpp: In function 'int solve()':
horses.cpp:37:20: warning: conversion from 'std::set<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   37 |  int sz = ones.size(), pos = n-1;
      |           ~~~~~~~~~^~
horses.cpp:37:24: warning: unused variable 'pos' [-Wunused-variable]
   37 |  int sz = ones.size(), pos = n-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...