Submission #279652

# Submission time Handle Problem Language Result Execution time Memory
279652 2020-08-22T09:09:55 Z arnold518 Exercise Deadlines (CCO20_day1problem2) C++14
25 / 25
141 ms 14148 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5;

int N, A[MAXN+10];
vector<int> P[MAXN+10];

int tree[MAXN+10];
void update(int i, int k) { for(; i<=N; i+=(i&-i)) tree[i]+=k; }
int query(int i) { int ret=0; for(; i>0; i-=(i&-i)) ret+=tree[i]; return ret; }

ll ans;

int main()
{
	scanf("%d", &N);
	for(int i=1; i<=N; i++) scanf("%d", &A[i]), P[A[i]].push_back(i);

	priority_queue<int> PQ;
	for(int i=1; i<=N; i++) update(i, 1);
	for(int i=N; i>=1; i--)
	{
		for(auto it : P[i]) PQ.push(it);	
		if(PQ.empty()) return !printf("-1\n");
		int now=PQ.top(); PQ.pop();
		update(N-now+1, -1);
		ans+=query(N-now+1);
	}
	printf("%lld\n", ans);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
Main.cpp:22:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |  for(int i=1; i<=N; i++) scanf("%d", &A[i]), P[A[i]].push_back(i);
      |                          ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5248 KB Output is correct
2 Correct 5 ms 5120 KB Output is correct
3 Correct 6 ms 5248 KB Output is correct
4 Correct 5 ms 5120 KB Output is correct
5 Correct 5 ms 5120 KB Output is correct
6 Correct 5 ms 5120 KB Output is correct
7 Correct 5 ms 5248 KB Output is correct
8 Correct 5 ms 5248 KB Output is correct
9 Correct 5 ms 5248 KB Output is correct
10 Correct 5 ms 5248 KB Output is correct
11 Correct 5 ms 5248 KB Output is correct
12 Correct 5 ms 5248 KB Output is correct
13 Correct 5 ms 5120 KB Output is correct
14 Correct 5 ms 5120 KB Output is correct
15 Correct 5 ms 5120 KB Output is correct
16 Correct 5 ms 5120 KB Output is correct
17 Correct 5 ms 5120 KB Output is correct
18 Correct 5 ms 5120 KB Output is correct
19 Correct 5 ms 5120 KB Output is correct
20 Correct 5 ms 5120 KB Output is correct
21 Correct 5 ms 5120 KB Output is correct
22 Correct 5 ms 5120 KB Output is correct
23 Correct 5 ms 5120 KB Output is correct
24 Correct 5 ms 5120 KB Output is correct
25 Correct 5 ms 5120 KB Output is correct
26 Correct 5 ms 5120 KB Output is correct
27 Correct 5 ms 5120 KB Output is correct
28 Correct 5 ms 5120 KB Output is correct
29 Correct 5 ms 5120 KB Output is correct
30 Correct 5 ms 5172 KB Output is correct
31 Correct 5 ms 5120 KB Output is correct
32 Correct 5 ms 5120 KB Output is correct
33 Correct 4 ms 5248 KB Output is correct
34 Correct 4 ms 5120 KB Output is correct
35 Correct 5 ms 5120 KB Output is correct
36 Correct 4 ms 5120 KB Output is correct
37 Correct 4 ms 5248 KB Output is correct
38 Correct 5 ms 5120 KB Output is correct
39 Correct 5 ms 5120 KB Output is correct
40 Correct 2 ms 5120 KB Output is correct
41 Correct 4 ms 5120 KB Output is correct
42 Correct 5 ms 5120 KB Output is correct
43 Correct 4 ms 5120 KB Output is correct
44 Correct 3 ms 4992 KB Output is correct
45 Correct 3 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5248 KB Output is correct
2 Correct 5 ms 5120 KB Output is correct
3 Correct 6 ms 5248 KB Output is correct
4 Correct 5 ms 5120 KB Output is correct
5 Correct 5 ms 5120 KB Output is correct
6 Correct 5 ms 5120 KB Output is correct
7 Correct 5 ms 5248 KB Output is correct
8 Correct 5 ms 5248 KB Output is correct
9 Correct 5 ms 5248 KB Output is correct
10 Correct 5 ms 5248 KB Output is correct
11 Correct 5 ms 5248 KB Output is correct
12 Correct 5 ms 5248 KB Output is correct
13 Correct 5 ms 5120 KB Output is correct
14 Correct 5 ms 5120 KB Output is correct
15 Correct 5 ms 5120 KB Output is correct
16 Correct 5 ms 5120 KB Output is correct
17 Correct 5 ms 5120 KB Output is correct
18 Correct 5 ms 5120 KB Output is correct
19 Correct 5 ms 5120 KB Output is correct
20 Correct 5 ms 5120 KB Output is correct
21 Correct 5 ms 5120 KB Output is correct
22 Correct 5 ms 5120 KB Output is correct
23 Correct 5 ms 5120 KB Output is correct
24 Correct 5 ms 5120 KB Output is correct
25 Correct 5 ms 5120 KB Output is correct
26 Correct 5 ms 5120 KB Output is correct
27 Correct 5 ms 5120 KB Output is correct
28 Correct 5 ms 5120 KB Output is correct
29 Correct 5 ms 5120 KB Output is correct
30 Correct 5 ms 5172 KB Output is correct
31 Correct 5 ms 5120 KB Output is correct
32 Correct 5 ms 5120 KB Output is correct
33 Correct 4 ms 5248 KB Output is correct
34 Correct 4 ms 5120 KB Output is correct
35 Correct 5 ms 5120 KB Output is correct
36 Correct 4 ms 5120 KB Output is correct
37 Correct 4 ms 5248 KB Output is correct
38 Correct 5 ms 5120 KB Output is correct
39 Correct 5 ms 5120 KB Output is correct
40 Correct 2 ms 5120 KB Output is correct
41 Correct 4 ms 5120 KB Output is correct
42 Correct 5 ms 5120 KB Output is correct
43 Correct 4 ms 5120 KB Output is correct
44 Correct 3 ms 4992 KB Output is correct
45 Correct 3 ms 4992 KB Output is correct
46 Correct 126 ms 11804 KB Output is correct
47 Correct 132 ms 11768 KB Output is correct
48 Correct 105 ms 11768 KB Output is correct
49 Correct 107 ms 11768 KB Output is correct
50 Correct 121 ms 11764 KB Output is correct
51 Correct 108 ms 11764 KB Output is correct
52 Correct 116 ms 14072 KB Output is correct
53 Correct 112 ms 14076 KB Output is correct
54 Correct 97 ms 14040 KB Output is correct
55 Correct 69 ms 14104 KB Output is correct
56 Correct 88 ms 14148 KB Output is correct
57 Correct 98 ms 14072 KB Output is correct
58 Correct 123 ms 11948 KB Output is correct
59 Correct 128 ms 11900 KB Output is correct
60 Correct 111 ms 11880 KB Output is correct
61 Correct 101 ms 11984 KB Output is correct
62 Correct 71 ms 11896 KB Output is correct
63 Correct 94 ms 11896 KB Output is correct
64 Correct 111 ms 11772 KB Output is correct
65 Correct 119 ms 11768 KB Output is correct
66 Correct 109 ms 11820 KB Output is correct
67 Correct 116 ms 11768 KB Output is correct
68 Correct 104 ms 11768 KB Output is correct
69 Correct 110 ms 11768 KB Output is correct
70 Correct 117 ms 11720 KB Output is correct
71 Correct 118 ms 11696 KB Output is correct
72 Correct 111 ms 11832 KB Output is correct
73 Correct 115 ms 11768 KB Output is correct
74 Correct 83 ms 11824 KB Output is correct
75 Correct 108 ms 11780 KB Output is correct
76 Correct 94 ms 11384 KB Output is correct
77 Correct 72 ms 10052 KB Output is correct
78 Correct 69 ms 14072 KB Output is correct
79 Correct 67 ms 11900 KB Output is correct
80 Correct 124 ms 11512 KB Output is correct
81 Correct 84 ms 10112 KB Output is correct
82 Correct 60 ms 14072 KB Output is correct
83 Correct 67 ms 11976 KB Output is correct
84 Correct 115 ms 11976 KB Output is correct
85 Correct 134 ms 11836 KB Output is correct
86 Correct 141 ms 11896 KB Output is correct
87 Correct 84 ms 11640 KB Output is correct
88 Correct 125 ms 11980 KB Output is correct