Submission #237677

# Submission time Handle Problem Language Result Execution time Memory
237677 2020-06-08T09:28:50 Z Half Pilot (NOI19_pilot) C++14
89 / 100
1000 ms 61800 KB
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;

#define loop(i,a,b) for (int i = a; i <= b; i++)

#define INF ((unsigned) ~0)
#define F first
#define S second
#define PB push_back
#define MP make_pair

const int MXN = 1000000;
int n, q;
int a[MXN];
map<pi, int> v;
int sdu[MXN];
int ssz[MXN];
vector<pair<int, ll>> f;

int rp(int x){
    if(sdu[x] == -1)
        return -1;
    if(sdu[x] == x)
        return x;
    if(sdu[sdu[x]] == sdu[x])
        return sdu[x];
    return sdu[x] = rp(sdu[x]);
}

int main(){
    cin >> n >> q;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        v[MP(a[i], i)] = -1;
        sdu[i] = -1;
    }
    f = {};
    f.push_back(MP(0, 0));
    ll sm = 0;
    for(map<pi, int>::iterator it = v.begin(); it != v.end(); it++){
        //cout << sm << "\n";
        /*for(int j = 0; j < n; j++)
            cout << rp(j) << " ";
        cout << "\n";*/
        it->S = 1;
        int i = (it->F).S;
        //cout << i << "\n";
        //cout << v[MP(a[i - 1], i - 1)] << " " << v[MP(a[i + 1], i + 1)] << "\n";
        if(i != 0 && i != n - 1){
            if(v[MP(a[i - 1], i - 1)] == 1 && v[MP(a[i + 1], i + 1)] == 1){
                int sz = ssz[rp(i - 1)] + ssz[rp(i + 1)] + 1;
                sm -= ((ll)ssz[rp(i - 1)])*((ll)ssz[rp(i - 1)] + 1) / (ll)2;
                sm -= ((ll)ssz[rp(i + 1)])*((ll)ssz[rp(i + 1)] + 1) / (ll)2;
                sm += ((ll)sz)*((ll)sz + 1) / (ll)2;
                sdu[rp(i - 1)] = rp(i + 1);
                sdu[i] = rp(i + 1);
                ssz[rp(i + 1)] = sz;

                if((it->F).F != f[f.size() - 1].F){
                    f.push_back(MP((it->F).F, sm));
                }else{
                    f[f.size() - 1].S = sm;
                }
                continue;
            }
        }
        if(i != 0){
            if(v[MP(a[i - 1], i - 1)] == 1){
                //cout << "<\n";
                sdu[i] = rp(i - 1);
                ssz[rp(i - 1)]++;
                sm += ssz[rp(i - 1)];

                if((it->F).F != f[f.size() - 1].F){
                    f.push_back(MP((it->F).F, sm));
                }else{
                    f[f.size() - 1].S = sm;
                }
                continue;
            }
        }
        if(i != n - 1){
            if(v[MP(a[i + 1], i + 1)] == 1){
                //cout << ">\n";
                sdu[i] = rp(i + 1);
                ssz[rp(i + 1)]++;
                sm += ssz[rp(i + 1)];

                if((it->F).F != f[f.size() - 1].F){
                    f.push_back(MP((it->F).F, sm));
                }else{
                    f[f.size() - 1].S = sm;
                }
                continue;
            }
        }
        //cout << "=\n";
        sdu[i] = i;
        ssz[i] = 1;
        sm += 1;
        if((it->F).F != f[f.size() - 1].F){
            f.push_back(MP((it->F).F, sm));
        }else{
            f[f.size() - 1].S = sm;
        }
    }
    while(q--){
        int y;
        cin >> y;
        int lo = 0, hi = f.size();
        while(hi - lo > 1){
            if(f[(hi + lo) / 2].F > y){
                hi = (hi + lo) / 2;
            }else{
                lo = (hi + lo) / 2;
            }
        }
        cout << f[lo].S << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 8 ms 512 KB Output is correct
22 Correct 8 ms 512 KB Output is correct
23 Correct 8 ms 512 KB Output is correct
24 Correct 8 ms 512 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 185 ms 9380 KB Output is correct
2 Correct 194 ms 10604 KB Output is correct
3 Correct 176 ms 9048 KB Output is correct
4 Correct 178 ms 9840 KB Output is correct
5 Correct 180 ms 8880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 357 ms 10596 KB Output is correct
2 Correct 381 ms 10768 KB Output is correct
3 Correct 364 ms 10596 KB Output is correct
4 Correct 359 ms 10900 KB Output is correct
5 Correct 361 ms 10596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 395 ms 10848 KB Output is correct
2 Correct 365 ms 10852 KB Output is correct
3 Correct 394 ms 10468 KB Output is correct
4 Correct 367 ms 11364 KB Output is correct
5 Correct 382 ms 11040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 185 ms 9380 KB Output is correct
12 Correct 194 ms 10604 KB Output is correct
13 Correct 176 ms 9048 KB Output is correct
14 Correct 178 ms 9840 KB Output is correct
15 Correct 180 ms 8880 KB Output is correct
16 Correct 185 ms 8948 KB Output is correct
17 Correct 229 ms 10604 KB Output is correct
18 Correct 227 ms 10704 KB Output is correct
19 Correct 183 ms 8816 KB Output is correct
20 Correct 201 ms 10348 KB Output is correct
21 Correct 174 ms 8820 KB Output is correct
22 Correct 176 ms 10088 KB Output is correct
23 Correct 185 ms 9456 KB Output is correct
24 Correct 167 ms 9960 KB Output is correct
25 Correct 175 ms 9204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 8 ms 512 KB Output is correct
22 Correct 8 ms 512 KB Output is correct
23 Correct 8 ms 512 KB Output is correct
24 Correct 8 ms 512 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 185 ms 9380 KB Output is correct
27 Correct 194 ms 10604 KB Output is correct
28 Correct 176 ms 9048 KB Output is correct
29 Correct 178 ms 9840 KB Output is correct
30 Correct 180 ms 8880 KB Output is correct
31 Correct 357 ms 10596 KB Output is correct
32 Correct 381 ms 10768 KB Output is correct
33 Correct 364 ms 10596 KB Output is correct
34 Correct 359 ms 10900 KB Output is correct
35 Correct 361 ms 10596 KB Output is correct
36 Correct 395 ms 10848 KB Output is correct
37 Correct 365 ms 10852 KB Output is correct
38 Correct 394 ms 10468 KB Output is correct
39 Correct 367 ms 11364 KB Output is correct
40 Correct 382 ms 11040 KB Output is correct
41 Correct 185 ms 8948 KB Output is correct
42 Correct 229 ms 10604 KB Output is correct
43 Correct 227 ms 10704 KB Output is correct
44 Correct 183 ms 8816 KB Output is correct
45 Correct 201 ms 10348 KB Output is correct
46 Correct 174 ms 8820 KB Output is correct
47 Correct 176 ms 10088 KB Output is correct
48 Correct 185 ms 9456 KB Output is correct
49 Correct 167 ms 9960 KB Output is correct
50 Correct 175 ms 9204 KB Output is correct
51 Correct 435 ms 10600 KB Output is correct
52 Correct 440 ms 10860 KB Output is correct
53 Correct 425 ms 10728 KB Output is correct
54 Correct 438 ms 10900 KB Output is correct
55 Correct 435 ms 10732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 8 ms 512 KB Output is correct
22 Correct 8 ms 512 KB Output is correct
23 Correct 8 ms 512 KB Output is correct
24 Correct 8 ms 512 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 185 ms 9380 KB Output is correct
27 Correct 194 ms 10604 KB Output is correct
28 Correct 176 ms 9048 KB Output is correct
29 Correct 178 ms 9840 KB Output is correct
30 Correct 180 ms 8880 KB Output is correct
31 Correct 357 ms 10596 KB Output is correct
32 Correct 381 ms 10768 KB Output is correct
33 Correct 364 ms 10596 KB Output is correct
34 Correct 359 ms 10900 KB Output is correct
35 Correct 361 ms 10596 KB Output is correct
36 Correct 395 ms 10848 KB Output is correct
37 Correct 365 ms 10852 KB Output is correct
38 Correct 394 ms 10468 KB Output is correct
39 Correct 367 ms 11364 KB Output is correct
40 Correct 382 ms 11040 KB Output is correct
41 Correct 185 ms 8948 KB Output is correct
42 Correct 229 ms 10604 KB Output is correct
43 Correct 227 ms 10704 KB Output is correct
44 Correct 183 ms 8816 KB Output is correct
45 Correct 201 ms 10348 KB Output is correct
46 Correct 174 ms 8820 KB Output is correct
47 Correct 176 ms 10088 KB Output is correct
48 Correct 185 ms 9456 KB Output is correct
49 Correct 167 ms 9960 KB Output is correct
50 Correct 175 ms 9204 KB Output is correct
51 Correct 435 ms 10600 KB Output is correct
52 Correct 440 ms 10860 KB Output is correct
53 Correct 425 ms 10728 KB Output is correct
54 Correct 438 ms 10900 KB Output is correct
55 Correct 435 ms 10732 KB Output is correct
56 Execution timed out 1096 ms 61800 KB Time limit exceeded
57 Halted 0 ms 0 KB -