# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
753108 |
2023-06-04T15:39:02 Z |
minhnhatnoe |
Pilot (NOI19_pilot) |
C++14 |
|
1000 ms |
47056 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cresult = 0;
set<pair<int, int>> s;
ll calcpair(ll len){
return len*(len+1)/2;
}
ll calcpair(pair<int, int> se){
return calcpair(se.second - se.first + 1);
}
void insert(int pos){
cresult += calcpair(1);
set<pair<int, int>>::iterator it1, it2;
it2 = s.emplace(pos, pos).first;
if (it2 != s.begin()){
it1 = prev(it2);
if (it1->second+1 == it2->first){
cresult -= calcpair(*it1) + calcpair(*it2);
pair<int, int> nxt(it1->first, it2->second);
s.erase(it1), s.erase(it2);
it1 = s.insert(nxt).first;
cresult += calcpair(nxt);
}
else it1 = it2;
}
else it1 = it2;
it2 = next(it1);
if (it2 != s.end()){
if (it1->second+1 == it2->first){
cresult -= calcpair(*it1) + calcpair(*it2);
pair<int, int> nxt(it1->first, it2->second);
s.erase(it1), s.erase(it2);
it1 = s.insert(nxt).first;
cresult += calcpair(nxt);
}
}
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n, q; cin >> n >> q;
vector<pair<int, int>> a(n), b(q);
for (int i=0; i<n; i++){
cin >> a[i].first;
a[i].second = i;
}
for (int i=0; i<q; i++){
cin >> b[i].first;
b[i].second = i;
}
vector<ll> result(q);
sort(a.begin(), a.end()), sort(b.begin(), b.end());
for (int i=0, aptr=0; i<q; i++){
while (aptr < a.size() && a[aptr].first <= b[i].first){
insert(a[aptr++].second);
}
result[b[i].second] = cresult;
}
for (int i=0; i<q; i++){
cout << result[i] << "\n";
}
}
Compilation message
pilot.cpp: In function 'int main()':
pilot.cpp:56:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | while (aptr < a.size() && a[aptr].first <= b[i].first){
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
2664 KB |
Output is correct |
2 |
Correct |
60 ms |
2788 KB |
Output is correct |
3 |
Correct |
57 ms |
2620 KB |
Output is correct |
4 |
Correct |
49 ms |
2672 KB |
Output is correct |
5 |
Correct |
56 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
4556 KB |
Output is correct |
2 |
Correct |
44 ms |
4608 KB |
Output is correct |
3 |
Correct |
43 ms |
4552 KB |
Output is correct |
4 |
Correct |
50 ms |
4684 KB |
Output is correct |
5 |
Correct |
45 ms |
4544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
4664 KB |
Output is correct |
2 |
Correct |
43 ms |
4708 KB |
Output is correct |
3 |
Correct |
44 ms |
4812 KB |
Output is correct |
4 |
Correct |
43 ms |
4752 KB |
Output is correct |
5 |
Correct |
46 ms |
4904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
54 ms |
2664 KB |
Output is correct |
12 |
Correct |
60 ms |
2788 KB |
Output is correct |
13 |
Correct |
57 ms |
2620 KB |
Output is correct |
14 |
Correct |
49 ms |
2672 KB |
Output is correct |
15 |
Correct |
56 ms |
2636 KB |
Output is correct |
16 |
Correct |
40 ms |
2648 KB |
Output is correct |
17 |
Correct |
32 ms |
2716 KB |
Output is correct |
18 |
Correct |
21 ms |
2112 KB |
Output is correct |
19 |
Correct |
19 ms |
1836 KB |
Output is correct |
20 |
Correct |
33 ms |
2744 KB |
Output is correct |
21 |
Correct |
65 ms |
2564 KB |
Output is correct |
22 |
Correct |
33 ms |
2700 KB |
Output is correct |
23 |
Correct |
25 ms |
2496 KB |
Output is correct |
24 |
Correct |
20 ms |
2172 KB |
Output is correct |
25 |
Correct |
34 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
54 ms |
2664 KB |
Output is correct |
27 |
Correct |
60 ms |
2788 KB |
Output is correct |
28 |
Correct |
57 ms |
2620 KB |
Output is correct |
29 |
Correct |
49 ms |
2672 KB |
Output is correct |
30 |
Correct |
56 ms |
2636 KB |
Output is correct |
31 |
Correct |
41 ms |
4556 KB |
Output is correct |
32 |
Correct |
44 ms |
4608 KB |
Output is correct |
33 |
Correct |
43 ms |
4552 KB |
Output is correct |
34 |
Correct |
50 ms |
4684 KB |
Output is correct |
35 |
Correct |
45 ms |
4544 KB |
Output is correct |
36 |
Correct |
46 ms |
4664 KB |
Output is correct |
37 |
Correct |
43 ms |
4708 KB |
Output is correct |
38 |
Correct |
44 ms |
4812 KB |
Output is correct |
39 |
Correct |
43 ms |
4752 KB |
Output is correct |
40 |
Correct |
46 ms |
4904 KB |
Output is correct |
41 |
Correct |
40 ms |
2648 KB |
Output is correct |
42 |
Correct |
32 ms |
2716 KB |
Output is correct |
43 |
Correct |
21 ms |
2112 KB |
Output is correct |
44 |
Correct |
19 ms |
1836 KB |
Output is correct |
45 |
Correct |
33 ms |
2744 KB |
Output is correct |
46 |
Correct |
65 ms |
2564 KB |
Output is correct |
47 |
Correct |
33 ms |
2700 KB |
Output is correct |
48 |
Correct |
25 ms |
2496 KB |
Output is correct |
49 |
Correct |
20 ms |
2172 KB |
Output is correct |
50 |
Correct |
34 ms |
2644 KB |
Output is correct |
51 |
Correct |
83 ms |
5684 KB |
Output is correct |
52 |
Correct |
86 ms |
5500 KB |
Output is correct |
53 |
Correct |
81 ms |
5580 KB |
Output is correct |
54 |
Correct |
82 ms |
5508 KB |
Output is correct |
55 |
Correct |
79 ms |
5636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
54 ms |
2664 KB |
Output is correct |
27 |
Correct |
60 ms |
2788 KB |
Output is correct |
28 |
Correct |
57 ms |
2620 KB |
Output is correct |
29 |
Correct |
49 ms |
2672 KB |
Output is correct |
30 |
Correct |
56 ms |
2636 KB |
Output is correct |
31 |
Correct |
41 ms |
4556 KB |
Output is correct |
32 |
Correct |
44 ms |
4608 KB |
Output is correct |
33 |
Correct |
43 ms |
4552 KB |
Output is correct |
34 |
Correct |
50 ms |
4684 KB |
Output is correct |
35 |
Correct |
45 ms |
4544 KB |
Output is correct |
36 |
Correct |
46 ms |
4664 KB |
Output is correct |
37 |
Correct |
43 ms |
4708 KB |
Output is correct |
38 |
Correct |
44 ms |
4812 KB |
Output is correct |
39 |
Correct |
43 ms |
4752 KB |
Output is correct |
40 |
Correct |
46 ms |
4904 KB |
Output is correct |
41 |
Correct |
40 ms |
2648 KB |
Output is correct |
42 |
Correct |
32 ms |
2716 KB |
Output is correct |
43 |
Correct |
21 ms |
2112 KB |
Output is correct |
44 |
Correct |
19 ms |
1836 KB |
Output is correct |
45 |
Correct |
33 ms |
2744 KB |
Output is correct |
46 |
Correct |
65 ms |
2564 KB |
Output is correct |
47 |
Correct |
33 ms |
2700 KB |
Output is correct |
48 |
Correct |
25 ms |
2496 KB |
Output is correct |
49 |
Correct |
20 ms |
2172 KB |
Output is correct |
50 |
Correct |
34 ms |
2644 KB |
Output is correct |
51 |
Correct |
83 ms |
5684 KB |
Output is correct |
52 |
Correct |
86 ms |
5500 KB |
Output is correct |
53 |
Correct |
81 ms |
5580 KB |
Output is correct |
54 |
Correct |
82 ms |
5508 KB |
Output is correct |
55 |
Correct |
79 ms |
5636 KB |
Output is correct |
56 |
Execution timed out |
1054 ms |
47056 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |