Submission #1079978

# Submission time Handle Problem Language Result Execution time Memory
1079978 2024-08-29T05:22:59 Z Trumling Horses (IOI15_horses) C++14
17 / 100
1500 ms 8436 KB
#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() || Y[sell[sell.size()-1]]*curr < Y[i] || mod)
		{
			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 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() || y[sell[sell.size()-1]]*curr < y[i] || mod)
		{
			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() || y[sell[sell.size()-1]]*curr < y[i] || mod)
		{
			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

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: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: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: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 time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 428 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Incorrect 0 ms 348 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1556 ms 8436 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Incorrect 0 ms 600 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 428 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Incorrect 0 ms 348 KB Output isn't correct
22 Halted 0 ms 0 KB -