Submission #968134

# Submission time Handle Problem Language Result Execution time Memory
968134 2024-04-23T07:54:09 Z pcc Real Mountains (CCO23_day1problem2) C++17
16 / 25
5000 ms 41896 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")


#define ll long long
#define pii pair<int,int>
#define fs first
#define sc second
#define int ll

const ll mod = 1e6+3;
const int inf = 1e9;
const int mxn = 1e6+10;
int arr[mxn],pref[mxn],suf[mxn],tar[mxn];
ll ans = 0;
int N;
vector<int> all;

void up(int id){
	vector<int> v;
	for(int i = 1;i<=N;i++){
		if(arr[i] == all[id]&&tar[i] != arr[i])v.push_back(i);
	}
	if(v.empty())return;
	pii ls = pii(inf,inf),rs = pii(inf,inf);
	for(int i = 1;i<=N;i++){
		if(arr[i]<=all[id])continue;
		if(i<v[0])ls.fs = min(ls.fs,arr[i]);
		else ls.sc = min(ls.sc,arr[i]);
		if(i<v.back())rs.fs = min(rs.fs,arr[i]);
		else rs.sc = min(rs.sc,arr[i]);
	}
	if(v.size() == 1){
		ans += (ls.fs+ls.sc)*(all[id+1]-all[id])+(all[id]+all[id+1]-1)*(all[id+1]-all[id])/2%mod;
		ans %= mod;
		arr[v[0]] = all[id+1];
		return;
	}
	if(ls.fs+ls.sc+rs.sc<=rs.fs+rs.sc+ls.fs){
		ans += (ls.fs+ls.sc)*(all[id+1]-all[id])%mod;
		ans += rs.sc*(all[id+1]-all[id])%mod+(all[id+1]+all[id]+1)*(all[id+1]-all[id])/2%mod;
	}
	else{
		ans += (rs.fs+rs.sc)*(all[id+1]-all[id])%mod;
		ans += ls.fs*(all[id+1]-all[id])%mod+(all[id+1]+all[id]+1)*(all[id+1]-all[id])/2%mod;
	}
	ans %= mod;
	ans += 1ll*(v.size()-2)*((all[id+1]+all[id]+1)*(all[id+1]-all[id])/2%mod*2)%mod;
	ans += 1ll*v.size()*((all[id+1]-1+all[id])*(all[id+1]-all[id])/2%mod)%mod;
	ans %= mod;
	for(auto &i:v)arr[i] = all[id+1];
	return;
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N;
	arr[0] = arr[N+1] = 1e9;
	for(int i = 1;i<=N;i++)cin>>arr[i],all.push_back(arr[i]);
	all.push_back(arr[0]);
	sort(all.begin(),all.end());
	all.erase(unique(all.begin(),all.end()),all.end());
	int mx = 0;
	for(int i = 1;i<=N;i++){
		mx = max(arr[i],mx);
		tar[i] = mx;
	}
	mx = 0;
	for(int i = N;i>=1;i--){
		mx = max(arr[i],mx);
		tar[i] = min(tar[i],mx);
	}
	for(int i = 0;i+1<all.size();i++){
		up(i);
	}
	cout<<ans%mod<<'\n';
	return 0;
}

Compilation message

Main.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main(){
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:76:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |  for(int i = 0;i+1<all.size();i++){
      |                ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 4 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 4 ms 2652 KB Output is correct
17 Correct 4 ms 2652 KB Output is correct
18 Correct 4 ms 2652 KB Output is correct
19 Correct 5 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2524 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 2 ms 2652 KB Output is correct
27 Correct 4 ms 2648 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 4 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 4 ms 2652 KB Output is correct
17 Correct 4 ms 2652 KB Output is correct
18 Correct 4 ms 2652 KB Output is correct
19 Correct 5 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2524 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 2 ms 2652 KB Output is correct
27 Correct 4 ms 2648 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 96 ms 2652 KB Output is correct
36 Correct 97 ms 2648 KB Output is correct
37 Correct 102 ms 2652 KB Output is correct
38 Correct 108 ms 2652 KB Output is correct
39 Correct 98 ms 2904 KB Output is correct
40 Correct 1 ms 2652 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 53 ms 2688 KB Output is correct
44 Correct 53 ms 2648 KB Output is correct
45 Correct 52 ms 2656 KB Output is correct
46 Correct 61 ms 2648 KB Output is correct
47 Correct 64 ms 2652 KB Output is correct
48 Correct 62 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 4 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 4 ms 2652 KB Output is correct
17 Correct 4 ms 2652 KB Output is correct
18 Correct 4 ms 2652 KB Output is correct
19 Correct 5 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2524 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 2 ms 2652 KB Output is correct
27 Correct 4 ms 2648 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 96 ms 2652 KB Output is correct
36 Correct 97 ms 2648 KB Output is correct
37 Correct 102 ms 2652 KB Output is correct
38 Correct 108 ms 2652 KB Output is correct
39 Correct 98 ms 2904 KB Output is correct
40 Correct 1 ms 2652 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 53 ms 2688 KB Output is correct
44 Correct 53 ms 2648 KB Output is correct
45 Correct 52 ms 2656 KB Output is correct
46 Correct 61 ms 2648 KB Output is correct
47 Correct 64 ms 2652 KB Output is correct
48 Correct 62 ms 2648 KB Output is correct
49 Correct 98 ms 2660 KB Output is correct
50 Correct 100 ms 2652 KB Output is correct
51 Correct 98 ms 2648 KB Output is correct
52 Correct 98 ms 2652 KB Output is correct
53 Correct 98 ms 2652 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
55 Correct 1 ms 2652 KB Output is correct
56 Correct 1 ms 2652 KB Output is correct
57 Correct 53 ms 2656 KB Output is correct
58 Correct 54 ms 2652 KB Output is correct
59 Correct 52 ms 2652 KB Output is correct
60 Correct 64 ms 2652 KB Output is correct
61 Correct 62 ms 2660 KB Output is correct
62 Correct 74 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 4 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 4 ms 2652 KB Output is correct
17 Correct 4 ms 2652 KB Output is correct
18 Correct 4 ms 2652 KB Output is correct
19 Correct 5 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2524 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 2 ms 2652 KB Output is correct
27 Correct 4 ms 2648 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 979 ms 41252 KB Output is correct
36 Correct 969 ms 41412 KB Output is correct
37 Correct 959 ms 41376 KB Output is correct
38 Correct 989 ms 41740 KB Output is correct
39 Correct 970 ms 41688 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 171 ms 41156 KB Output is correct
43 Correct 160 ms 41252 KB Output is correct
44 Correct 156 ms 41896 KB Output is correct
45 Correct 524 ms 41180 KB Output is correct
46 Correct 540 ms 41692 KB Output is correct
47 Correct 528 ms 41560 KB Output is correct
48 Correct 694 ms 41416 KB Output is correct
49 Correct 643 ms 41436 KB Output is correct
50 Correct 701 ms 41136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 4 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 4 ms 2652 KB Output is correct
17 Correct 4 ms 2652 KB Output is correct
18 Correct 4 ms 2652 KB Output is correct
19 Correct 5 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2524 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 2 ms 2652 KB Output is correct
27 Correct 4 ms 2648 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 96 ms 2652 KB Output is correct
36 Correct 97 ms 2648 KB Output is correct
37 Correct 102 ms 2652 KB Output is correct
38 Correct 108 ms 2652 KB Output is correct
39 Correct 98 ms 2904 KB Output is correct
40 Correct 1 ms 2652 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 53 ms 2688 KB Output is correct
44 Correct 53 ms 2648 KB Output is correct
45 Correct 52 ms 2656 KB Output is correct
46 Correct 61 ms 2648 KB Output is correct
47 Correct 64 ms 2652 KB Output is correct
48 Correct 62 ms 2648 KB Output is correct
49 Correct 979 ms 41252 KB Output is correct
50 Correct 969 ms 41412 KB Output is correct
51 Correct 959 ms 41376 KB Output is correct
52 Correct 989 ms 41740 KB Output is correct
53 Correct 970 ms 41688 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 171 ms 41156 KB Output is correct
57 Correct 160 ms 41252 KB Output is correct
58 Correct 156 ms 41896 KB Output is correct
59 Correct 524 ms 41180 KB Output is correct
60 Correct 540 ms 41692 KB Output is correct
61 Correct 528 ms 41560 KB Output is correct
62 Correct 694 ms 41416 KB Output is correct
63 Correct 643 ms 41436 KB Output is correct
64 Correct 701 ms 41136 KB Output is correct
65 Execution timed out 5003 ms 25176 KB Time limit exceeded
66 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 4 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 4 ms 2652 KB Output is correct
17 Correct 4 ms 2652 KB Output is correct
18 Correct 4 ms 2652 KB Output is correct
19 Correct 5 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2524 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 2 ms 2652 KB Output is correct
27 Correct 4 ms 2648 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 96 ms 2652 KB Output is correct
36 Correct 97 ms 2648 KB Output is correct
37 Correct 102 ms 2652 KB Output is correct
38 Correct 108 ms 2652 KB Output is correct
39 Correct 98 ms 2904 KB Output is correct
40 Correct 1 ms 2652 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 53 ms 2688 KB Output is correct
44 Correct 53 ms 2648 KB Output is correct
45 Correct 52 ms 2656 KB Output is correct
46 Correct 61 ms 2648 KB Output is correct
47 Correct 64 ms 2652 KB Output is correct
48 Correct 62 ms 2648 KB Output is correct
49 Correct 98 ms 2660 KB Output is correct
50 Correct 100 ms 2652 KB Output is correct
51 Correct 98 ms 2648 KB Output is correct
52 Correct 98 ms 2652 KB Output is correct
53 Correct 98 ms 2652 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
55 Correct 1 ms 2652 KB Output is correct
56 Correct 1 ms 2652 KB Output is correct
57 Correct 53 ms 2656 KB Output is correct
58 Correct 54 ms 2652 KB Output is correct
59 Correct 52 ms 2652 KB Output is correct
60 Correct 64 ms 2652 KB Output is correct
61 Correct 62 ms 2660 KB Output is correct
62 Correct 74 ms 2648 KB Output is correct
63 Correct 979 ms 41252 KB Output is correct
64 Correct 969 ms 41412 KB Output is correct
65 Correct 959 ms 41376 KB Output is correct
66 Correct 989 ms 41740 KB Output is correct
67 Correct 970 ms 41688 KB Output is correct
68 Correct 1 ms 2396 KB Output is correct
69 Correct 1 ms 2396 KB Output is correct
70 Correct 171 ms 41156 KB Output is correct
71 Correct 160 ms 41252 KB Output is correct
72 Correct 156 ms 41896 KB Output is correct
73 Correct 524 ms 41180 KB Output is correct
74 Correct 540 ms 41692 KB Output is correct
75 Correct 528 ms 41560 KB Output is correct
76 Correct 694 ms 41416 KB Output is correct
77 Correct 643 ms 41436 KB Output is correct
78 Correct 701 ms 41136 KB Output is correct
79 Execution timed out 5003 ms 25176 KB Time limit exceeded
80 Halted 0 ms 0 KB -