답안 #992996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
992996 2024-06-05T08:49:50 Z emad234 말 (IOI15_horses) C++17
100 / 100
1481 ms 57632 KB
#include "horses.h"
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S 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;
struct ones
{
	int l,r;
	friend bool operator<(ones a, ones b) {return a.l < b.l;}
};
 
set<ones> 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, INT_MAX});
			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.upper_bound({i, INT_MAX});
			it--;
			seg.s = i + 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++)
	{
		// s.insert({i, i});
		if (X[i] == 1)
		{
			if (l == -1)
				l = i;
			r = i;
		}
		else
		{
			if (l != -1)
			{
				s.insert({l, r});
				l = -1;r = -1;
			}
		}
	}
	if (l != -1)
	{
		s.insert({l, r});
		l = -1; 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);
	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 function 'long long int solve()':
horses.cpp:61:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   61 |  int i = n - 1;
      |          ~~^~~
horses.cpp:78:7: warning: statement has no effect [-Wunused-value]
   78 |  for (i; i < n; i++)
      |       ^
horses.cpp:60:5: warning: unused variable 'st' [-Wunused-variable]
   60 |  ll st, id = 0;
      |     ^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:154:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  154 |  return solve();
      |         ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:170:8: warning: variable 'p' set but not used [-Wunused-but-set-variable]
  170 |   auto p = s.lower_bound({l, r});
      |        ^
horses.cpp:190:14: warning: narrowing conversion of 'l' from 'long long int' to 'int' [-Wnarrowing]
  190 |    s.insert({l, r});
      |              ^
horses.cpp:190:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
horses.cpp:190:17: warning: narrowing conversion of 'r' from 'long long int' to 'int' [-Wnarrowing]
  190 |    s.insert({l, r});
      |                 ^
horses.cpp:190:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
horses.cpp:192:14: warning: narrowing conversion of 'l1' from 'long long int' to 'int' [-Wnarrowing]
  192 |    s.insert({l1, r1});
      |              ^~
horses.cpp:192:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
horses.cpp:192:18: warning: narrowing conversion of 'r1' from 'long long int' to 'int' [-Wnarrowing]
  192 |    s.insert({l1, r1});
      |                  ^~
horses.cpp:192:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
horses.cpp:196:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  196 |  return solve();
      |         ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:203:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  203 |  return solve();
      |         ~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2644 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 5 ms 348 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 6 ms 2588 KB Output is correct
28 Correct 6 ms 348 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 45908 KB Output is correct
2 Correct 176 ms 45808 KB Output is correct
3 Correct 140 ms 45824 KB Output is correct
4 Correct 155 ms 45832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2408 KB Output is correct
2 Correct 1 ms 2408 KB Output is correct
3 Correct 1 ms 2408 KB Output is correct
4 Correct 1 ms 2408 KB Output is correct
5 Correct 1 ms 356 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 1 ms 2400 KB Output is correct
8 Correct 0 ms 2408 KB Output is correct
9 Correct 1 ms 2408 KB Output is correct
10 Correct 0 ms 2408 KB Output is correct
11 Correct 1 ms 2408 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 5 ms 2588 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 5 ms 2396 KB Output is correct
28 Correct 4 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 2 ms 2392 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 3 ms 2396 KB Output is correct
33 Correct 208 ms 45140 KB Output is correct
34 Correct 83 ms 45136 KB Output is correct
35 Correct 106 ms 44884 KB Output is correct
36 Correct 103 ms 44880 KB Output is correct
37 Correct 197 ms 45136 KB Output is correct
38 Correct 254 ms 56656 KB Output is correct
39 Correct 79 ms 44880 KB Output is correct
40 Correct 89 ms 44884 KB Output is correct
41 Correct 73 ms 45040 KB Output is correct
42 Correct 95 ms 45036 KB Output is correct
43 Correct 84 ms 44900 KB Output is correct
44 Correct 86 ms 44884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2480 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 5 ms 2580 KB Output is correct
24 Correct 2 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 5 ms 2580 KB Output is correct
28 Correct 4 ms 2612 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 122 ms 45808 KB Output is correct
34 Correct 165 ms 46064 KB Output is correct
35 Correct 125 ms 45908 KB Output is correct
36 Correct 149 ms 45904 KB Output is correct
37 Correct 211 ms 45172 KB Output is correct
38 Correct 84 ms 45136 KB Output is correct
39 Correct 104 ms 44880 KB Output is correct
40 Correct 101 ms 45036 KB Output is correct
41 Correct 208 ms 45136 KB Output is correct
42 Correct 248 ms 56660 KB Output is correct
43 Correct 73 ms 44852 KB Output is correct
44 Correct 89 ms 45036 KB Output is correct
45 Correct 71 ms 44888 KB Output is correct
46 Correct 94 ms 44880 KB Output is correct
47 Correct 82 ms 44880 KB Output is correct
48 Correct 83 ms 44784 KB Output is correct
49 Correct 1296 ms 46828 KB Output is correct
50 Correct 213 ms 46932 KB Output is correct
51 Correct 183 ms 45908 KB Output is correct
52 Correct 155 ms 45908 KB Output is correct
53 Correct 1228 ms 46848 KB Output is correct
54 Correct 1481 ms 57632 KB Output is correct
55 Correct 135 ms 47976 KB Output is correct
56 Correct 158 ms 52816 KB Output is correct
57 Correct 115 ms 48740 KB Output is correct
58 Correct 344 ms 49256 KB Output is correct
59 Correct 86 ms 51284 KB Output is correct