Submission #91205

# Submission time Handle Problem Language Result Execution time Memory
91205 2018-12-26T14:25:22 Z davitmarg Money (IZhO17_money) C++17
100 / 100
612 ms 22100 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 * 1000001 + 2; i++)
		t[i] = mod;
	update(1, 0, 1000001, 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, 1000001, st.top());
				st.pop();
			}
			it = query(1, 0, 1000001, l + 1, 1000001);
		}
		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);
   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 15992 KB Output is correct
2 Correct 14 ms 16124 KB Output is correct
3 Correct 15 ms 16124 KB Output is correct
4 Correct 14 ms 16124 KB Output is correct
5 Correct 14 ms 16124 KB Output is correct
6 Correct 14 ms 16124 KB Output is correct
7 Correct 13 ms 16176 KB Output is correct
8 Correct 13 ms 16176 KB Output is correct
9 Correct 14 ms 16344 KB Output is correct
10 Correct 14 ms 16344 KB Output is correct
11 Correct 14 ms 16344 KB Output is correct
12 Correct 14 ms 16344 KB Output is correct
13 Correct 14 ms 16344 KB Output is correct
14 Correct 14 ms 16344 KB Output is correct
15 Correct 15 ms 16344 KB Output is correct
16 Correct 14 ms 16344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 15992 KB Output is correct
2 Correct 14 ms 16124 KB Output is correct
3 Correct 15 ms 16124 KB Output is correct
4 Correct 14 ms 16124 KB Output is correct
5 Correct 14 ms 16124 KB Output is correct
6 Correct 14 ms 16124 KB Output is correct
7 Correct 13 ms 16176 KB Output is correct
8 Correct 13 ms 16176 KB Output is correct
9 Correct 14 ms 16344 KB Output is correct
10 Correct 14 ms 16344 KB Output is correct
11 Correct 14 ms 16344 KB Output is correct
12 Correct 14 ms 16344 KB Output is correct
13 Correct 14 ms 16344 KB Output is correct
14 Correct 14 ms 16344 KB Output is correct
15 Correct 15 ms 16344 KB Output is correct
16 Correct 14 ms 16344 KB Output is correct
17 Correct 14 ms 16344 KB Output is correct
18 Correct 14 ms 16344 KB Output is correct
19 Correct 14 ms 16344 KB Output is correct
20 Correct 13 ms 16344 KB Output is correct
21 Correct 16 ms 16344 KB Output is correct
22 Correct 15 ms 16344 KB Output is correct
23 Correct 15 ms 16344 KB Output is correct
24 Correct 15 ms 16344 KB Output is correct
25 Correct 15 ms 16344 KB Output is correct
26 Correct 13 ms 16344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 15992 KB Output is correct
2 Correct 14 ms 16124 KB Output is correct
3 Correct 15 ms 16124 KB Output is correct
4 Correct 14 ms 16124 KB Output is correct
5 Correct 14 ms 16124 KB Output is correct
6 Correct 14 ms 16124 KB Output is correct
7 Correct 13 ms 16176 KB Output is correct
8 Correct 13 ms 16176 KB Output is correct
9 Correct 14 ms 16344 KB Output is correct
10 Correct 14 ms 16344 KB Output is correct
11 Correct 14 ms 16344 KB Output is correct
12 Correct 14 ms 16344 KB Output is correct
13 Correct 14 ms 16344 KB Output is correct
14 Correct 14 ms 16344 KB Output is correct
15 Correct 15 ms 16344 KB Output is correct
16 Correct 14 ms 16344 KB Output is correct
17 Correct 14 ms 16344 KB Output is correct
18 Correct 14 ms 16344 KB Output is correct
19 Correct 14 ms 16344 KB Output is correct
20 Correct 13 ms 16344 KB Output is correct
21 Correct 16 ms 16344 KB Output is correct
22 Correct 15 ms 16344 KB Output is correct
23 Correct 15 ms 16344 KB Output is correct
24 Correct 15 ms 16344 KB Output is correct
25 Correct 15 ms 16344 KB Output is correct
26 Correct 13 ms 16344 KB Output is correct
27 Correct 14 ms 16344 KB Output is correct
28 Correct 14 ms 16344 KB Output is correct
29 Correct 14 ms 16344 KB Output is correct
30 Correct 15 ms 16344 KB Output is correct
31 Correct 15 ms 16344 KB Output is correct
32 Correct 15 ms 16344 KB Output is correct
33 Correct 14 ms 16344 KB Output is correct
34 Correct 15 ms 16348 KB Output is correct
35 Correct 14 ms 16444 KB Output is correct
36 Correct 15 ms 16444 KB Output is correct
37 Correct 15 ms 16488 KB Output is correct
38 Correct 15 ms 16488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 15992 KB Output is correct
2 Correct 14 ms 16124 KB Output is correct
3 Correct 15 ms 16124 KB Output is correct
4 Correct 14 ms 16124 KB Output is correct
5 Correct 14 ms 16124 KB Output is correct
6 Correct 14 ms 16124 KB Output is correct
7 Correct 13 ms 16176 KB Output is correct
8 Correct 13 ms 16176 KB Output is correct
9 Correct 14 ms 16344 KB Output is correct
10 Correct 14 ms 16344 KB Output is correct
11 Correct 14 ms 16344 KB Output is correct
12 Correct 14 ms 16344 KB Output is correct
13 Correct 14 ms 16344 KB Output is correct
14 Correct 14 ms 16344 KB Output is correct
15 Correct 15 ms 16344 KB Output is correct
16 Correct 14 ms 16344 KB Output is correct
17 Correct 14 ms 16344 KB Output is correct
18 Correct 14 ms 16344 KB Output is correct
19 Correct 14 ms 16344 KB Output is correct
20 Correct 13 ms 16344 KB Output is correct
21 Correct 16 ms 16344 KB Output is correct
22 Correct 15 ms 16344 KB Output is correct
23 Correct 15 ms 16344 KB Output is correct
24 Correct 15 ms 16344 KB Output is correct
25 Correct 15 ms 16344 KB Output is correct
26 Correct 13 ms 16344 KB Output is correct
27 Correct 14 ms 16344 KB Output is correct
28 Correct 14 ms 16344 KB Output is correct
29 Correct 14 ms 16344 KB Output is correct
30 Correct 15 ms 16344 KB Output is correct
31 Correct 15 ms 16344 KB Output is correct
32 Correct 15 ms 16344 KB Output is correct
33 Correct 14 ms 16344 KB Output is correct
34 Correct 15 ms 16348 KB Output is correct
35 Correct 14 ms 16444 KB Output is correct
36 Correct 15 ms 16444 KB Output is correct
37 Correct 15 ms 16488 KB Output is correct
38 Correct 15 ms 16488 KB Output is correct
39 Correct 127 ms 19056 KB Output is correct
40 Correct 220 ms 20308 KB Output is correct
41 Correct 101 ms 20308 KB Output is correct
42 Correct 101 ms 20308 KB Output is correct
43 Correct 77 ms 20308 KB Output is correct
44 Correct 262 ms 21272 KB Output is correct
45 Correct 279 ms 21272 KB Output is correct
46 Correct 260 ms 21272 KB Output is correct
47 Correct 228 ms 21932 KB Output is correct
48 Correct 237 ms 21972 KB Output is correct
49 Correct 457 ms 21984 KB Output is correct
50 Correct 453 ms 21984 KB Output is correct
51 Correct 449 ms 21984 KB Output is correct
52 Correct 428 ms 22096 KB Output is correct
53 Correct 434 ms 22096 KB Output is correct
54 Correct 445 ms 22096 KB Output is correct
55 Correct 607 ms 22096 KB Output is correct
56 Correct 612 ms 22096 KB Output is correct
57 Correct 605 ms 22096 KB Output is correct
58 Correct 574 ms 22096 KB Output is correct
59 Correct 590 ms 22100 KB Output is correct
60 Correct 596 ms 22100 KB Output is correct
61 Correct 603 ms 22100 KB Output is correct
62 Correct 588 ms 22100 KB Output is correct