Submission #1079983

#TimeUsernameProblemLanguageResultExecution timeMemory
1079983TrumlingHorses (IOI15_horses)C++14
34 / 100
1592 ms12412 KiB
#include "horses.h" #include<bits/stdc++.h> using namespace std; #define F first #define S second #define pb push_back #define all(x) x.begin(),x.end() #define INF 9999999999999999 #define MOD 1000000007 typedef long long ll; ll n; vector<int>sell; vector<int>x,y; int init(int N, int X[], int Y[]) { n=N; ll curr=1; for(int i=0;i<n;i++) { x.pb(X[i]); y.pb(Y[i]); } bool mod=0; for(int i=n-1;i>=0;i--) { if(sell.empty() || !mod && y[sell[sell.size()-1]]*curr < y[i]) { sell.pb(i); curr=1; mod=0; } curr*=x[i]; if(curr>=MOD) { curr%=MOD; mod=1; } } for(int i=0;i<sell.size()/2;i++) swap(sell[i],sell[sell.size()-1-i]); //for(int i=0;i<sell.size();i++) //cout<<sell[i]<<' '; ll idx=0; ll ans=0; curr=1; for(int i=0;i<n;i++) { curr*=x[i]; curr%=MOD; if(sell[idx]==i) { ans+=(curr*y[i])%MOD; ans%=MOD; idx++; curr=0; } } return ans; } int updateX(int pos, int val) { ll curr=1; x[pos]=val; sell.clear(); bool mod=0; for(int i=n-1;i>=0;i--) { if(sell.empty() || !mod && y[sell[sell.size()-1]]*curr < y[i]) { sell.pb(i); curr=1; mod=0; } curr*=x[i]; if(curr>=MOD) { mod=1; curr%=MOD; } } for(int i=0;i<sell.size()/2;i++) swap(sell[i],sell[sell.size()-1-i]); //for(int i=0;i<sell.size();i++) //cout<<sell[i]<<' '; ll idx=0; ll ans=0; curr=1; for(int i=0;i<n;i++) { curr*=x[i]; curr%=MOD; if(sell[idx]==i) { ans+=(curr*y[i])%MOD; ans%=MOD; idx++; curr=0; } } return ans; } int updateY(int pos, int val) { ll curr=1; y[pos]=val; sell.clear(); bool mod=0; for(int i=n-1;i>=0;i--) { if(sell.empty() || !mod && y[sell[sell.size()-1]]*curr < y[i]) { sell.pb(i); curr=1; mod=0; } curr*=x[i]; if(curr>=MOD) { mod=1; curr%=MOD; } } for(int i=0;i<sell.size()/2;i++) swap(sell[i],sell[sell.size()-1-i]); //for(int i=0;i<sell.size();i++) //cout<<sell[i]<<' '; ll idx=0; ll ans=0; curr=1; for(int i=0;i<n;i++) { curr*=x[i]; curr%=MOD; if(sell[idx]==i) { ans+=(curr*y[i])%MOD; ans%=MOD; idx++; curr=0; } } return ans; }

Compilation message (stderr)

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:27:13: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   27 |  for(int i=n-1;i>=0;i--)
      |            ~^~
horses.cpp:29:27: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   29 |   if(sell.empty() || !mod && y[sell[sell.size()-1]]*curr < y[i])
horses.cpp:43:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for(int i=0;i<sell.size()/2;i++)
      |              ~^~~~~~~~~~~~~~
horses.cpp:64:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   64 |  return ans;
      |         ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:75:13: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   75 |  for(int i=n-1;i>=0;i--)
      |            ~^~
horses.cpp:77:27: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   77 |   if(sell.empty() || !mod && y[sell[sell.size()-1]]*curr < y[i])
horses.cpp:91:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |  for(int i=0;i<sell.size()/2;i++)
      |              ~^~~~~~~~~~~~~~
horses.cpp:112:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  112 |  return ans;
      |         ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:121:13: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  121 |  for(int i=n-1;i>=0;i--)
      |            ~^~
horses.cpp:123:27: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  123 |   if(sell.empty() || !mod && y[sell[sell.size()-1]]*curr < y[i])
horses.cpp:137:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |  for(int i=0;i<sell.size()/2;i++)
      |              ~^~~~~~~~~~~~~~
horses.cpp:158:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  158 |  return ans;
      |         ^~~
#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...