답안 #968032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968032 2024-04-23T07:04:10 Z pcc Real Mountains (CCO23_day1problem2) C++17
0 / 25
2 ms 2396 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;
	int ls = inf,rs = inf;
	for(int i = 1;i<v[0];i++){
		if(arr[i]>all[id])ls = min(ls,arr[i]);
	}
	for(int i = v.back()+1;i<=N;i++){
		if(arr[i]>all[id])rs = min(rs,arr[i]);
	}
	if(v.size() == 1){
		ans += (ls+rs)*(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;
	}
	ans += (ls+rs)*(all[id+1]-all[id])%mod;
	ans += min(ls,rs)*(all[id+1]-all[id])+(all[id]+all[id+1]-1)*(all[id+1]-all[id])/2%mod+(all[id+1]-all[id]);
	ans += 1ll*(v.size()-2)*((all[id+1]+all[id]+1)*(all[id+1]-all[id])/2%mod)%mod*2;
	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<<'\n';
	return 0;
}

Compilation message

Main.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   49 | main(){
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:67: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]
   67 |  for(int i = 0;i+1<all.size();i++){
      |                ~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 2 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 2 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 2 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 2 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 2 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 2 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 2 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -