# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
320925 |
2020-11-10T09:13:38 Z |
egas |
Pilot (NOI19_pilot) |
C++14 |
|
1000 ms |
192504 KB |
#include <bits/stdc++.h>
using namespace std;
long LOG[1000005];
class SparseTable {
private:
long lookup[1000005][(long)log2l(1000005)+1];
void buildSparseTable(long arr[], long n) {
for (long i = 0; i < n; i++)
lookup[i][0] = arr[i];
for (long j = 1; (1 << j) <= n; j++) {
for (long i = 0; (i + (1 << j) - 1) < n; i++) {
if (lookup[i][j - 1] > lookup[i + (1 << (j - 1))][j - 1])
lookup[i][j] = lookup[i][j - 1];
else
lookup[i][j] = lookup[i + (1 << (j - 1))][j - 1];
}
}
}
public:
SparseTable(vector<long> &a) {
long num[a.size()];
for(long i = 0 ; i < a.size() ; i++) {
num[i]=a[i];
}
buildSparseTable(num,a.size());
}
long query(long L, long R) {
L--;
R--;
long j = LOG[R - L + 1];
if (lookup[L][j] >= lookup[R - (1 << j) + 1][j])
return lookup[L][j];
else
return lookup[R - (1 << j) + 1][j];
}
};
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long n;
cin >> n;
long m;
cin >> m;
vector<long> a(n);
for(long i = 0 ; i < n ; i++) {
cin >> a[i];
}
vector<long> b(m);
for(long i = 0 ; i < m ; i++) {
cin >> b[i];
}
for(int i=0;i<1000005;i++){
LOG[i]=(long)log2l(i);
}
vector<long> diff(1000005,0);
SparseTable ST(a);
long *last=new long[1000005];
for(long i = 0 ; i < a.size() ; i++) {
last[a[i]]=-1;
}
for(long i=0; i<n; i++) {
long ryt=0;
long l=i;
long r=a.size()-1;
while(l<=r) {
if(l==r) {
if(ST.query(i+1,l+1)<=a[i]) {
ryt=max(ryt,l);
}
break;
}
long m=(l+r)/2;
if(ST.query(i+1,m+1)>a[i]) {
r=m-1;
} else {
l=m+1;
ryt=max(ryt,m);
}
}
ryt=ryt-i+1;
ryt--;
long left=1e9;
l=last[a[i]]+1;
r=i;
while(l<=r) {
if(l==r) {
if(ST.query(l+1,i+1)<=a[i]) {
left=min(left,l);
}
break;
}
long m=(l+r)/2;
if(ST.query(m+1,i+1)>a[i]) {
l=m+1;
} else {
r=m-1;
left=min(left,m);
}
}
left=i-left;
last[a[i]]=i;
diff[a[i]]+=((left+1)*(ryt+1));
}
for(long i=1; i<diff.size(); i++) {
diff[i]+=diff[i-1];
}
for(long i = 0 ; i < b.size() ; i++) {
cout << diff[b[i]] << '\n';
}
return 0;
}
Compilation message
pilot.cpp: In constructor 'SparseTable::SparseTable(std::vector<long int>&)':
pilot.cpp:43:28: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(long i = 0 ; i < a.size() ; i++) {
| ~~^~~~~~~~~~
pilot.cpp: In function 'int32_t main()':
pilot.cpp:113:24: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for(long i = 0 ; i < a.size() ; i++) {
| ~~^~~~~~~~~~
pilot.cpp:205:20: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
205 | for(long i=1; i<diff.size(); i++) {
| ~^~~~~~~~~~~~
pilot.cpp:211:24: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
211 | for(long i = 0 ; i < b.size() ; i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
15972 KB |
Output is correct |
2 |
Correct |
58 ms |
16008 KB |
Output is correct |
3 |
Correct |
58 ms |
15972 KB |
Output is correct |
4 |
Correct |
65 ms |
15972 KB |
Output is correct |
5 |
Correct |
60 ms |
15968 KB |
Output is correct |
6 |
Correct |
64 ms |
15972 KB |
Output is correct |
7 |
Correct |
77 ms |
16100 KB |
Output is correct |
8 |
Correct |
58 ms |
15972 KB |
Output is correct |
9 |
Correct |
64 ms |
15972 KB |
Output is correct |
10 |
Correct |
59 ms |
15972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
15972 KB |
Output is correct |
2 |
Correct |
58 ms |
16008 KB |
Output is correct |
3 |
Correct |
58 ms |
15972 KB |
Output is correct |
4 |
Correct |
65 ms |
15972 KB |
Output is correct |
5 |
Correct |
60 ms |
15968 KB |
Output is correct |
6 |
Correct |
64 ms |
15972 KB |
Output is correct |
7 |
Correct |
77 ms |
16100 KB |
Output is correct |
8 |
Correct |
58 ms |
15972 KB |
Output is correct |
9 |
Correct |
64 ms |
15972 KB |
Output is correct |
10 |
Correct |
59 ms |
15972 KB |
Output is correct |
11 |
Correct |
59 ms |
16100 KB |
Output is correct |
12 |
Correct |
63 ms |
16100 KB |
Output is correct |
13 |
Correct |
58 ms |
15972 KB |
Output is correct |
14 |
Correct |
60 ms |
16228 KB |
Output is correct |
15 |
Correct |
58 ms |
15972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
15972 KB |
Output is correct |
2 |
Correct |
58 ms |
16008 KB |
Output is correct |
3 |
Correct |
58 ms |
15972 KB |
Output is correct |
4 |
Correct |
65 ms |
15972 KB |
Output is correct |
5 |
Correct |
60 ms |
15968 KB |
Output is correct |
6 |
Correct |
64 ms |
15972 KB |
Output is correct |
7 |
Correct |
77 ms |
16100 KB |
Output is correct |
8 |
Correct |
58 ms |
15972 KB |
Output is correct |
9 |
Correct |
64 ms |
15972 KB |
Output is correct |
10 |
Correct |
59 ms |
15972 KB |
Output is correct |
11 |
Correct |
59 ms |
16100 KB |
Output is correct |
12 |
Correct |
63 ms |
16100 KB |
Output is correct |
13 |
Correct |
58 ms |
15972 KB |
Output is correct |
14 |
Correct |
60 ms |
16228 KB |
Output is correct |
15 |
Correct |
58 ms |
15972 KB |
Output is correct |
16 |
Correct |
59 ms |
16100 KB |
Output is correct |
17 |
Correct |
60 ms |
16872 KB |
Output is correct |
18 |
Correct |
59 ms |
16100 KB |
Output is correct |
19 |
Correct |
58 ms |
16740 KB |
Output is correct |
20 |
Correct |
59 ms |
16100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
15972 KB |
Output is correct |
2 |
Correct |
58 ms |
16008 KB |
Output is correct |
3 |
Correct |
58 ms |
15972 KB |
Output is correct |
4 |
Correct |
65 ms |
15972 KB |
Output is correct |
5 |
Correct |
60 ms |
15968 KB |
Output is correct |
6 |
Correct |
64 ms |
15972 KB |
Output is correct |
7 |
Correct |
77 ms |
16100 KB |
Output is correct |
8 |
Correct |
58 ms |
15972 KB |
Output is correct |
9 |
Correct |
64 ms |
15972 KB |
Output is correct |
10 |
Correct |
59 ms |
15972 KB |
Output is correct |
11 |
Correct |
59 ms |
16100 KB |
Output is correct |
12 |
Correct |
63 ms |
16100 KB |
Output is correct |
13 |
Correct |
58 ms |
15972 KB |
Output is correct |
14 |
Correct |
60 ms |
16228 KB |
Output is correct |
15 |
Correct |
58 ms |
15972 KB |
Output is correct |
16 |
Correct |
59 ms |
16100 KB |
Output is correct |
17 |
Correct |
60 ms |
16872 KB |
Output is correct |
18 |
Correct |
59 ms |
16100 KB |
Output is correct |
19 |
Correct |
58 ms |
16740 KB |
Output is correct |
20 |
Correct |
59 ms |
16100 KB |
Output is correct |
21 |
Correct |
59 ms |
16232 KB |
Output is correct |
22 |
Correct |
60 ms |
19300 KB |
Output is correct |
23 |
Correct |
60 ms |
16228 KB |
Output is correct |
24 |
Correct |
60 ms |
19300 KB |
Output is correct |
25 |
Correct |
61 ms |
16228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
33380 KB |
Output is correct |
2 |
Correct |
154 ms |
40676 KB |
Output is correct |
3 |
Correct |
128 ms |
32952 KB |
Output is correct |
4 |
Correct |
138 ms |
39396 KB |
Output is correct |
5 |
Correct |
137 ms |
32612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
34532 KB |
Output is correct |
2 |
Correct |
143 ms |
34532 KB |
Output is correct |
3 |
Correct |
143 ms |
34148 KB |
Output is correct |
4 |
Correct |
148 ms |
35032 KB |
Output is correct |
5 |
Correct |
144 ms |
34148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
41956 KB |
Output is correct |
2 |
Correct |
146 ms |
41572 KB |
Output is correct |
3 |
Correct |
147 ms |
41188 KB |
Output is correct |
4 |
Correct |
155 ms |
42664 KB |
Output is correct |
5 |
Correct |
158 ms |
41828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
15972 KB |
Output is correct |
2 |
Correct |
58 ms |
16008 KB |
Output is correct |
3 |
Correct |
58 ms |
15972 KB |
Output is correct |
4 |
Correct |
65 ms |
15972 KB |
Output is correct |
5 |
Correct |
60 ms |
15968 KB |
Output is correct |
6 |
Correct |
64 ms |
15972 KB |
Output is correct |
7 |
Correct |
77 ms |
16100 KB |
Output is correct |
8 |
Correct |
58 ms |
15972 KB |
Output is correct |
9 |
Correct |
64 ms |
15972 KB |
Output is correct |
10 |
Correct |
59 ms |
15972 KB |
Output is correct |
11 |
Correct |
134 ms |
33380 KB |
Output is correct |
12 |
Correct |
154 ms |
40676 KB |
Output is correct |
13 |
Correct |
128 ms |
32952 KB |
Output is correct |
14 |
Correct |
138 ms |
39396 KB |
Output is correct |
15 |
Correct |
137 ms |
32612 KB |
Output is correct |
16 |
Correct |
132 ms |
32612 KB |
Output is correct |
17 |
Correct |
149 ms |
40676 KB |
Output is correct |
18 |
Correct |
151 ms |
40932 KB |
Output is correct |
19 |
Correct |
129 ms |
32484 KB |
Output is correct |
20 |
Correct |
148 ms |
40420 KB |
Output is correct |
21 |
Correct |
131 ms |
32484 KB |
Output is correct |
22 |
Correct |
149 ms |
39908 KB |
Output is correct |
23 |
Correct |
133 ms |
33892 KB |
Output is correct |
24 |
Correct |
141 ms |
39780 KB |
Output is correct |
25 |
Correct |
140 ms |
33380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
15972 KB |
Output is correct |
2 |
Correct |
58 ms |
16008 KB |
Output is correct |
3 |
Correct |
58 ms |
15972 KB |
Output is correct |
4 |
Correct |
65 ms |
15972 KB |
Output is correct |
5 |
Correct |
60 ms |
15968 KB |
Output is correct |
6 |
Correct |
64 ms |
15972 KB |
Output is correct |
7 |
Correct |
77 ms |
16100 KB |
Output is correct |
8 |
Correct |
58 ms |
15972 KB |
Output is correct |
9 |
Correct |
64 ms |
15972 KB |
Output is correct |
10 |
Correct |
59 ms |
15972 KB |
Output is correct |
11 |
Correct |
59 ms |
16100 KB |
Output is correct |
12 |
Correct |
63 ms |
16100 KB |
Output is correct |
13 |
Correct |
58 ms |
15972 KB |
Output is correct |
14 |
Correct |
60 ms |
16228 KB |
Output is correct |
15 |
Correct |
58 ms |
15972 KB |
Output is correct |
16 |
Correct |
59 ms |
16100 KB |
Output is correct |
17 |
Correct |
60 ms |
16872 KB |
Output is correct |
18 |
Correct |
59 ms |
16100 KB |
Output is correct |
19 |
Correct |
58 ms |
16740 KB |
Output is correct |
20 |
Correct |
59 ms |
16100 KB |
Output is correct |
21 |
Correct |
59 ms |
16232 KB |
Output is correct |
22 |
Correct |
60 ms |
19300 KB |
Output is correct |
23 |
Correct |
60 ms |
16228 KB |
Output is correct |
24 |
Correct |
60 ms |
19300 KB |
Output is correct |
25 |
Correct |
61 ms |
16228 KB |
Output is correct |
26 |
Correct |
134 ms |
33380 KB |
Output is correct |
27 |
Correct |
154 ms |
40676 KB |
Output is correct |
28 |
Correct |
128 ms |
32952 KB |
Output is correct |
29 |
Correct |
138 ms |
39396 KB |
Output is correct |
30 |
Correct |
137 ms |
32612 KB |
Output is correct |
31 |
Correct |
145 ms |
34532 KB |
Output is correct |
32 |
Correct |
143 ms |
34532 KB |
Output is correct |
33 |
Correct |
143 ms |
34148 KB |
Output is correct |
34 |
Correct |
148 ms |
35032 KB |
Output is correct |
35 |
Correct |
144 ms |
34148 KB |
Output is correct |
36 |
Correct |
154 ms |
41956 KB |
Output is correct |
37 |
Correct |
146 ms |
41572 KB |
Output is correct |
38 |
Correct |
147 ms |
41188 KB |
Output is correct |
39 |
Correct |
155 ms |
42664 KB |
Output is correct |
40 |
Correct |
158 ms |
41828 KB |
Output is correct |
41 |
Correct |
132 ms |
32612 KB |
Output is correct |
42 |
Correct |
149 ms |
40676 KB |
Output is correct |
43 |
Correct |
151 ms |
40932 KB |
Output is correct |
44 |
Correct |
129 ms |
32484 KB |
Output is correct |
45 |
Correct |
148 ms |
40420 KB |
Output is correct |
46 |
Correct |
131 ms |
32484 KB |
Output is correct |
47 |
Correct |
149 ms |
39908 KB |
Output is correct |
48 |
Correct |
133 ms |
33892 KB |
Output is correct |
49 |
Correct |
141 ms |
39780 KB |
Output is correct |
50 |
Correct |
140 ms |
33380 KB |
Output is correct |
51 |
Correct |
161 ms |
34916 KB |
Output is correct |
52 |
Correct |
180 ms |
41444 KB |
Output is correct |
53 |
Correct |
162 ms |
35172 KB |
Output is correct |
54 |
Correct |
181 ms |
41444 KB |
Output is correct |
55 |
Correct |
173 ms |
35336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
15972 KB |
Output is correct |
2 |
Correct |
58 ms |
16008 KB |
Output is correct |
3 |
Correct |
58 ms |
15972 KB |
Output is correct |
4 |
Correct |
65 ms |
15972 KB |
Output is correct |
5 |
Correct |
60 ms |
15968 KB |
Output is correct |
6 |
Correct |
64 ms |
15972 KB |
Output is correct |
7 |
Correct |
77 ms |
16100 KB |
Output is correct |
8 |
Correct |
58 ms |
15972 KB |
Output is correct |
9 |
Correct |
64 ms |
15972 KB |
Output is correct |
10 |
Correct |
59 ms |
15972 KB |
Output is correct |
11 |
Correct |
59 ms |
16100 KB |
Output is correct |
12 |
Correct |
63 ms |
16100 KB |
Output is correct |
13 |
Correct |
58 ms |
15972 KB |
Output is correct |
14 |
Correct |
60 ms |
16228 KB |
Output is correct |
15 |
Correct |
58 ms |
15972 KB |
Output is correct |
16 |
Correct |
59 ms |
16100 KB |
Output is correct |
17 |
Correct |
60 ms |
16872 KB |
Output is correct |
18 |
Correct |
59 ms |
16100 KB |
Output is correct |
19 |
Correct |
58 ms |
16740 KB |
Output is correct |
20 |
Correct |
59 ms |
16100 KB |
Output is correct |
21 |
Correct |
59 ms |
16232 KB |
Output is correct |
22 |
Correct |
60 ms |
19300 KB |
Output is correct |
23 |
Correct |
60 ms |
16228 KB |
Output is correct |
24 |
Correct |
60 ms |
19300 KB |
Output is correct |
25 |
Correct |
61 ms |
16228 KB |
Output is correct |
26 |
Correct |
134 ms |
33380 KB |
Output is correct |
27 |
Correct |
154 ms |
40676 KB |
Output is correct |
28 |
Correct |
128 ms |
32952 KB |
Output is correct |
29 |
Correct |
138 ms |
39396 KB |
Output is correct |
30 |
Correct |
137 ms |
32612 KB |
Output is correct |
31 |
Correct |
145 ms |
34532 KB |
Output is correct |
32 |
Correct |
143 ms |
34532 KB |
Output is correct |
33 |
Correct |
143 ms |
34148 KB |
Output is correct |
34 |
Correct |
148 ms |
35032 KB |
Output is correct |
35 |
Correct |
144 ms |
34148 KB |
Output is correct |
36 |
Correct |
154 ms |
41956 KB |
Output is correct |
37 |
Correct |
146 ms |
41572 KB |
Output is correct |
38 |
Correct |
147 ms |
41188 KB |
Output is correct |
39 |
Correct |
155 ms |
42664 KB |
Output is correct |
40 |
Correct |
158 ms |
41828 KB |
Output is correct |
41 |
Correct |
132 ms |
32612 KB |
Output is correct |
42 |
Correct |
149 ms |
40676 KB |
Output is correct |
43 |
Correct |
151 ms |
40932 KB |
Output is correct |
44 |
Correct |
129 ms |
32484 KB |
Output is correct |
45 |
Correct |
148 ms |
40420 KB |
Output is correct |
46 |
Correct |
131 ms |
32484 KB |
Output is correct |
47 |
Correct |
149 ms |
39908 KB |
Output is correct |
48 |
Correct |
133 ms |
33892 KB |
Output is correct |
49 |
Correct |
141 ms |
39780 KB |
Output is correct |
50 |
Correct |
140 ms |
33380 KB |
Output is correct |
51 |
Correct |
161 ms |
34916 KB |
Output is correct |
52 |
Correct |
180 ms |
41444 KB |
Output is correct |
53 |
Correct |
162 ms |
35172 KB |
Output is correct |
54 |
Correct |
181 ms |
41444 KB |
Output is correct |
55 |
Correct |
173 ms |
35336 KB |
Output is correct |
56 |
Execution timed out |
1098 ms |
192504 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |