답안 #378368

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378368 2021-03-16T15:12:27 Z Mounir Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
205 ms 14172 KB
#include <bits/stdc++.h>
#define int long long
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define all(v) v.begin(), v.end()
using namespace std;
 
const int MOD = 1e9 + 7, N = 2e5;
set<int> pasVisites;
 
int nInters(int len){
	return ((len * (len + 1))/2)%MOD;
}
 
int subSum(int n){
	return ((n * (n+1))/2)%MOD;
}
 
struct Zone {
	int hauteur, largeur, ind;
	
	bool operator < (const Zone &autre) const {
		if (hauteur != autre.hauteur) return hauteur > autre.hauteur;
		return largeur < autre.largeur;
	}
};
 
 
signed main(){
	int nZones; cin >> nZones;
	vector<int> hauteurs(nZones), largeurs(nZones);
	for (int& hauteur : hauteurs) cin >> hauteur;
	for (int& largeur : largeurs) cin >> largeur;
	
	vector<Zone> zones, pastriees;
	for (int i = 0; i < nZones; ++i){
		if (zones.size() == 0 || zones[zones.size() - 1].hauteur != hauteurs[i])
			zones.push_back({hauteurs[i], 0, (int)zones.size()});
		zones[zones.size() - 1].largeur = (zones[zones.size() - 1].largeur + largeurs[i])%MOD;
	}
	
	
	vector<int> cumul(zones.size());
	for (int i = 0; i < (int)zones.size(); ++i){
		cumul[i] = zones[i].largeur;
		if (i != 0)
			cumul[i] = (cumul[i] + cumul[i - 1])%MOD;
		pasVisites.insert(i);
	}
	
	pastriees = zones;
	sort(all(zones));
	int sum = 0;
	for (Zone& zone : zones){
		pasVisites.erase(zone.ind);
		auto it = pasVisites.upper_bound(zone.ind);
		int gauche = -1, droite = zones.size() - 1;
		if (it != pasVisites.end()) droite = *it - 1;
		if (it != pasVisites.begin()){
			it--;
			gauche = *it;
		}
		int len = cumul[droite];
		if (gauche != -1) len -= cumul[gauche];
		len = (len + MOD)%MOD;
		
		/* Trouver la hauteur */
		int maxi = 0;
		if (gauche != -1) chmax(maxi, pastriees[gauche].hauteur);
		if (droite + 1 < (int)zones.size())chmax(maxi, pastriees[droite + 1].hauteur);
		int s = subSum(zone.hauteur) - subSum(maxi);
		
		sum = (sum + nInters(len) * (s))%MOD;
	}
	cout << sum << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 47 ms 4344 KB Output is correct
4 Correct 84 ms 6388 KB Output is correct
5 Correct 96 ms 7904 KB Output is correct
6 Correct 72 ms 4964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 11 ms 620 KB Output is correct
3 Correct 42 ms 2028 KB Output is correct
4 Correct 85 ms 3820 KB Output is correct
5 Correct 90 ms 3968 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 9 ms 620 KB Output is correct
4 Correct 43 ms 2028 KB Output is correct
5 Correct 87 ms 3948 KB Output is correct
6 Correct 90 ms 4204 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 16 ms 1660 KB Output is correct
9 Correct 51 ms 4196 KB Output is correct
10 Correct 127 ms 13912 KB Output is correct
11 Correct 130 ms 14172 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 372 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 48 ms 4344 KB Output is correct
12 Correct 84 ms 6372 KB Output is correct
13 Correct 97 ms 8028 KB Output is correct
14 Correct 71 ms 4964 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 9 ms 620 KB Output is correct
17 Correct 42 ms 2048 KB Output is correct
18 Correct 84 ms 3860 KB Output is correct
19 Correct 97 ms 4076 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 12 ms 1640 KB Output is correct
22 Correct 51 ms 4196 KB Output is correct
23 Correct 125 ms 13916 KB Output is correct
24 Correct 126 ms 14044 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 15 ms 1640 KB Output is correct
31 Correct 15 ms 1640 KB Output is correct
32 Correct 80 ms 7132 KB Output is correct
33 Correct 83 ms 7264 KB Output is correct
34 Correct 182 ms 13912 KB Output is correct
35 Correct 182 ms 13916 KB Output is correct
36 Correct 192 ms 14040 KB Output is correct
37 Correct 205 ms 14168 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 184 ms 14004 KB Output is correct
40 Correct 155 ms 14040 KB Output is correct
41 Correct 136 ms 14044 KB Output is correct
42 Correct 131 ms 14168 KB Output is correct