답안 #373432

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373432 2021-03-04T14:46:34 Z cpp219 Pilot (NOI19_pilot) C++14
100 / 100
842 ms 68388 KB
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e6 + 9;
const ll inf = 1e16 + 7;
LL q[N];
ll n,Q,ans[N],lab[N],cur,a[N];
deque<ll> dq;
ll Find(ll u){
    if (lab[u] < 0) return u;
    return lab[u] = Find(lab[u]);
}

void Union(ll p,ll q){
    ll r = Find(p),s = Find(q);
    if (r == s) return;
    cur += lab[r]*lab[s];
    if (lab[r] > lab[s]) swap(r,s);
    lab[r] += lab[s]; lab[s] = r;
}

bool lf(ll x,ll y){
    return a[x] < a[y];
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define task "tst"
    if (fopen(task".INP","r")){
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    cin>>n>>Q; memset(lab,-1,sizeof(lab));
    for (ll i = 1;i <= n;i++) cin>>a[i],dq.push_back(i); sort(dq.begin(),dq.end(),lf);
    for (ll i = 1;i <= Q;i++) cin>>q[i].fs,q[i].sc = i; sort(q + 1,q + Q + 1);
    for (ll i = 1;i <= Q;i++){
        while(!dq.empty()){
            ll t = dq.front();
            if (a[t] > q[i].fs) break; dq.pop_front();
            cur++;
            if (t != 1&&a[t - 1] <= q[i].fs) Union(t,t - 1);
            if (t != n&&a[t + 1] <= q[i].fs) Union(t,t + 1);
        }
        ans[q[i].sc] = cur;
    }
    for (ll i = 1;i <= Q;i++) cout<<ans[i]<<"\n";
}

Compilation message

pilot.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
pilot.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
pilot.cpp: In function 'int main()':
pilot.cpp:43:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   43 |     for (ll i = 1;i <= n;i++) cin>>a[i],dq.push_back(i); sort(dq.begin(),dq.end(),lf);
      |     ^~~
pilot.cpp:43:58: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   43 |     for (ll i = 1;i <= n;i++) cin>>a[i],dq.push_back(i); sort(dq.begin(),dq.end(),lf);
      |                                                          ^~~~
pilot.cpp:44:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   44 |     for (ll i = 1;i <= Q;i++) cin>>q[i].fs,q[i].sc = i; sort(q + 1,q + Q + 1);
      |     ^~~
pilot.cpp:44:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   44 |     for (ll i = 1;i <= Q;i++) cin>>q[i].fs,q[i].sc = i; sort(q + 1,q + Q + 1);
      |                                                         ^~~~
pilot.cpp:48:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   48 |             if (a[t] > q[i].fs) break; dq.pop_front();
      |             ^~
pilot.cpp:48:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   48 |             if (a[t] > q[i].fs) break; dq.pop_front();
      |                                        ^~
pilot.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   39 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8300 KB Output is correct
2 Correct 4 ms 8172 KB Output is correct
3 Correct 4 ms 8172 KB Output is correct
4 Correct 6 ms 8172 KB Output is correct
5 Correct 4 ms 8172 KB Output is correct
6 Correct 5 ms 8184 KB Output is correct
7 Correct 5 ms 8172 KB Output is correct
8 Correct 6 ms 8172 KB Output is correct
9 Correct 4 ms 8172 KB Output is correct
10 Correct 5 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8300 KB Output is correct
2 Correct 4 ms 8172 KB Output is correct
3 Correct 4 ms 8172 KB Output is correct
4 Correct 6 ms 8172 KB Output is correct
5 Correct 4 ms 8172 KB Output is correct
6 Correct 5 ms 8184 KB Output is correct
7 Correct 5 ms 8172 KB Output is correct
8 Correct 6 ms 8172 KB Output is correct
9 Correct 4 ms 8172 KB Output is correct
10 Correct 5 ms 8172 KB Output is correct
11 Correct 4 ms 8300 KB Output is correct
12 Correct 14 ms 8300 KB Output is correct
13 Correct 5 ms 8172 KB Output is correct
14 Correct 5 ms 8172 KB Output is correct
15 Correct 5 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8300 KB Output is correct
2 Correct 4 ms 8172 KB Output is correct
3 Correct 4 ms 8172 KB Output is correct
4 Correct 6 ms 8172 KB Output is correct
5 Correct 4 ms 8172 KB Output is correct
6 Correct 5 ms 8184 KB Output is correct
7 Correct 5 ms 8172 KB Output is correct
8 Correct 6 ms 8172 KB Output is correct
9 Correct 4 ms 8172 KB Output is correct
10 Correct 5 ms 8172 KB Output is correct
11 Correct 4 ms 8300 KB Output is correct
12 Correct 14 ms 8300 KB Output is correct
13 Correct 5 ms 8172 KB Output is correct
14 Correct 5 ms 8172 KB Output is correct
15 Correct 5 ms 8172 KB Output is correct
16 Correct 6 ms 8172 KB Output is correct
17 Correct 5 ms 8172 KB Output is correct
18 Correct 5 ms 8192 KB Output is correct
19 Correct 5 ms 8172 KB Output is correct
20 Correct 5 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8300 KB Output is correct
2 Correct 4 ms 8172 KB Output is correct
3 Correct 4 ms 8172 KB Output is correct
4 Correct 6 ms 8172 KB Output is correct
5 Correct 4 ms 8172 KB Output is correct
6 Correct 5 ms 8184 KB Output is correct
7 Correct 5 ms 8172 KB Output is correct
8 Correct 6 ms 8172 KB Output is correct
9 Correct 4 ms 8172 KB Output is correct
10 Correct 5 ms 8172 KB Output is correct
11 Correct 4 ms 8300 KB Output is correct
12 Correct 14 ms 8300 KB Output is correct
13 Correct 5 ms 8172 KB Output is correct
14 Correct 5 ms 8172 KB Output is correct
15 Correct 5 ms 8172 KB Output is correct
16 Correct 6 ms 8172 KB Output is correct
17 Correct 5 ms 8172 KB Output is correct
18 Correct 5 ms 8192 KB Output is correct
19 Correct 5 ms 8172 KB Output is correct
20 Correct 5 ms 8172 KB Output is correct
21 Correct 6 ms 8300 KB Output is correct
22 Correct 6 ms 8300 KB Output is correct
23 Correct 6 ms 8300 KB Output is correct
24 Correct 6 ms 8300 KB Output is correct
25 Correct 5 ms 8300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 10364 KB Output is correct
2 Correct 37 ms 10476 KB Output is correct
3 Correct 34 ms 10220 KB Output is correct
4 Correct 34 ms 10220 KB Output is correct
5 Correct 34 ms 10348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 13932 KB Output is correct
2 Correct 53 ms 14188 KB Output is correct
3 Correct 51 ms 14060 KB Output is correct
4 Correct 67 ms 14060 KB Output is correct
5 Correct 51 ms 13932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 14188 KB Output is correct
2 Correct 53 ms 14060 KB Output is correct
3 Correct 53 ms 14188 KB Output is correct
4 Correct 53 ms 14188 KB Output is correct
5 Correct 58 ms 14444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8300 KB Output is correct
2 Correct 4 ms 8172 KB Output is correct
3 Correct 4 ms 8172 KB Output is correct
4 Correct 6 ms 8172 KB Output is correct
5 Correct 4 ms 8172 KB Output is correct
6 Correct 5 ms 8184 KB Output is correct
7 Correct 5 ms 8172 KB Output is correct
8 Correct 6 ms 8172 KB Output is correct
9 Correct 4 ms 8172 KB Output is correct
10 Correct 5 ms 8172 KB Output is correct
11 Correct 36 ms 10364 KB Output is correct
12 Correct 37 ms 10476 KB Output is correct
13 Correct 34 ms 10220 KB Output is correct
14 Correct 34 ms 10220 KB Output is correct
15 Correct 34 ms 10348 KB Output is correct
16 Correct 32 ms 10220 KB Output is correct
17 Correct 38 ms 10604 KB Output is correct
18 Correct 33 ms 10476 KB Output is correct
19 Correct 29 ms 10220 KB Output is correct
20 Correct 33 ms 10348 KB Output is correct
21 Correct 35 ms 10220 KB Output is correct
22 Correct 32 ms 10348 KB Output is correct
23 Correct 32 ms 10348 KB Output is correct
24 Correct 30 ms 10348 KB Output is correct
25 Correct 32 ms 10348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8300 KB Output is correct
2 Correct 4 ms 8172 KB Output is correct
3 Correct 4 ms 8172 KB Output is correct
4 Correct 6 ms 8172 KB Output is correct
5 Correct 4 ms 8172 KB Output is correct
6 Correct 5 ms 8184 KB Output is correct
7 Correct 5 ms 8172 KB Output is correct
8 Correct 6 ms 8172 KB Output is correct
9 Correct 4 ms 8172 KB Output is correct
10 Correct 5 ms 8172 KB Output is correct
11 Correct 4 ms 8300 KB Output is correct
12 Correct 14 ms 8300 KB Output is correct
13 Correct 5 ms 8172 KB Output is correct
14 Correct 5 ms 8172 KB Output is correct
15 Correct 5 ms 8172 KB Output is correct
16 Correct 6 ms 8172 KB Output is correct
17 Correct 5 ms 8172 KB Output is correct
18 Correct 5 ms 8192 KB Output is correct
19 Correct 5 ms 8172 KB Output is correct
20 Correct 5 ms 8172 KB Output is correct
21 Correct 6 ms 8300 KB Output is correct
22 Correct 6 ms 8300 KB Output is correct
23 Correct 6 ms 8300 KB Output is correct
24 Correct 6 ms 8300 KB Output is correct
25 Correct 5 ms 8300 KB Output is correct
26 Correct 36 ms 10364 KB Output is correct
27 Correct 37 ms 10476 KB Output is correct
28 Correct 34 ms 10220 KB Output is correct
29 Correct 34 ms 10220 KB Output is correct
30 Correct 34 ms 10348 KB Output is correct
31 Correct 50 ms 13932 KB Output is correct
32 Correct 53 ms 14188 KB Output is correct
33 Correct 51 ms 14060 KB Output is correct
34 Correct 67 ms 14060 KB Output is correct
35 Correct 51 ms 13932 KB Output is correct
36 Correct 53 ms 14188 KB Output is correct
37 Correct 53 ms 14060 KB Output is correct
38 Correct 53 ms 14188 KB Output is correct
39 Correct 53 ms 14188 KB Output is correct
40 Correct 58 ms 14444 KB Output is correct
41 Correct 32 ms 10220 KB Output is correct
42 Correct 38 ms 10604 KB Output is correct
43 Correct 33 ms 10476 KB Output is correct
44 Correct 29 ms 10220 KB Output is correct
45 Correct 33 ms 10348 KB Output is correct
46 Correct 35 ms 10220 KB Output is correct
47 Correct 32 ms 10348 KB Output is correct
48 Correct 32 ms 10348 KB Output is correct
49 Correct 30 ms 10348 KB Output is correct
50 Correct 32 ms 10348 KB Output is correct
51 Correct 66 ms 14060 KB Output is correct
52 Correct 64 ms 13932 KB Output is correct
53 Correct 65 ms 13932 KB Output is correct
54 Correct 63 ms 13956 KB Output is correct
55 Correct 71 ms 13932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8300 KB Output is correct
2 Correct 4 ms 8172 KB Output is correct
3 Correct 4 ms 8172 KB Output is correct
4 Correct 6 ms 8172 KB Output is correct
5 Correct 4 ms 8172 KB Output is correct
6 Correct 5 ms 8184 KB Output is correct
7 Correct 5 ms 8172 KB Output is correct
8 Correct 6 ms 8172 KB Output is correct
9 Correct 4 ms 8172 KB Output is correct
10 Correct 5 ms 8172 KB Output is correct
11 Correct 4 ms 8300 KB Output is correct
12 Correct 14 ms 8300 KB Output is correct
13 Correct 5 ms 8172 KB Output is correct
14 Correct 5 ms 8172 KB Output is correct
15 Correct 5 ms 8172 KB Output is correct
16 Correct 6 ms 8172 KB Output is correct
17 Correct 5 ms 8172 KB Output is correct
18 Correct 5 ms 8192 KB Output is correct
19 Correct 5 ms 8172 KB Output is correct
20 Correct 5 ms 8172 KB Output is correct
21 Correct 6 ms 8300 KB Output is correct
22 Correct 6 ms 8300 KB Output is correct
23 Correct 6 ms 8300 KB Output is correct
24 Correct 6 ms 8300 KB Output is correct
25 Correct 5 ms 8300 KB Output is correct
26 Correct 36 ms 10364 KB Output is correct
27 Correct 37 ms 10476 KB Output is correct
28 Correct 34 ms 10220 KB Output is correct
29 Correct 34 ms 10220 KB Output is correct
30 Correct 34 ms 10348 KB Output is correct
31 Correct 50 ms 13932 KB Output is correct
32 Correct 53 ms 14188 KB Output is correct
33 Correct 51 ms 14060 KB Output is correct
34 Correct 67 ms 14060 KB Output is correct
35 Correct 51 ms 13932 KB Output is correct
36 Correct 53 ms 14188 KB Output is correct
37 Correct 53 ms 14060 KB Output is correct
38 Correct 53 ms 14188 KB Output is correct
39 Correct 53 ms 14188 KB Output is correct
40 Correct 58 ms 14444 KB Output is correct
41 Correct 32 ms 10220 KB Output is correct
42 Correct 38 ms 10604 KB Output is correct
43 Correct 33 ms 10476 KB Output is correct
44 Correct 29 ms 10220 KB Output is correct
45 Correct 33 ms 10348 KB Output is correct
46 Correct 35 ms 10220 KB Output is correct
47 Correct 32 ms 10348 KB Output is correct
48 Correct 32 ms 10348 KB Output is correct
49 Correct 30 ms 10348 KB Output is correct
50 Correct 32 ms 10348 KB Output is correct
51 Correct 66 ms 14060 KB Output is correct
52 Correct 64 ms 13932 KB Output is correct
53 Correct 65 ms 13932 KB Output is correct
54 Correct 63 ms 13956 KB Output is correct
55 Correct 71 ms 13932 KB Output is correct
56 Correct 823 ms 67324 KB Output is correct
57 Correct 818 ms 66300 KB Output is correct
58 Correct 760 ms 63228 KB Output is correct
59 Correct 781 ms 64508 KB Output is correct
60 Correct 842 ms 68388 KB Output is correct