Submission #99640

#TimeUsernameProblemLanguageResultExecution timeMemory
99640Retro3014Horses (IOI15_horses)C++17
20 / 100
1032 ms50552 KiB
#include "horses.h" #include <bits/stdc++.h> typedef long long ll; const ll DIV = 1000000007; using namespace std; vector<int> x, y; struct SEG{ int l, r; ll data; }; vector<SEG> seg1, seg2; void inits1(int idx, int s, int e){ seg1.push_back({-1, -1, 1}); if(s==e){ seg1[idx].data = x[s]%DIV; return; } seg1[idx].l = seg1.size(); inits1(seg1[idx].l, s, (s+e)/2); seg1[idx].r = seg1.size(); inits1(seg1[idx].r, (s+e)/2+1, e); seg1[idx].data = (seg1[seg1[idx].l].data * seg1[seg1[idx].r].data)%DIV; } void inits2(int idx, int s, int e){ seg2.push_back({-1, -1, 0}); if(s==e){ seg2[idx].data = y[s]; return; } seg2[idx].l = seg2.size(); inits2(seg2[idx].l, s, (s+e)/2); seg2[idx].r = seg2.size(); inits2(seg2[idx].r, (s+e)/2+1, e); seg2[idx].data = max(seg2[seg2[idx].l].data, seg2[seg2[idx].r].data); } ll calc1(int idx, int s, int e, int x, int y){ if(idx==-1) return 1; if(x<=s && e<=y) return seg1[idx].data; if(x>e || s>y) return 1; return (calc1(seg1[idx].l, s, (s+e)/2, x, y) * calc1(seg1[idx].r, (s+e)/2+1, e, x, y))%DIV; } ll calc2(int idx, int s, int e, int x, int y){ if(idx==-1) return 0; if(x<=s && e<=y) return seg2[idx].data; if(x>e || s>y) return 0; return max(calc2(seg2[idx].l, s, (s+e)/2, x, y), calc2(seg2[idx].r, (s+e)/2+1, e, x, y)); } void update1(int idx, int s, int e, int x, int y){ if(idx==-1) return; if(s==e) { seg1[idx].data = y%DIV; return; } if(x<=(s+e)/2){ update1(seg1[idx].l, s, (s+e)/2, x, y); }else{ update1(seg1[idx].r, (s+e)/2+1, e, x, y); } seg1[idx].data = (seg1[seg1[idx].l].data * seg1[seg1[idx].r].data)%DIV; return; } void update2(int idx, int s, int e, int x, int y){ if(idx==-1) return; if(s==e){ seg2[idx].data = y; return; } if(x<=(s+e)/2){ update2(seg2[idx].l, s, (s+e)/2, x, y); }else{ update2(seg2[idx].r, (s+e)/2+1, e, x, y); } seg2[idx].data = max(seg2[seg2[idx].l].data, seg2[seg2[idx].r].data); return; } priority_queue<int> pq; vector<int> t; int calc_ans(){ ll m = 1; ll ans = 0; t.push_back(x.size()); while(!pq.empty()){ int k = pq.top(); pq.pop(); if(x[k]==1) continue; t.push_back(k); m *= x[k]; //cout<<k<<' '; if(m>1000000000LL) break; }//cout<<endl; m = 1; ll nowy, prvy; int idx = t.size()-1; prvy = calc2(0, 0, x.size()-1, t[idx], t[idx-1]-1); for(int i=t.size()-2; i>=1; i--){ m*=x[t[i]]; nowy = calc2(0, 0, x.size()-1, t[i], t[i-1]-1); //cout<<idx<<' '<<prvy<<' '<<m<<' '<<nowy<<' '<<i<<endl; if(m*nowy>prvy){ idx = i; prvy = nowy; m = 1; } } //cout<<t[idx]<<endl; ans = (calc1(0, 0, x.size()-1, 0, t[idx]) * prvy)%DIV; while(t.size()>1){ pq.push(t.back()); t.pop_back(); }t.pop_back(); return ans; } int init(int N, int X[], int Y[]){ for(int i=0; i<N; i++){ x.push_back(X[i]); y.push_back(Y[i]); if(X[i]!=1){ pq.push(i); } } inits1(0, 0, N-1); inits2(0, 0, N-1); return calc_ans(); } int updateX(int pos, int val){ if(x[pos]==1 && val!=1){ pq.push(pos); } x[pos] = val; update1(0, 0, x.size()-1, pos, val); return calc_ans(); } int updateY(int pos, int val){ y[pos] = val; update2(0, 0, x.size()-1, pos, val); return calc_ans(); }

Compilation message (stderr)

horses.cpp: In function 'void inits1(int, int, int)':
horses.cpp:23:25: warning: conversion to 'int' from 'std::vector<SEG>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  seg1[idx].l = seg1.size(); inits1(seg1[idx].l, s, (s+e)/2);
                ~~~~~~~~~^~
horses.cpp:24:25: warning: conversion to 'int' from 'std::vector<SEG>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  seg1[idx].r = seg1.size(); inits1(seg1[idx].r, (s+e)/2+1, e);
                ~~~~~~~~~^~
horses.cpp: In function 'void inits2(int, int, int)':
horses.cpp:33:25: warning: conversion to 'int' from 'std::vector<SEG>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  seg2[idx].l = seg2.size(); inits2(seg2[idx].l, s, (s+e)/2);
                ~~~~~~~~~^~
horses.cpp:34:25: warning: conversion to 'int' from 'std::vector<SEG>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  seg2[idx].r = seg2.size(); inits2(seg2[idx].r, (s+e)/2+1, e);
                ~~~~~~~~~^~
horses.cpp: In function 'll calc1(int, int, int, int, int)':
horses.cpp:38:45: warning: declaration of 'y' shadows a global declaration [-Wshadow]
 ll calc1(int idx, int s, int e, int x, int y){
                                             ^
horses.cpp:9:16: note: shadowed declaration is here
 vector<int> x, y;
                ^
horses.cpp:38:45: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 ll calc1(int idx, int s, int e, int x, int y){
                                             ^
horses.cpp:9:13: note: shadowed declaration is here
 vector<int> x, y;
             ^
horses.cpp: In function 'll calc2(int, int, int, int, int)':
horses.cpp:45:45: warning: declaration of 'y' shadows a global declaration [-Wshadow]
 ll calc2(int idx, int s, int e, int x, int y){
                                             ^
horses.cpp:9:16: note: shadowed declaration is here
 vector<int> x, y;
                ^
horses.cpp:45:45: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 ll calc2(int idx, int s, int e, int x, int y){
                                             ^
horses.cpp:9:13: note: shadowed declaration is here
 vector<int> x, y;
             ^
horses.cpp: In function 'void update1(int, int, int, int, int)':
horses.cpp:52:49: warning: declaration of 'y' shadows a global declaration [-Wshadow]
 void update1(int idx, int s, int e, int x, int y){
                                                 ^
horses.cpp:9:16: note: shadowed declaration is here
 vector<int> x, y;
                ^
horses.cpp:52:49: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 void update1(int idx, int s, int e, int x, int y){
                                                 ^
horses.cpp:9:13: note: shadowed declaration is here
 vector<int> x, y;
             ^
horses.cpp: In function 'void update2(int, int, int, int, int)':
horses.cpp:66:49: warning: declaration of 'y' shadows a global declaration [-Wshadow]
 void update2(int idx, int s, int e, int x, int y){
                                                 ^
horses.cpp:9:16: note: shadowed declaration is here
 vector<int> x, y;
                ^
horses.cpp:66:49: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 void update2(int idx, int s, int e, int x, int y){
                                                 ^
horses.cpp:9:13: note: shadowed declaration is here
 vector<int> x, y;
             ^
horses.cpp: In function 'int calc_ans()':
horses.cpp:87:20: warning: conversion to 'std::vector<int>::value_type {aka int}' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  t.push_back(x.size());
              ~~~~~~^~
horses.cpp:97:20: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  int idx = t.size()-1;
            ~~~~~~~~^~
horses.cpp:98:29: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  prvy = calc2(0, 0, x.size()-1, t[idx], t[idx-1]-1);
                     ~~~~~~~~^~
horses.cpp:99:20: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  for(int i=t.size()-2; i>=1; i--){
            ~~~~~~~~^~
horses.cpp:101:30: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
   nowy = calc2(0, 0, x.size()-1, t[i], t[i-1]-1);
                      ~~~~~~~~^~
horses.cpp:109:29: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  ans = (calc1(0, 0, x.size()-1, 0, t[idx]) * prvy)%DIV;
                     ~~~~~~~~^~
horses.cpp:114:9: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return ans;
         ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:134:24: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  update1(0, 0, x.size()-1, pos, val);
                ~~~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:140:24: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  update2(0, 0, x.size()-1, pos, val);
                ~~~~~~~~^~
#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...