답안 #955762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955762 2024-03-31T11:57:42 Z emad234 말 (IOI15_horses) C++17
컴파일 오류
0 ms 0 KB
#include "horses.h"
#include <bits/stdc++.h>
#define ll long long
#define l first
#define r second
#define pii pair<ll, ll>
const ll mod = 1e9 + 7;
const ll mxN = 5e5 + 5;
using namespace std;
ll NN;
struct tree
{
	vector<pii> seg;
	ll s, e;
	void init(ll n)
	{
		NN = exp2(ceil(log2(n)));
		seg.resize(NN * 4);
	}
	ll queryMax(ll l = 1, ll r = NN, ll ind = 1)
	{
		if (l > e || r < s)
			return 0;
		if (l >= s && r <= e)
			return seg[ind].F;
		ll md = (l + r) / 2;
		return max(queryMax(l, md, ind * 2), queryMax(md + 1, r, ind * 2 + 1));
	}
	ll queryProd(ll l = 1, ll r = NN, ll ind = 1)
	{
		if (l > e || r < s)
			return 1;
		if (l >= s && r <= e)
			return seg[ind].S;
		ll md = (l + r) / 2;
		return (queryProd(l, md, ind * 2) * queryProd(md + 1, r, ind * 2 + 1)) % mod;
	}
	void update(pii val, ll ind)
	{
		ind += NN;
		seg[ind] = val;
		while (ind /= 2)
		{
			seg[ind].F = max(seg[ind * 2].F, seg[ind * 2 + 1].F);
			seg[ind].S = (seg[ind * 2].S * seg[ind * 2 + 1].S) % mod;
		}
	}
} seg;
set<pii> s;
ll x[mxN], y[mxN];
ll n;
ll solve()
{
	ll st, id = 0;
	int i = n - 1;
	while (i > 0 && id <= 100)
	{
		if (x[i] == 1)
		{
			auto it = s.upper_bound({i, i});
			it--;
			i = (*it).l;
			id--;
		}
		i--;
		id++;
	}
	if (i == -1)
		i = 0;
	ll mx = -1, mxid = -1;
	ll prd = 1;
	for (i; i < n; i++)
	{
		if (x[i] == 1)
		{
			auto it = s.lower_bound({i, i});
			seg.s = (*it).l + 1, seg.e = (*it).r + 1;
			ll val = seg.queryMax();
			if (val * prd > mx)
			{
				mx = val;
				mxid = i;
				prd = 1;
			}
			i = (*it).r;
			continue;
		}
		if (prd * x[i] > mx)
		{
			mx = y[i];
			mxid = i;
			prd = 1;
			continue;
		}
		prd *= x[i];
		if (prd * y[i] > mx)
		{
			mx = y[i];
			mxid = i;
			prd = 1;
			continue;
		}
	}
	seg.s = 1;
	seg.e = mxid + 1;
	return (mx * seg.queryProd()) % mod;
}
int init(int N, int X[], int Y[])
{
	seg.init(N);
	n = N;
	for (int i = 0; i < N; i++)
	{
		y[i] = Y[i];
		x[i] = X[i];
		seg.update({Y[i], X[i]}, i);
	}
	int l = -1, r = -1;
	for (int i = 0; i < N; i++)
	{
		if (X[i] == 1)
		{
			if (l == -1)
				l = i;
			r = i;
		}
		else
		{
			if (l != -1)
			{
				s.insert({l, r});
				l = r = -1;
			}
		}
	}
	if (l != -1)
	{
		s.insert({l, r});
		l = r = -1;
	}
	// for (auto el : s)
	// {
	// 	fprintf(_outputFile, "%d ", el.l);
	// 	fprintf(_outputFile, "%d\n", el.r);
	// }
	return solve();
}

int updateX(int pos, int val)
{
	if (x[pos] != 1 && val == 1)
	{
		auto it = s.upper_bound({pos, pos});
		int l = pos, r = pos;
		if (it != s.end() && (*it).l == pos + 1)
		{
			l = pos, r = (*it).r;
			s.erase(it);
		}
		s.insert({l, r});
		it = s.lower_bound({l, r});
		auto p = s.lower_bound({l, r});
		if (it != s.begin())
		{
			it--;
			if ((*it).r == l - 1)
			{
				l = (*it).l;
				s.erase(it);
				s.erase(s.lower_bound({pos, pos}));
				s.insert({l, r});
			}
		}
	}
	if (x[pos] == 1 && val != 1)
	{
		auto it = s.upper_bound({pos, 0});
		it--;
		ll l = (*it).l, r = pos - 1, l1 = pos + 1, r1 = (*it).r;
		s.erase(it);
		if (l <= r)
			s.insert({l, r});
		if (l1 <= r1)
			s.insert({l1, r1});
	}
	x[pos] = val;
	seg.update({y[pos], x[pos]}, pos);
	// for (auto el : s)
	// {
	// 	fprintf(_outputFile, "%d ", el.l);
	// 	fprintf(_outputFile, "%d\n", el.r);
	// }
	return solve();
}

int updateY(int pos, int val)
{
	y[pos] = val;
	seg.update({y[pos], x[pos]}, pos);
	return solve();
}

Compilation message

horses.cpp: In member function 'void tree::init(long long int)':
horses.cpp:17:12: warning: conversion from 'double' to 'long long int' may change value [-Wfloat-conversion]
   17 |   NN = exp2(ceil(log2(n)));
      |        ~~~~^~~~~~~~~~~~~~~
horses.cpp: In member function 'long long int tree::queryMax(long long int, long long int, long long int)':
horses.cpp:25:20: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'struct std::pair<long long int, long long int>'} has no member named 'F'
   25 |    return seg[ind].F;
      |                    ^
horses.cpp: In member function 'long long int tree::queryProd(long long int, long long int, long long int)':
horses.cpp:34:20: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'struct std::pair<long long int, long long int>'} has no member named 'S'
   34 |    return seg[ind].S;
      |                    ^
horses.cpp: In member function 'void tree::update(std::pair<long long int, long long int>, long long int)':
horses.cpp:44:13: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'struct std::pair<long long int, long long int>'} has no member named 'F'
   44 |    seg[ind].F = max(seg[ind * 2].F, seg[ind * 2 + 1].F);
      |             ^
horses.cpp:44:34: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'struct std::pair<long long int, long long int>'} has no member named 'F'
   44 |    seg[ind].F = max(seg[ind * 2].F, seg[ind * 2 + 1].F);
      |                                  ^
horses.cpp:44:54: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'struct std::pair<long long int, long long int>'} has no member named 'F'
   44 |    seg[ind].F = max(seg[ind * 2].F, seg[ind * 2 + 1].F);
      |                                                      ^
horses.cpp:45:13: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'struct std::pair<long long int, long long int>'} has no member named 'S'
   45 |    seg[ind].S = (seg[ind * 2].S * seg[ind * 2 + 1].S) % mod;
      |             ^
horses.cpp:45:31: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'struct std::pair<long long int, long long int>'} has no member named 'S'
   45 |    seg[ind].S = (seg[ind * 2].S * seg[ind * 2 + 1].S) % mod;
      |                               ^
horses.cpp:45:52: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'struct std::pair<long long int, long long int>'} has no member named 'S'
   45 |    seg[ind].S = (seg[ind * 2].S * seg[ind * 2 + 1].S) % mod;
      |                                                    ^
horses.cpp: In function 'long long int solve()':
horses.cpp:55:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   55 |  int i = n - 1;
      |          ~~^~~
horses.cpp:4:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
    4 | #define l first
      |           ^
horses.cpp:62:14: note: in expansion of macro 'l'
   62 |    i = (*it).l;
      |              ^
horses.cpp:72:7: warning: statement has no effect [-Wunused-value]
   72 |  for (i; i < n; i++)
      |       ^
horses.cpp:5:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
    5 | #define r second
      |           ^
horses.cpp:85:14: note: in expansion of macro 'r'
   85 |    i = (*it).r;
      |              ^
horses.cpp:54:5: warning: unused variable 'st' [-Wunused-variable]
   54 |  ll st, id = 0;
      |     ^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:146:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  146 |  return solve();
      |         ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:5:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
    5 | #define r second
      |           ^
horses.cpp:157:23: note: in expansion of macro 'r'
  157 |    l = pos, r = (*it).r;
      |                       ^
horses.cpp:4:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
    4 | #define l first
      |           ^
horses.cpp:168:15: note: in expansion of macro 'l'
  168 |     l = (*it).l;
      |               ^
horses.cpp:193:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  193 |  return solve();
      |         ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:200:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  200 |  return solve();
      |         ~~~~~^~