답안 #763697

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763697 2023-06-22T16:05:35 Z HoriaHaivas Pilot (NOI19_pilot) C++14
100 / 100
494 ms 76316 KB
/*
    "TLE is like the wind, always by my side"
    - Yasuo - 2022 -
*/
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast")
#define int long long

using namespace std;

struct number
{
    int val;
    int poz;
};

number v[2000001];
bool enable[2000001];
int ans[2000001];
int query[2000001];
int originalquery[2000001];
int cardinal[2000001];
int root[2000001];
int total;

bool cmp (number a, number b)
{
    if (a.val!=b.val)
        return a.val<b.val;
    else
        return a.poz<b.poz;
}

void unite(int a, int b)
{
    if (cardinal[a]>cardinal[b])
        swap(a,b);
    root[a]=root[b];
    cardinal[b]+=cardinal[a];
    cardinal[a]=cardinal[b];
}

int searchset(int a)
{
    if (root[a]==a)
        return a;
    root[a]=searchset(root[a]);
    return root[a];
}

void update(int index)
{
    enable[index]=1;
    root[index]=index;
    cardinal[index]=1;
    int enter;
    enter=0;
    if (enable[index-1])
    {
        enter++;
    }
    if (enable[index+1])
    {
        enter++;
    }
    if (enter==0)
        total++;
    if (enter==1)
    {
        if (enable[index-1])
        {
            total+=cardinal[searchset(index-1)]+1;
            unite(searchset(index-1),searchset(index));
        }
        else
        {
            total+=cardinal[searchset(index+1)]+1;
            unite(searchset(index+1),searchset(index));
        }
    }
    if (enter==2)
    {
        total-=cardinal[searchset(index-1)]*(cardinal[searchset(index-1)]+1)/2;
        total-=cardinal[searchset(index+1)]*(cardinal[searchset(index+1)]+1)/2;
        unite(searchset(index-1),searchset(index));
        unite(searchset(index+1),searchset(index));
        total+=cardinal[searchset(index)]*(cardinal[searchset(index)]+1)/2;
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,q,i,j,cnt;
    cin >> n >> q;
    for (i=1; i<=n; i++)
    {
        cin >> v[i].val;
        v[i].poz=i;
    }
    for (i=1; i<=q; i++)
    {
        cin >> originalquery[i];
        query[i]=originalquery[i];
    }
    sort(query+1,query+1+q);
    sort(v+1,v+1+n,cmp);
    cnt=1;
    while (query[cnt]<v[1].val)
        cnt++;
    total=0;
    for (i=1; i<=n; i++)
    {
        update(v[i].poz);
        if (v[i].val!=v[i+1].val)
        {
            while (query[cnt]<v[i+1].val && cnt<=q || i==n && cnt<=q)
            {
                ans[query[cnt]]=total;
                cnt++;
            }
        }
    }
    for (i=1; i<=q; i++)
    {
        if (originalquery[i]<=v[n].val)
            cout << ans[originalquery[i]] << "\n";
        else
            cout << total << "\n";
    }
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:121:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  121 |             while (query[cnt]<v[i+1].val && cnt<=q || i==n && cnt<=q)
      |                    ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
pilot.cpp:98:15: warning: unused variable 'j' [-Wunused-variable]
   98 |     int n,q,i,j,cnt;
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 6 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 6 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 6 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 6 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 1 ms 2004 KB Output is correct
22 Correct 2 ms 3156 KB Output is correct
23 Correct 1 ms 2132 KB Output is correct
24 Correct 2 ms 3156 KB Output is correct
25 Correct 1 ms 2004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3476 KB Output is correct
2 Correct 20 ms 3548 KB Output is correct
3 Correct 21 ms 3356 KB Output is correct
4 Correct 17 ms 3192 KB Output is correct
5 Correct 17 ms 3284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 13588 KB Output is correct
2 Correct 35 ms 13652 KB Output is correct
3 Correct 35 ms 13640 KB Output is correct
4 Correct 35 ms 13776 KB Output is correct
5 Correct 36 ms 13596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 13620 KB Output is correct
2 Correct 38 ms 14880 KB Output is correct
3 Correct 40 ms 14884 KB Output is correct
4 Correct 46 ms 15024 KB Output is correct
5 Correct 39 ms 15112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 6 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 18 ms 3476 KB Output is correct
12 Correct 20 ms 3548 KB Output is correct
13 Correct 21 ms 3356 KB Output is correct
14 Correct 17 ms 3192 KB Output is correct
15 Correct 17 ms 3284 KB Output is correct
16 Correct 17 ms 3332 KB Output is correct
17 Correct 18 ms 3420 KB Output is correct
18 Correct 18 ms 3572 KB Output is correct
19 Correct 17 ms 3284 KB Output is correct
20 Correct 20 ms 3412 KB Output is correct
21 Correct 18 ms 3312 KB Output is correct
22 Correct 19 ms 3280 KB Output is correct
23 Correct 19 ms 3568 KB Output is correct
24 Correct 17 ms 3200 KB Output is correct
25 Correct 18 ms 3392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 6 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 1 ms 2004 KB Output is correct
22 Correct 2 ms 3156 KB Output is correct
23 Correct 1 ms 2132 KB Output is correct
24 Correct 2 ms 3156 KB Output is correct
25 Correct 1 ms 2004 KB Output is correct
26 Correct 18 ms 3476 KB Output is correct
27 Correct 20 ms 3548 KB Output is correct
28 Correct 21 ms 3356 KB Output is correct
29 Correct 17 ms 3192 KB Output is correct
30 Correct 17 ms 3284 KB Output is correct
31 Correct 34 ms 13588 KB Output is correct
32 Correct 35 ms 13652 KB Output is correct
33 Correct 35 ms 13640 KB Output is correct
34 Correct 35 ms 13776 KB Output is correct
35 Correct 36 ms 13596 KB Output is correct
36 Correct 37 ms 13620 KB Output is correct
37 Correct 38 ms 14880 KB Output is correct
38 Correct 40 ms 14884 KB Output is correct
39 Correct 46 ms 15024 KB Output is correct
40 Correct 39 ms 15112 KB Output is correct
41 Correct 17 ms 3332 KB Output is correct
42 Correct 18 ms 3420 KB Output is correct
43 Correct 18 ms 3572 KB Output is correct
44 Correct 17 ms 3284 KB Output is correct
45 Correct 20 ms 3412 KB Output is correct
46 Correct 18 ms 3312 KB Output is correct
47 Correct 19 ms 3280 KB Output is correct
48 Correct 19 ms 3568 KB Output is correct
49 Correct 17 ms 3200 KB Output is correct
50 Correct 18 ms 3392 KB Output is correct
51 Correct 41 ms 14668 KB Output is correct
52 Correct 43 ms 14644 KB Output is correct
53 Correct 40 ms 14800 KB Output is correct
54 Correct 41 ms 14580 KB Output is correct
55 Correct 40 ms 14740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 6 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 1 ms 2004 KB Output is correct
22 Correct 2 ms 3156 KB Output is correct
23 Correct 1 ms 2132 KB Output is correct
24 Correct 2 ms 3156 KB Output is correct
25 Correct 1 ms 2004 KB Output is correct
26 Correct 18 ms 3476 KB Output is correct
27 Correct 20 ms 3548 KB Output is correct
28 Correct 21 ms 3356 KB Output is correct
29 Correct 17 ms 3192 KB Output is correct
30 Correct 17 ms 3284 KB Output is correct
31 Correct 34 ms 13588 KB Output is correct
32 Correct 35 ms 13652 KB Output is correct
33 Correct 35 ms 13640 KB Output is correct
34 Correct 35 ms 13776 KB Output is correct
35 Correct 36 ms 13596 KB Output is correct
36 Correct 37 ms 13620 KB Output is correct
37 Correct 38 ms 14880 KB Output is correct
38 Correct 40 ms 14884 KB Output is correct
39 Correct 46 ms 15024 KB Output is correct
40 Correct 39 ms 15112 KB Output is correct
41 Correct 17 ms 3332 KB Output is correct
42 Correct 18 ms 3420 KB Output is correct
43 Correct 18 ms 3572 KB Output is correct
44 Correct 17 ms 3284 KB Output is correct
45 Correct 20 ms 3412 KB Output is correct
46 Correct 18 ms 3312 KB Output is correct
47 Correct 19 ms 3280 KB Output is correct
48 Correct 19 ms 3568 KB Output is correct
49 Correct 17 ms 3200 KB Output is correct
50 Correct 18 ms 3392 KB Output is correct
51 Correct 41 ms 14668 KB Output is correct
52 Correct 43 ms 14644 KB Output is correct
53 Correct 40 ms 14800 KB Output is correct
54 Correct 41 ms 14580 KB Output is correct
55 Correct 40 ms 14740 KB Output is correct
56 Correct 478 ms 74504 KB Output is correct
57 Correct 463 ms 74608 KB Output is correct
58 Correct 417 ms 70740 KB Output is correct
59 Correct 494 ms 72204 KB Output is correct
60 Correct 466 ms 76316 KB Output is correct