# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
344741 |
2021-01-06T12:29:18 Z |
nguot |
Pilot (NOI19_pilot) |
C++14 |
|
944 ms |
97516 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0)
#define fori(x,a,b) for (int x=a;x<=b;x++)
#define ford(x,a,b) for (int x=a;x>=b;x--)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define all(a) a.begin(),a.end()
#define reset(f,x) memset(f, x, sizeof(f))
#define getbit(x,i) ((x>>(i-1))&1)
#define batbit(x,i) (x|(1ll<<(i-1)))
#define tatbit(x,i) (x&~(1<<(i-1)))
#define gg exit(0);
const int maxn = 1e6 + 10;
int n,t,x,dd[maxn];
vector<int> ke[maxn];
ii q[maxn];
int f[maxn];
int root(int x)
{
if(f[x]<0) return x;
return f[x] = root(f[x]);
}
int kq=0;
void hop(int x,int y)
{
if(!dd[y]||y>n||y<1) return;
x = root(x),y = root(y);
kq-=(f[x]*(f[x]-1) + f[y]*(f[y]-1))/2;
f[y]+=f[x];
f[x] = y;
kq+=f[y]*(f[y]-1)/2;
}
int ans[maxn];
main()
{
//freopen("task.inp","r",stdin);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>t;
fori(i,1,n) cin>>x,ke[x].pb(i);
fori(i,1,t) cin>>q[i].fi,q[i].se = i;
sort(q+1,q+t+1);
reset(f,-1);
int m=1;
fori(i,1,1e6)
{
forv(j,ke[i])
{
++kq,dd[j] = 1;
hop(j,j+1),hop(j,j-1);
}
while(q[m].fi==i) ans[q[m].se] = kq,++m;
}
fori(i,1,t) cout<<ans[i]<<"\n";
}
Compilation message
pilot.cpp:47:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
47 | main()
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
31852 KB |
Output is correct |
2 |
Correct |
21 ms |
31724 KB |
Output is correct |
3 |
Correct |
21 ms |
31724 KB |
Output is correct |
4 |
Correct |
21 ms |
31724 KB |
Output is correct |
5 |
Correct |
21 ms |
31724 KB |
Output is correct |
6 |
Correct |
21 ms |
31676 KB |
Output is correct |
7 |
Correct |
21 ms |
31724 KB |
Output is correct |
8 |
Correct |
20 ms |
31724 KB |
Output is correct |
9 |
Correct |
20 ms |
31724 KB |
Output is correct |
10 |
Correct |
21 ms |
31724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
31852 KB |
Output is correct |
2 |
Correct |
21 ms |
31724 KB |
Output is correct |
3 |
Correct |
21 ms |
31724 KB |
Output is correct |
4 |
Correct |
21 ms |
31724 KB |
Output is correct |
5 |
Correct |
21 ms |
31724 KB |
Output is correct |
6 |
Correct |
21 ms |
31676 KB |
Output is correct |
7 |
Correct |
21 ms |
31724 KB |
Output is correct |
8 |
Correct |
20 ms |
31724 KB |
Output is correct |
9 |
Correct |
20 ms |
31724 KB |
Output is correct |
10 |
Correct |
21 ms |
31724 KB |
Output is correct |
11 |
Correct |
22 ms |
31724 KB |
Output is correct |
12 |
Correct |
21 ms |
31724 KB |
Output is correct |
13 |
Correct |
23 ms |
31724 KB |
Output is correct |
14 |
Correct |
21 ms |
31724 KB |
Output is correct |
15 |
Correct |
21 ms |
31724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
31852 KB |
Output is correct |
2 |
Correct |
21 ms |
31724 KB |
Output is correct |
3 |
Correct |
21 ms |
31724 KB |
Output is correct |
4 |
Correct |
21 ms |
31724 KB |
Output is correct |
5 |
Correct |
21 ms |
31724 KB |
Output is correct |
6 |
Correct |
21 ms |
31676 KB |
Output is correct |
7 |
Correct |
21 ms |
31724 KB |
Output is correct |
8 |
Correct |
20 ms |
31724 KB |
Output is correct |
9 |
Correct |
20 ms |
31724 KB |
Output is correct |
10 |
Correct |
21 ms |
31724 KB |
Output is correct |
11 |
Correct |
22 ms |
31724 KB |
Output is correct |
12 |
Correct |
21 ms |
31724 KB |
Output is correct |
13 |
Correct |
23 ms |
31724 KB |
Output is correct |
14 |
Correct |
21 ms |
31724 KB |
Output is correct |
15 |
Correct |
21 ms |
31724 KB |
Output is correct |
16 |
Correct |
21 ms |
31724 KB |
Output is correct |
17 |
Correct |
21 ms |
31724 KB |
Output is correct |
18 |
Correct |
21 ms |
31724 KB |
Output is correct |
19 |
Correct |
21 ms |
31724 KB |
Output is correct |
20 |
Correct |
21 ms |
31744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
31852 KB |
Output is correct |
2 |
Correct |
21 ms |
31724 KB |
Output is correct |
3 |
Correct |
21 ms |
31724 KB |
Output is correct |
4 |
Correct |
21 ms |
31724 KB |
Output is correct |
5 |
Correct |
21 ms |
31724 KB |
Output is correct |
6 |
Correct |
21 ms |
31676 KB |
Output is correct |
7 |
Correct |
21 ms |
31724 KB |
Output is correct |
8 |
Correct |
20 ms |
31724 KB |
Output is correct |
9 |
Correct |
20 ms |
31724 KB |
Output is correct |
10 |
Correct |
21 ms |
31724 KB |
Output is correct |
11 |
Correct |
22 ms |
31724 KB |
Output is correct |
12 |
Correct |
21 ms |
31724 KB |
Output is correct |
13 |
Correct |
23 ms |
31724 KB |
Output is correct |
14 |
Correct |
21 ms |
31724 KB |
Output is correct |
15 |
Correct |
21 ms |
31724 KB |
Output is correct |
16 |
Correct |
21 ms |
31724 KB |
Output is correct |
17 |
Correct |
21 ms |
31724 KB |
Output is correct |
18 |
Correct |
21 ms |
31724 KB |
Output is correct |
19 |
Correct |
21 ms |
31724 KB |
Output is correct |
20 |
Correct |
21 ms |
31744 KB |
Output is correct |
21 |
Correct |
21 ms |
31724 KB |
Output is correct |
22 |
Correct |
22 ms |
31744 KB |
Output is correct |
23 |
Correct |
22 ms |
31724 KB |
Output is correct |
24 |
Correct |
22 ms |
31724 KB |
Output is correct |
25 |
Correct |
21 ms |
31724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
35052 KB |
Output is correct |
2 |
Correct |
67 ms |
36076 KB |
Output is correct |
3 |
Correct |
50 ms |
34924 KB |
Output is correct |
4 |
Correct |
60 ms |
35716 KB |
Output is correct |
5 |
Correct |
47 ms |
34924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
39532 KB |
Output is correct |
2 |
Correct |
68 ms |
39788 KB |
Output is correct |
3 |
Correct |
79 ms |
39660 KB |
Output is correct |
4 |
Correct |
68 ms |
39788 KB |
Output is correct |
5 |
Correct |
65 ms |
39532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
39788 KB |
Output is correct |
2 |
Correct |
71 ms |
39788 KB |
Output is correct |
3 |
Correct |
71 ms |
39788 KB |
Output is correct |
4 |
Correct |
80 ms |
39916 KB |
Output is correct |
5 |
Correct |
83 ms |
40044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
31852 KB |
Output is correct |
2 |
Correct |
21 ms |
31724 KB |
Output is correct |
3 |
Correct |
21 ms |
31724 KB |
Output is correct |
4 |
Correct |
21 ms |
31724 KB |
Output is correct |
5 |
Correct |
21 ms |
31724 KB |
Output is correct |
6 |
Correct |
21 ms |
31676 KB |
Output is correct |
7 |
Correct |
21 ms |
31724 KB |
Output is correct |
8 |
Correct |
20 ms |
31724 KB |
Output is correct |
9 |
Correct |
20 ms |
31724 KB |
Output is correct |
10 |
Correct |
21 ms |
31724 KB |
Output is correct |
11 |
Correct |
53 ms |
35052 KB |
Output is correct |
12 |
Correct |
67 ms |
36076 KB |
Output is correct |
13 |
Correct |
50 ms |
34924 KB |
Output is correct |
14 |
Correct |
60 ms |
35716 KB |
Output is correct |
15 |
Correct |
47 ms |
34924 KB |
Output is correct |
16 |
Correct |
51 ms |
34924 KB |
Output is correct |
17 |
Correct |
72 ms |
36076 KB |
Output is correct |
18 |
Correct |
68 ms |
36096 KB |
Output is correct |
19 |
Correct |
67 ms |
34828 KB |
Output is correct |
20 |
Correct |
71 ms |
36076 KB |
Output is correct |
21 |
Correct |
51 ms |
34924 KB |
Output is correct |
22 |
Correct |
74 ms |
35820 KB |
Output is correct |
23 |
Correct |
51 ms |
35180 KB |
Output is correct |
24 |
Correct |
63 ms |
35692 KB |
Output is correct |
25 |
Correct |
51 ms |
35052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
31852 KB |
Output is correct |
2 |
Correct |
21 ms |
31724 KB |
Output is correct |
3 |
Correct |
21 ms |
31724 KB |
Output is correct |
4 |
Correct |
21 ms |
31724 KB |
Output is correct |
5 |
Correct |
21 ms |
31724 KB |
Output is correct |
6 |
Correct |
21 ms |
31676 KB |
Output is correct |
7 |
Correct |
21 ms |
31724 KB |
Output is correct |
8 |
Correct |
20 ms |
31724 KB |
Output is correct |
9 |
Correct |
20 ms |
31724 KB |
Output is correct |
10 |
Correct |
21 ms |
31724 KB |
Output is correct |
11 |
Correct |
22 ms |
31724 KB |
Output is correct |
12 |
Correct |
21 ms |
31724 KB |
Output is correct |
13 |
Correct |
23 ms |
31724 KB |
Output is correct |
14 |
Correct |
21 ms |
31724 KB |
Output is correct |
15 |
Correct |
21 ms |
31724 KB |
Output is correct |
16 |
Correct |
21 ms |
31724 KB |
Output is correct |
17 |
Correct |
21 ms |
31724 KB |
Output is correct |
18 |
Correct |
21 ms |
31724 KB |
Output is correct |
19 |
Correct |
21 ms |
31724 KB |
Output is correct |
20 |
Correct |
21 ms |
31744 KB |
Output is correct |
21 |
Correct |
21 ms |
31724 KB |
Output is correct |
22 |
Correct |
22 ms |
31744 KB |
Output is correct |
23 |
Correct |
22 ms |
31724 KB |
Output is correct |
24 |
Correct |
22 ms |
31724 KB |
Output is correct |
25 |
Correct |
21 ms |
31724 KB |
Output is correct |
26 |
Correct |
53 ms |
35052 KB |
Output is correct |
27 |
Correct |
67 ms |
36076 KB |
Output is correct |
28 |
Correct |
50 ms |
34924 KB |
Output is correct |
29 |
Correct |
60 ms |
35716 KB |
Output is correct |
30 |
Correct |
47 ms |
34924 KB |
Output is correct |
31 |
Correct |
65 ms |
39532 KB |
Output is correct |
32 |
Correct |
68 ms |
39788 KB |
Output is correct |
33 |
Correct |
79 ms |
39660 KB |
Output is correct |
34 |
Correct |
68 ms |
39788 KB |
Output is correct |
35 |
Correct |
65 ms |
39532 KB |
Output is correct |
36 |
Correct |
69 ms |
39788 KB |
Output is correct |
37 |
Correct |
71 ms |
39788 KB |
Output is correct |
38 |
Correct |
71 ms |
39788 KB |
Output is correct |
39 |
Correct |
80 ms |
39916 KB |
Output is correct |
40 |
Correct |
83 ms |
40044 KB |
Output is correct |
41 |
Correct |
51 ms |
34924 KB |
Output is correct |
42 |
Correct |
72 ms |
36076 KB |
Output is correct |
43 |
Correct |
68 ms |
36096 KB |
Output is correct |
44 |
Correct |
67 ms |
34828 KB |
Output is correct |
45 |
Correct |
71 ms |
36076 KB |
Output is correct |
46 |
Correct |
51 ms |
34924 KB |
Output is correct |
47 |
Correct |
74 ms |
35820 KB |
Output is correct |
48 |
Correct |
51 ms |
35180 KB |
Output is correct |
49 |
Correct |
63 ms |
35692 KB |
Output is correct |
50 |
Correct |
51 ms |
35052 KB |
Output is correct |
51 |
Correct |
85 ms |
38716 KB |
Output is correct |
52 |
Correct |
97 ms |
39532 KB |
Output is correct |
53 |
Correct |
82 ms |
38660 KB |
Output is correct |
54 |
Correct |
99 ms |
39404 KB |
Output is correct |
55 |
Correct |
93 ms |
38636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
31852 KB |
Output is correct |
2 |
Correct |
21 ms |
31724 KB |
Output is correct |
3 |
Correct |
21 ms |
31724 KB |
Output is correct |
4 |
Correct |
21 ms |
31724 KB |
Output is correct |
5 |
Correct |
21 ms |
31724 KB |
Output is correct |
6 |
Correct |
21 ms |
31676 KB |
Output is correct |
7 |
Correct |
21 ms |
31724 KB |
Output is correct |
8 |
Correct |
20 ms |
31724 KB |
Output is correct |
9 |
Correct |
20 ms |
31724 KB |
Output is correct |
10 |
Correct |
21 ms |
31724 KB |
Output is correct |
11 |
Correct |
22 ms |
31724 KB |
Output is correct |
12 |
Correct |
21 ms |
31724 KB |
Output is correct |
13 |
Correct |
23 ms |
31724 KB |
Output is correct |
14 |
Correct |
21 ms |
31724 KB |
Output is correct |
15 |
Correct |
21 ms |
31724 KB |
Output is correct |
16 |
Correct |
21 ms |
31724 KB |
Output is correct |
17 |
Correct |
21 ms |
31724 KB |
Output is correct |
18 |
Correct |
21 ms |
31724 KB |
Output is correct |
19 |
Correct |
21 ms |
31724 KB |
Output is correct |
20 |
Correct |
21 ms |
31744 KB |
Output is correct |
21 |
Correct |
21 ms |
31724 KB |
Output is correct |
22 |
Correct |
22 ms |
31744 KB |
Output is correct |
23 |
Correct |
22 ms |
31724 KB |
Output is correct |
24 |
Correct |
22 ms |
31724 KB |
Output is correct |
25 |
Correct |
21 ms |
31724 KB |
Output is correct |
26 |
Correct |
53 ms |
35052 KB |
Output is correct |
27 |
Correct |
67 ms |
36076 KB |
Output is correct |
28 |
Correct |
50 ms |
34924 KB |
Output is correct |
29 |
Correct |
60 ms |
35716 KB |
Output is correct |
30 |
Correct |
47 ms |
34924 KB |
Output is correct |
31 |
Correct |
65 ms |
39532 KB |
Output is correct |
32 |
Correct |
68 ms |
39788 KB |
Output is correct |
33 |
Correct |
79 ms |
39660 KB |
Output is correct |
34 |
Correct |
68 ms |
39788 KB |
Output is correct |
35 |
Correct |
65 ms |
39532 KB |
Output is correct |
36 |
Correct |
69 ms |
39788 KB |
Output is correct |
37 |
Correct |
71 ms |
39788 KB |
Output is correct |
38 |
Correct |
71 ms |
39788 KB |
Output is correct |
39 |
Correct |
80 ms |
39916 KB |
Output is correct |
40 |
Correct |
83 ms |
40044 KB |
Output is correct |
41 |
Correct |
51 ms |
34924 KB |
Output is correct |
42 |
Correct |
72 ms |
36076 KB |
Output is correct |
43 |
Correct |
68 ms |
36096 KB |
Output is correct |
44 |
Correct |
67 ms |
34828 KB |
Output is correct |
45 |
Correct |
71 ms |
36076 KB |
Output is correct |
46 |
Correct |
51 ms |
34924 KB |
Output is correct |
47 |
Correct |
74 ms |
35820 KB |
Output is correct |
48 |
Correct |
51 ms |
35180 KB |
Output is correct |
49 |
Correct |
63 ms |
35692 KB |
Output is correct |
50 |
Correct |
51 ms |
35052 KB |
Output is correct |
51 |
Correct |
85 ms |
38716 KB |
Output is correct |
52 |
Correct |
97 ms |
39532 KB |
Output is correct |
53 |
Correct |
82 ms |
38660 KB |
Output is correct |
54 |
Correct |
99 ms |
39404 KB |
Output is correct |
55 |
Correct |
93 ms |
38636 KB |
Output is correct |
56 |
Correct |
904 ms |
96208 KB |
Output is correct |
57 |
Correct |
909 ms |
95788 KB |
Output is correct |
58 |
Correct |
834 ms |
92624 KB |
Output is correct |
59 |
Correct |
857 ms |
94216 KB |
Output is correct |
60 |
Correct |
944 ms |
97516 KB |
Output is correct |