답안 #91196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91196 2018-12-26T13:53:15 Z davitmarg Money (IZhO17_money) C++17
45 / 100
1500 ms 20224 KB
/*
DEATH-MATCH
Davit-Marg
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <stdlib.h>  
#include <fstream>  
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
using namespace std;
int n,ans,a[1000006],l,it;
stack<int> st;

int t[4 * 1000006];

void update(int v,int l,int r,int pos)
{
	if (l == r)
	{
		t[v] = l;
		return;
	}
	int m = (l + r) / 2;
	if (pos <= m)
		update(v * 2, l, m, pos);
	else
		update(v * 2 + 1, m + 1, r, pos);
	t[v] = min(t[v * 2], t[v * 2 + 1]);
}

int query(int v, int l, int r, int i,int j)
{
	if (l == i && r==j)
		return t[v];
	int m = (l + r) / 2;
	if (j <= m)
		return query(v * 2, l, m, i, j);
	else if (i >= m + 1)
		return query(v * 2 + 1, m + 1, r, i, j);
	else
		return min(query(v * 2, l, m, i, m), t[v*2+1]);
}

int main()
{
	cin >> n;
	ans = 1;
	for (int i = 1; i <= n; i++)
		scanf("%d", a+i);
	for (int i = 0; i <= 4 * 1000000 + 2; i++)
		t[i] = mod;
	update(1, 0, 1000000, 0);
	it = mod;
	for (int i = 1; i <= n; i++)
	{
		if ((a[i] < a[i - 1]) || (it != mod && it < a[i]) )
		{
			l = a[i];
			ans++;
			while (!st.empty())
			{
				update(1, 0, 1000000, st.top());
				st.pop();
			}
			it = query(1, 0, 1000000, l + 1, 1000000);
		}
		st.push(a[i]);
	}

	cout << ans << endl;
	return 0;
}

/*

6
1 3 5 2 4 6

*/

Compilation message

money.cpp: In function 'int main()':
money.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a+i);
   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 15992 KB Output is correct
2 Correct 12 ms 16176 KB Output is correct
3 Correct 12 ms 16176 KB Output is correct
4 Correct 12 ms 16252 KB Output is correct
5 Correct 12 ms 16252 KB Output is correct
6 Correct 13 ms 16272 KB Output is correct
7 Correct 12 ms 16272 KB Output is correct
8 Correct 13 ms 16272 KB Output is correct
9 Correct 12 ms 16272 KB Output is correct
10 Correct 13 ms 16272 KB Output is correct
11 Correct 12 ms 16272 KB Output is correct
12 Correct 13 ms 16272 KB Output is correct
13 Correct 13 ms 16272 KB Output is correct
14 Correct 13 ms 16272 KB Output is correct
15 Correct 13 ms 16272 KB Output is correct
16 Correct 12 ms 16272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 15992 KB Output is correct
2 Correct 12 ms 16176 KB Output is correct
3 Correct 12 ms 16176 KB Output is correct
4 Correct 12 ms 16252 KB Output is correct
5 Correct 12 ms 16252 KB Output is correct
6 Correct 13 ms 16272 KB Output is correct
7 Correct 12 ms 16272 KB Output is correct
8 Correct 13 ms 16272 KB Output is correct
9 Correct 12 ms 16272 KB Output is correct
10 Correct 13 ms 16272 KB Output is correct
11 Correct 12 ms 16272 KB Output is correct
12 Correct 13 ms 16272 KB Output is correct
13 Correct 13 ms 16272 KB Output is correct
14 Correct 13 ms 16272 KB Output is correct
15 Correct 13 ms 16272 KB Output is correct
16 Correct 12 ms 16272 KB Output is correct
17 Correct 12 ms 16272 KB Output is correct
18 Correct 12 ms 16328 KB Output is correct
19 Correct 13 ms 16328 KB Output is correct
20 Correct 12 ms 16328 KB Output is correct
21 Correct 12 ms 16328 KB Output is correct
22 Correct 12 ms 16328 KB Output is correct
23 Correct 13 ms 16328 KB Output is correct
24 Correct 12 ms 16328 KB Output is correct
25 Correct 13 ms 16328 KB Output is correct
26 Correct 12 ms 16328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 15992 KB Output is correct
2 Correct 12 ms 16176 KB Output is correct
3 Correct 12 ms 16176 KB Output is correct
4 Correct 12 ms 16252 KB Output is correct
5 Correct 12 ms 16252 KB Output is correct
6 Correct 13 ms 16272 KB Output is correct
7 Correct 12 ms 16272 KB Output is correct
8 Correct 13 ms 16272 KB Output is correct
9 Correct 12 ms 16272 KB Output is correct
10 Correct 13 ms 16272 KB Output is correct
11 Correct 12 ms 16272 KB Output is correct
12 Correct 13 ms 16272 KB Output is correct
13 Correct 13 ms 16272 KB Output is correct
14 Correct 13 ms 16272 KB Output is correct
15 Correct 13 ms 16272 KB Output is correct
16 Correct 12 ms 16272 KB Output is correct
17 Correct 12 ms 16272 KB Output is correct
18 Correct 12 ms 16328 KB Output is correct
19 Correct 13 ms 16328 KB Output is correct
20 Correct 12 ms 16328 KB Output is correct
21 Correct 12 ms 16328 KB Output is correct
22 Correct 12 ms 16328 KB Output is correct
23 Correct 13 ms 16328 KB Output is correct
24 Correct 12 ms 16328 KB Output is correct
25 Correct 13 ms 16328 KB Output is correct
26 Correct 12 ms 16328 KB Output is correct
27 Correct 13 ms 16328 KB Output is correct
28 Correct 13 ms 16328 KB Output is correct
29 Correct 13 ms 16328 KB Output is correct
30 Correct 13 ms 16328 KB Output is correct
31 Correct 12 ms 16328 KB Output is correct
32 Correct 13 ms 16328 KB Output is correct
33 Correct 12 ms 16328 KB Output is correct
34 Correct 12 ms 16328 KB Output is correct
35 Correct 12 ms 16328 KB Output is correct
36 Correct 13 ms 16328 KB Output is correct
37 Correct 12 ms 16328 KB Output is correct
38 Correct 12 ms 16328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 15992 KB Output is correct
2 Correct 12 ms 16176 KB Output is correct
3 Correct 12 ms 16176 KB Output is correct
4 Correct 12 ms 16252 KB Output is correct
5 Correct 12 ms 16252 KB Output is correct
6 Correct 13 ms 16272 KB Output is correct
7 Correct 12 ms 16272 KB Output is correct
8 Correct 13 ms 16272 KB Output is correct
9 Correct 12 ms 16272 KB Output is correct
10 Correct 13 ms 16272 KB Output is correct
11 Correct 12 ms 16272 KB Output is correct
12 Correct 13 ms 16272 KB Output is correct
13 Correct 13 ms 16272 KB Output is correct
14 Correct 13 ms 16272 KB Output is correct
15 Correct 13 ms 16272 KB Output is correct
16 Correct 12 ms 16272 KB Output is correct
17 Correct 12 ms 16272 KB Output is correct
18 Correct 12 ms 16328 KB Output is correct
19 Correct 13 ms 16328 KB Output is correct
20 Correct 12 ms 16328 KB Output is correct
21 Correct 12 ms 16328 KB Output is correct
22 Correct 12 ms 16328 KB Output is correct
23 Correct 13 ms 16328 KB Output is correct
24 Correct 12 ms 16328 KB Output is correct
25 Correct 13 ms 16328 KB Output is correct
26 Correct 12 ms 16328 KB Output is correct
27 Correct 13 ms 16328 KB Output is correct
28 Correct 13 ms 16328 KB Output is correct
29 Correct 13 ms 16328 KB Output is correct
30 Correct 13 ms 16328 KB Output is correct
31 Correct 12 ms 16328 KB Output is correct
32 Correct 13 ms 16328 KB Output is correct
33 Correct 12 ms 16328 KB Output is correct
34 Correct 12 ms 16328 KB Output is correct
35 Correct 12 ms 16328 KB Output is correct
36 Correct 13 ms 16328 KB Output is correct
37 Correct 12 ms 16328 KB Output is correct
38 Correct 12 ms 16328 KB Output is correct
39 Correct 156 ms 18164 KB Output is correct
40 Correct 212 ms 19476 KB Output is correct
41 Correct 103 ms 19476 KB Output is correct
42 Correct 100 ms 19476 KB Output is correct
43 Correct 78 ms 19476 KB Output is correct
44 Correct 261 ms 20220 KB Output is correct
45 Correct 255 ms 20220 KB Output is correct
46 Correct 260 ms 20220 KB Output is correct
47 Correct 229 ms 20220 KB Output is correct
48 Correct 238 ms 20220 KB Output is correct
49 Correct 447 ms 20220 KB Output is correct
50 Correct 464 ms 20220 KB Output is correct
51 Execution timed out 1570 ms 20224 KB Time limit exceeded
52 Halted 0 ms 0 KB -