# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
942236 |
2024-03-10T11:27:03 Z |
Litusiano |
Pilot (NOI19_pilot) |
C++17 |
|
1000 ms |
79084 KB |
#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define endl "\n"
const int MAXN = 1e6+5;
long long calc(pair<int,int> p){
int len = p.second - p.first +1;
return 1LL*(1LL*len*(1LL*len+1))/2;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,m; cin>>n>>m;
vector<int> v(n); for(int& i : v) cin>>i;
vector<int> b(m); for(int& i : b) cin>>i;
set<pair<int,int>> segs; segs.insert({0,n-1}); segs.insert({n,n});
vector<vector<int>> ST(MAXN);
for(int i = 0; i<m; i++) ST[b[i]].push_back(i); // indexed one more
for(int i = 0; i<n; i++) ST[v[i]].push_back(-i-1);
long long ans = 1LL*n*(n+1)/2;
vector<long long> q(m);
// cerr<<MAXN<<endl;
for(int j = MAXN-1; j>=0; j--){
for(int i : ST[j]){
if(i < 0){
// cur seg
if(segs.size() == 0) continue;
int x = -i -1;//i+1
pair<int,int> p = {x, n};
auto it = segs.upper_bound(p);
if(it != segs.begin()) it = prev(it);
pair<int,int> p1 = *it;
// divide p1 in two
int len = p1.second - p1.first +1;
ans -= 1LL*(1LL*len*(1LL*len+1))/2;
pair<int,int> seg1; pair<int,int> seg2;
seg1 = {p1.first, x-1}; seg2 = {x+1, p1.second};
// cerr<<"X: "<<x<<" J: "<<j<<" P1 "<<p1.first<<" "<<p1.second<<" SEG1 "<<seg1.first<<" "<<seg1.second<<" SEG2 "<<seg2.first<<" "<<seg2.second<<endl;
if(seg1.second >= seg1.first) segs.insert(seg1), ans+= 1LL*calc(seg1);
if(seg2.second >= seg2.first) segs.insert(seg2), ans+= 1LL*calc(seg2);
segs.erase(p1);
// cerr<<"SEGS: ";
// for(auto z : segs) cout<<z.first<<" "<<z.second<<" "; cout<<endl;
}
else{
q[i] = ans;
}
}
}
for(long long i : q) cout<<1LL*i<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
7 ms |
23900 KB |
Output is correct |
3 |
Correct |
8 ms |
23900 KB |
Output is correct |
4 |
Correct |
7 ms |
23932 KB |
Output is correct |
5 |
Correct |
7 ms |
23900 KB |
Output is correct |
6 |
Correct |
8 ms |
23896 KB |
Output is correct |
7 |
Correct |
8 ms |
23900 KB |
Output is correct |
8 |
Correct |
8 ms |
23900 KB |
Output is correct |
9 |
Correct |
8 ms |
23900 KB |
Output is correct |
10 |
Correct |
8 ms |
23828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
7 ms |
23900 KB |
Output is correct |
3 |
Correct |
8 ms |
23900 KB |
Output is correct |
4 |
Correct |
7 ms |
23932 KB |
Output is correct |
5 |
Correct |
7 ms |
23900 KB |
Output is correct |
6 |
Correct |
8 ms |
23896 KB |
Output is correct |
7 |
Correct |
8 ms |
23900 KB |
Output is correct |
8 |
Correct |
8 ms |
23900 KB |
Output is correct |
9 |
Correct |
8 ms |
23900 KB |
Output is correct |
10 |
Correct |
8 ms |
23828 KB |
Output is correct |
11 |
Correct |
8 ms |
23900 KB |
Output is correct |
12 |
Correct |
8 ms |
23900 KB |
Output is correct |
13 |
Correct |
8 ms |
23900 KB |
Output is correct |
14 |
Correct |
7 ms |
23896 KB |
Output is correct |
15 |
Correct |
9 ms |
23836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
7 ms |
23900 KB |
Output is correct |
3 |
Correct |
8 ms |
23900 KB |
Output is correct |
4 |
Correct |
7 ms |
23932 KB |
Output is correct |
5 |
Correct |
7 ms |
23900 KB |
Output is correct |
6 |
Correct |
8 ms |
23896 KB |
Output is correct |
7 |
Correct |
8 ms |
23900 KB |
Output is correct |
8 |
Correct |
8 ms |
23900 KB |
Output is correct |
9 |
Correct |
8 ms |
23900 KB |
Output is correct |
10 |
Correct |
8 ms |
23828 KB |
Output is correct |
11 |
Correct |
8 ms |
23900 KB |
Output is correct |
12 |
Correct |
8 ms |
23900 KB |
Output is correct |
13 |
Correct |
8 ms |
23900 KB |
Output is correct |
14 |
Correct |
7 ms |
23896 KB |
Output is correct |
15 |
Correct |
9 ms |
23836 KB |
Output is correct |
16 |
Correct |
8 ms |
23900 KB |
Output is correct |
17 |
Correct |
7 ms |
23896 KB |
Output is correct |
18 |
Correct |
8 ms |
23900 KB |
Output is correct |
19 |
Correct |
8 ms |
23900 KB |
Output is correct |
20 |
Correct |
9 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
7 ms |
23900 KB |
Output is correct |
3 |
Correct |
8 ms |
23900 KB |
Output is correct |
4 |
Correct |
7 ms |
23932 KB |
Output is correct |
5 |
Correct |
7 ms |
23900 KB |
Output is correct |
6 |
Correct |
8 ms |
23896 KB |
Output is correct |
7 |
Correct |
8 ms |
23900 KB |
Output is correct |
8 |
Correct |
8 ms |
23900 KB |
Output is correct |
9 |
Correct |
8 ms |
23900 KB |
Output is correct |
10 |
Correct |
8 ms |
23828 KB |
Output is correct |
11 |
Correct |
8 ms |
23900 KB |
Output is correct |
12 |
Correct |
8 ms |
23900 KB |
Output is correct |
13 |
Correct |
8 ms |
23900 KB |
Output is correct |
14 |
Correct |
7 ms |
23896 KB |
Output is correct |
15 |
Correct |
9 ms |
23836 KB |
Output is correct |
16 |
Correct |
8 ms |
23900 KB |
Output is correct |
17 |
Correct |
7 ms |
23896 KB |
Output is correct |
18 |
Correct |
8 ms |
23900 KB |
Output is correct |
19 |
Correct |
8 ms |
23900 KB |
Output is correct |
20 |
Correct |
9 ms |
23900 KB |
Output is correct |
21 |
Correct |
8 ms |
23900 KB |
Output is correct |
22 |
Correct |
8 ms |
23900 KB |
Output is correct |
23 |
Correct |
9 ms |
23900 KB |
Output is correct |
24 |
Correct |
8 ms |
23900 KB |
Output is correct |
25 |
Correct |
9 ms |
24052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
27284 KB |
Output is correct |
2 |
Correct |
88 ms |
28244 KB |
Output is correct |
3 |
Correct |
60 ms |
27220 KB |
Output is correct |
4 |
Correct |
63 ms |
27988 KB |
Output is correct |
5 |
Correct |
61 ms |
27472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
30488 KB |
Output is correct |
2 |
Correct |
48 ms |
30448 KB |
Output is correct |
3 |
Correct |
45 ms |
30384 KB |
Output is correct |
4 |
Correct |
47 ms |
30548 KB |
Output is correct |
5 |
Correct |
48 ms |
30328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
30888 KB |
Output is correct |
2 |
Correct |
53 ms |
30932 KB |
Output is correct |
3 |
Correct |
54 ms |
30968 KB |
Output is correct |
4 |
Correct |
56 ms |
31056 KB |
Output is correct |
5 |
Correct |
55 ms |
31320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
7 ms |
23900 KB |
Output is correct |
3 |
Correct |
8 ms |
23900 KB |
Output is correct |
4 |
Correct |
7 ms |
23932 KB |
Output is correct |
5 |
Correct |
7 ms |
23900 KB |
Output is correct |
6 |
Correct |
8 ms |
23896 KB |
Output is correct |
7 |
Correct |
8 ms |
23900 KB |
Output is correct |
8 |
Correct |
8 ms |
23900 KB |
Output is correct |
9 |
Correct |
8 ms |
23900 KB |
Output is correct |
10 |
Correct |
8 ms |
23828 KB |
Output is correct |
11 |
Correct |
61 ms |
27284 KB |
Output is correct |
12 |
Correct |
88 ms |
28244 KB |
Output is correct |
13 |
Correct |
60 ms |
27220 KB |
Output is correct |
14 |
Correct |
63 ms |
27988 KB |
Output is correct |
15 |
Correct |
61 ms |
27472 KB |
Output is correct |
16 |
Correct |
56 ms |
27208 KB |
Output is correct |
17 |
Correct |
70 ms |
28244 KB |
Output is correct |
18 |
Correct |
79 ms |
28244 KB |
Output is correct |
19 |
Correct |
58 ms |
26940 KB |
Output is correct |
20 |
Correct |
70 ms |
28204 KB |
Output is correct |
21 |
Correct |
56 ms |
26960 KB |
Output is correct |
22 |
Correct |
65 ms |
27996 KB |
Output is correct |
23 |
Correct |
62 ms |
27224 KB |
Output is correct |
24 |
Correct |
72 ms |
27988 KB |
Output is correct |
25 |
Correct |
60 ms |
27216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
7 ms |
23900 KB |
Output is correct |
3 |
Correct |
8 ms |
23900 KB |
Output is correct |
4 |
Correct |
7 ms |
23932 KB |
Output is correct |
5 |
Correct |
7 ms |
23900 KB |
Output is correct |
6 |
Correct |
8 ms |
23896 KB |
Output is correct |
7 |
Correct |
8 ms |
23900 KB |
Output is correct |
8 |
Correct |
8 ms |
23900 KB |
Output is correct |
9 |
Correct |
8 ms |
23900 KB |
Output is correct |
10 |
Correct |
8 ms |
23828 KB |
Output is correct |
11 |
Correct |
8 ms |
23900 KB |
Output is correct |
12 |
Correct |
8 ms |
23900 KB |
Output is correct |
13 |
Correct |
8 ms |
23900 KB |
Output is correct |
14 |
Correct |
7 ms |
23896 KB |
Output is correct |
15 |
Correct |
9 ms |
23836 KB |
Output is correct |
16 |
Correct |
8 ms |
23900 KB |
Output is correct |
17 |
Correct |
7 ms |
23896 KB |
Output is correct |
18 |
Correct |
8 ms |
23900 KB |
Output is correct |
19 |
Correct |
8 ms |
23900 KB |
Output is correct |
20 |
Correct |
9 ms |
23900 KB |
Output is correct |
21 |
Correct |
8 ms |
23900 KB |
Output is correct |
22 |
Correct |
8 ms |
23900 KB |
Output is correct |
23 |
Correct |
9 ms |
23900 KB |
Output is correct |
24 |
Correct |
8 ms |
23900 KB |
Output is correct |
25 |
Correct |
9 ms |
24052 KB |
Output is correct |
26 |
Correct |
61 ms |
27284 KB |
Output is correct |
27 |
Correct |
88 ms |
28244 KB |
Output is correct |
28 |
Correct |
60 ms |
27220 KB |
Output is correct |
29 |
Correct |
63 ms |
27988 KB |
Output is correct |
30 |
Correct |
61 ms |
27472 KB |
Output is correct |
31 |
Correct |
46 ms |
30488 KB |
Output is correct |
32 |
Correct |
48 ms |
30448 KB |
Output is correct |
33 |
Correct |
45 ms |
30384 KB |
Output is correct |
34 |
Correct |
47 ms |
30548 KB |
Output is correct |
35 |
Correct |
48 ms |
30328 KB |
Output is correct |
36 |
Correct |
53 ms |
30888 KB |
Output is correct |
37 |
Correct |
53 ms |
30932 KB |
Output is correct |
38 |
Correct |
54 ms |
30968 KB |
Output is correct |
39 |
Correct |
56 ms |
31056 KB |
Output is correct |
40 |
Correct |
55 ms |
31320 KB |
Output is correct |
41 |
Correct |
56 ms |
27208 KB |
Output is correct |
42 |
Correct |
70 ms |
28244 KB |
Output is correct |
43 |
Correct |
79 ms |
28244 KB |
Output is correct |
44 |
Correct |
58 ms |
26940 KB |
Output is correct |
45 |
Correct |
70 ms |
28204 KB |
Output is correct |
46 |
Correct |
56 ms |
26960 KB |
Output is correct |
47 |
Correct |
65 ms |
27996 KB |
Output is correct |
48 |
Correct |
62 ms |
27224 KB |
Output is correct |
49 |
Correct |
72 ms |
27988 KB |
Output is correct |
50 |
Correct |
60 ms |
27216 KB |
Output is correct |
51 |
Correct |
82 ms |
30764 KB |
Output is correct |
52 |
Correct |
95 ms |
31888 KB |
Output is correct |
53 |
Correct |
85 ms |
30796 KB |
Output is correct |
54 |
Correct |
105 ms |
31768 KB |
Output is correct |
55 |
Correct |
85 ms |
30800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
7 ms |
23900 KB |
Output is correct |
3 |
Correct |
8 ms |
23900 KB |
Output is correct |
4 |
Correct |
7 ms |
23932 KB |
Output is correct |
5 |
Correct |
7 ms |
23900 KB |
Output is correct |
6 |
Correct |
8 ms |
23896 KB |
Output is correct |
7 |
Correct |
8 ms |
23900 KB |
Output is correct |
8 |
Correct |
8 ms |
23900 KB |
Output is correct |
9 |
Correct |
8 ms |
23900 KB |
Output is correct |
10 |
Correct |
8 ms |
23828 KB |
Output is correct |
11 |
Correct |
8 ms |
23900 KB |
Output is correct |
12 |
Correct |
8 ms |
23900 KB |
Output is correct |
13 |
Correct |
8 ms |
23900 KB |
Output is correct |
14 |
Correct |
7 ms |
23896 KB |
Output is correct |
15 |
Correct |
9 ms |
23836 KB |
Output is correct |
16 |
Correct |
8 ms |
23900 KB |
Output is correct |
17 |
Correct |
7 ms |
23896 KB |
Output is correct |
18 |
Correct |
8 ms |
23900 KB |
Output is correct |
19 |
Correct |
8 ms |
23900 KB |
Output is correct |
20 |
Correct |
9 ms |
23900 KB |
Output is correct |
21 |
Correct |
8 ms |
23900 KB |
Output is correct |
22 |
Correct |
8 ms |
23900 KB |
Output is correct |
23 |
Correct |
9 ms |
23900 KB |
Output is correct |
24 |
Correct |
8 ms |
23900 KB |
Output is correct |
25 |
Correct |
9 ms |
24052 KB |
Output is correct |
26 |
Correct |
61 ms |
27284 KB |
Output is correct |
27 |
Correct |
88 ms |
28244 KB |
Output is correct |
28 |
Correct |
60 ms |
27220 KB |
Output is correct |
29 |
Correct |
63 ms |
27988 KB |
Output is correct |
30 |
Correct |
61 ms |
27472 KB |
Output is correct |
31 |
Correct |
46 ms |
30488 KB |
Output is correct |
32 |
Correct |
48 ms |
30448 KB |
Output is correct |
33 |
Correct |
45 ms |
30384 KB |
Output is correct |
34 |
Correct |
47 ms |
30548 KB |
Output is correct |
35 |
Correct |
48 ms |
30328 KB |
Output is correct |
36 |
Correct |
53 ms |
30888 KB |
Output is correct |
37 |
Correct |
53 ms |
30932 KB |
Output is correct |
38 |
Correct |
54 ms |
30968 KB |
Output is correct |
39 |
Correct |
56 ms |
31056 KB |
Output is correct |
40 |
Correct |
55 ms |
31320 KB |
Output is correct |
41 |
Correct |
56 ms |
27208 KB |
Output is correct |
42 |
Correct |
70 ms |
28244 KB |
Output is correct |
43 |
Correct |
79 ms |
28244 KB |
Output is correct |
44 |
Correct |
58 ms |
26940 KB |
Output is correct |
45 |
Correct |
70 ms |
28204 KB |
Output is correct |
46 |
Correct |
56 ms |
26960 KB |
Output is correct |
47 |
Correct |
65 ms |
27996 KB |
Output is correct |
48 |
Correct |
62 ms |
27224 KB |
Output is correct |
49 |
Correct |
72 ms |
27988 KB |
Output is correct |
50 |
Correct |
60 ms |
27216 KB |
Output is correct |
51 |
Correct |
82 ms |
30764 KB |
Output is correct |
52 |
Correct |
95 ms |
31888 KB |
Output is correct |
53 |
Correct |
85 ms |
30796 KB |
Output is correct |
54 |
Correct |
105 ms |
31768 KB |
Output is correct |
55 |
Correct |
85 ms |
30800 KB |
Output is correct |
56 |
Execution timed out |
1076 ms |
79084 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |