답안 #753111

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753111 2023-06-04T15:43:49 Z minhnhatnoe Pilot (NOI19_pilot) C++14
89 / 100
1000 ms 34244 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll cresult = 0;
vector<bool> act;
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){
    act[pos] = true;
    cresult += calcpair(1);
    set<pair<int, int>>::iterator it1, it2;
    it2 = s.emplace(pos, pos).first;
    if (pos && act[pos-1]){
        it1 = prev(it2);
        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;

    if (pos != act.size()-1 && act[pos+1]){
        it2 = next(it1);
        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;
    act.resize(n);
    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 'void insert(int)':
pilot.cpp:29:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     if (pos != act.size()-1 && act[pos+1]){
      |         ~~~~^~~~~~~~~~~~~~~
pilot.cpp: In function 'int main()':
pilot.cpp:54: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]
   54 |         while (aptr < a.size() && a[aptr].first <= b[i].first){
      |                ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 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 368 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 2124 KB Output is correct
2 Correct 60 ms 2128 KB Output is correct
3 Correct 53 ms 2156 KB Output is correct
4 Correct 51 ms 2004 KB Output is correct
5 Correct 52 ms 2064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 3400 KB Output is correct
2 Correct 44 ms 3480 KB Output is correct
3 Correct 43 ms 3532 KB Output is correct
4 Correct 42 ms 3476 KB Output is correct
5 Correct 40 ms 3424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 3400 KB Output is correct
2 Correct 40 ms 3436 KB Output is correct
3 Correct 42 ms 3464 KB Output is correct
4 Correct 54 ms 3428 KB Output is correct
5 Correct 43 ms 3652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 54 ms 2124 KB Output is correct
12 Correct 60 ms 2128 KB Output is correct
13 Correct 53 ms 2156 KB Output is correct
14 Correct 51 ms 2004 KB Output is correct
15 Correct 52 ms 2064 KB Output is correct
16 Correct 40 ms 1996 KB Output is correct
17 Correct 29 ms 2132 KB Output is correct
18 Correct 24 ms 1504 KB Output is correct
19 Correct 18 ms 1316 KB Output is correct
20 Correct 34 ms 2116 KB Output is correct
21 Correct 51 ms 2084 KB Output is correct
22 Correct 30 ms 2132 KB Output is correct
23 Correct 24 ms 1992 KB Output is correct
24 Correct 21 ms 1576 KB Output is correct
25 Correct 33 ms 2120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 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 368 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 54 ms 2124 KB Output is correct
27 Correct 60 ms 2128 KB Output is correct
28 Correct 53 ms 2156 KB Output is correct
29 Correct 51 ms 2004 KB Output is correct
30 Correct 52 ms 2064 KB Output is correct
31 Correct 40 ms 3400 KB Output is correct
32 Correct 44 ms 3480 KB Output is correct
33 Correct 43 ms 3532 KB Output is correct
34 Correct 42 ms 3476 KB Output is correct
35 Correct 40 ms 3424 KB Output is correct
36 Correct 40 ms 3400 KB Output is correct
37 Correct 40 ms 3436 KB Output is correct
38 Correct 42 ms 3464 KB Output is correct
39 Correct 54 ms 3428 KB Output is correct
40 Correct 43 ms 3652 KB Output is correct
41 Correct 40 ms 1996 KB Output is correct
42 Correct 29 ms 2132 KB Output is correct
43 Correct 24 ms 1504 KB Output is correct
44 Correct 18 ms 1316 KB Output is correct
45 Correct 34 ms 2116 KB Output is correct
46 Correct 51 ms 2084 KB Output is correct
47 Correct 30 ms 2132 KB Output is correct
48 Correct 24 ms 1992 KB Output is correct
49 Correct 21 ms 1576 KB Output is correct
50 Correct 33 ms 2120 KB Output is correct
51 Correct 78 ms 4520 KB Output is correct
52 Correct 84 ms 4276 KB Output is correct
53 Correct 80 ms 4516 KB Output is correct
54 Correct 85 ms 4252 KB Output is correct
55 Correct 79 ms 4496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 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 368 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 54 ms 2124 KB Output is correct
27 Correct 60 ms 2128 KB Output is correct
28 Correct 53 ms 2156 KB Output is correct
29 Correct 51 ms 2004 KB Output is correct
30 Correct 52 ms 2064 KB Output is correct
31 Correct 40 ms 3400 KB Output is correct
32 Correct 44 ms 3480 KB Output is correct
33 Correct 43 ms 3532 KB Output is correct
34 Correct 42 ms 3476 KB Output is correct
35 Correct 40 ms 3424 KB Output is correct
36 Correct 40 ms 3400 KB Output is correct
37 Correct 40 ms 3436 KB Output is correct
38 Correct 42 ms 3464 KB Output is correct
39 Correct 54 ms 3428 KB Output is correct
40 Correct 43 ms 3652 KB Output is correct
41 Correct 40 ms 1996 KB Output is correct
42 Correct 29 ms 2132 KB Output is correct
43 Correct 24 ms 1504 KB Output is correct
44 Correct 18 ms 1316 KB Output is correct
45 Correct 34 ms 2116 KB Output is correct
46 Correct 51 ms 2084 KB Output is correct
47 Correct 30 ms 2132 KB Output is correct
48 Correct 24 ms 1992 KB Output is correct
49 Correct 21 ms 1576 KB Output is correct
50 Correct 33 ms 2120 KB Output is correct
51 Correct 78 ms 4520 KB Output is correct
52 Correct 84 ms 4276 KB Output is correct
53 Correct 80 ms 4516 KB Output is correct
54 Correct 85 ms 4252 KB Output is correct
55 Correct 79 ms 4496 KB Output is correct
56 Execution timed out 1081 ms 34244 KB Time limit exceeded
57 Halted 0 ms 0 KB -