답안 #51341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51341 2018-06-17T13:55:33 Z Nicksechko Money (IZhO17_money) C++11
100 / 100
975 ms 57192 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
int ans = 0;
bitset<1000502> s;
ll a[1000500];
int t[4000500];
int p[1000500];
int sz = 1000001;

inline void upd(int v, int tl, int tr, int p)
{
	if(tl == tr)
	{
		t[v] = 1;
		return;
	}
	int tm = tl + tr >> 1;
	if(p <= tm) upd(v << 1, tl, tm, p);
	else upd((v << 1) + 1, tm + 1, tr, p);	
	t[v] = t[v << 1] + t[(v << 1) + 1];
}

inline int get(int v, int tl , int tr, int l, int r)
{
	if(l > r) return 0;
	if(tl == l && tr == r)
		return t[v];
	int tm = tl + tr >> 1;
	return get((v << 1), tl, tm, l, min(r, tm)) + get((v << 1) + 1, tm + 1, tr, max(tm + 1, l), r);
}

inline int fnd(int v, int tl, int tr, int need)
{
	if(tl == tr)
		return tl;
	int tm = tl + tr >> 1;
	if(need <= t[(v << 1)])
		return fnd((v << 1), tl, tm, need);
	else
		return fnd((v << 1) + 1, tm + 1, tr, need- t[(v << 1)]);
}

int main()
{
//	freopen("money.in", "r", stdin);
//	freopen("money.out", "w", stdout);
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%lld", a + i);
	upd(1, 1, sz, sz);
	for(int i = 1; i <= n;)
	{
		int f = get(1, 1, sz, 1, a[i]) + 1;
		int nxt = fnd(1, 1, sz, f);
		ll last = a[i];
		while(i <= n && a[i] <= nxt && a[i] >= last)
			upd(1, 1, sz, a[i]), last = a[i], i++;
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

money.cpp: In function 'void upd(int, int, int, int)':
money.cpp:22:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int tm = tl + tr >> 1;
           ~~~^~~~
money.cpp: In function 'int get(int, int, int, int, int)':
money.cpp:33:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int tm = tl + tr >> 1;
           ~~~^~~~
money.cpp: In function 'int fnd(int, int, int, int)':
money.cpp:41:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int tm = tl + tr >> 1;
           ~~~^~~~
money.cpp: In function 'int main()':
money.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
money.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", a + i);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 2 ms 628 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 3 ms 680 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 3 ms 816 KB Output is correct
13 Correct 2 ms 816 KB Output is correct
14 Correct 3 ms 816 KB Output is correct
15 Correct 2 ms 816 KB Output is correct
16 Correct 3 ms 880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 2 ms 628 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 3 ms 680 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 3 ms 816 KB Output is correct
13 Correct 2 ms 816 KB Output is correct
14 Correct 3 ms 816 KB Output is correct
15 Correct 2 ms 816 KB Output is correct
16 Correct 3 ms 880 KB Output is correct
17 Correct 2 ms 880 KB Output is correct
18 Correct 2 ms 884 KB Output is correct
19 Correct 2 ms 884 KB Output is correct
20 Correct 2 ms 884 KB Output is correct
21 Correct 2 ms 884 KB Output is correct
22 Correct 2 ms 884 KB Output is correct
23 Correct 2 ms 884 KB Output is correct
24 Correct 3 ms 884 KB Output is correct
25 Correct 2 ms 1016 KB Output is correct
26 Correct 2 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 2 ms 628 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 3 ms 680 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 3 ms 816 KB Output is correct
13 Correct 2 ms 816 KB Output is correct
14 Correct 3 ms 816 KB Output is correct
15 Correct 2 ms 816 KB Output is correct
16 Correct 3 ms 880 KB Output is correct
17 Correct 2 ms 880 KB Output is correct
18 Correct 2 ms 884 KB Output is correct
19 Correct 2 ms 884 KB Output is correct
20 Correct 2 ms 884 KB Output is correct
21 Correct 2 ms 884 KB Output is correct
22 Correct 2 ms 884 KB Output is correct
23 Correct 2 ms 884 KB Output is correct
24 Correct 3 ms 884 KB Output is correct
25 Correct 2 ms 1016 KB Output is correct
26 Correct 2 ms 1016 KB Output is correct
27 Correct 2 ms 1016 KB Output is correct
28 Correct 2 ms 1016 KB Output is correct
29 Correct 2 ms 1016 KB Output is correct
30 Correct 3 ms 1016 KB Output is correct
31 Correct 2 ms 1016 KB Output is correct
32 Correct 2 ms 1016 KB Output is correct
33 Correct 3 ms 1016 KB Output is correct
34 Correct 3 ms 1016 KB Output is correct
35 Correct 2 ms 1016 KB Output is correct
36 Correct 2 ms 1016 KB Output is correct
37 Correct 5 ms 3084 KB Output is correct
38 Correct 4 ms 3084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 2 ms 628 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 3 ms 680 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 3 ms 816 KB Output is correct
13 Correct 2 ms 816 KB Output is correct
14 Correct 3 ms 816 KB Output is correct
15 Correct 2 ms 816 KB Output is correct
16 Correct 3 ms 880 KB Output is correct
17 Correct 2 ms 880 KB Output is correct
18 Correct 2 ms 884 KB Output is correct
19 Correct 2 ms 884 KB Output is correct
20 Correct 2 ms 884 KB Output is correct
21 Correct 2 ms 884 KB Output is correct
22 Correct 2 ms 884 KB Output is correct
23 Correct 2 ms 884 KB Output is correct
24 Correct 3 ms 884 KB Output is correct
25 Correct 2 ms 1016 KB Output is correct
26 Correct 2 ms 1016 KB Output is correct
27 Correct 2 ms 1016 KB Output is correct
28 Correct 2 ms 1016 KB Output is correct
29 Correct 2 ms 1016 KB Output is correct
30 Correct 3 ms 1016 KB Output is correct
31 Correct 2 ms 1016 KB Output is correct
32 Correct 2 ms 1016 KB Output is correct
33 Correct 3 ms 1016 KB Output is correct
34 Correct 3 ms 1016 KB Output is correct
35 Correct 2 ms 1016 KB Output is correct
36 Correct 2 ms 1016 KB Output is correct
37 Correct 5 ms 3084 KB Output is correct
38 Correct 4 ms 3084 KB Output is correct
39 Correct 151 ms 4748 KB Output is correct
40 Correct 260 ms 7180 KB Output is correct
41 Correct 113 ms 7180 KB Output is correct
42 Correct 135 ms 7180 KB Output is correct
43 Correct 88 ms 7180 KB Output is correct
44 Correct 332 ms 8844 KB Output is correct
45 Correct 331 ms 8844 KB Output is correct
46 Correct 343 ms 8972 KB Output is correct
47 Correct 276 ms 8972 KB Output is correct
48 Correct 309 ms 8972 KB Output is correct
49 Correct 565 ms 16704 KB Output is correct
50 Correct 645 ms 16760 KB Output is correct
51 Correct 643 ms 16808 KB Output is correct
52 Correct 628 ms 16808 KB Output is correct
53 Correct 684 ms 16808 KB Output is correct
54 Correct 587 ms 16808 KB Output is correct
55 Correct 867 ms 16904 KB Output is correct
56 Correct 893 ms 16904 KB Output is correct
57 Correct 881 ms 23564 KB Output is correct
58 Correct 975 ms 30244 KB Output is correct
59 Correct 923 ms 37116 KB Output is correct
60 Correct 842 ms 43716 KB Output is correct
61 Correct 881 ms 50460 KB Output is correct
62 Correct 847 ms 57192 KB Output is correct