답안 #557127

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
557127 2022-05-04T18:43:10 Z original_name Mountains (NOI20_mountains) C++17
100 / 100
165 ms 14752 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double db;
typedef string str;

#define mp make_pair
#define f first
#define s second

typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<pi> vpi;

#define all(x) begin(x), end(x)
#define sor(x) sort(all(x))
#define rsor(x) sort(x.rbegin(), x.rend())
#define pb push_back

#define forn(i,a,b) for (int i = (a); i < (b); ++i)
#define fors(i,a,b,s) for (int i = (a); i < (b); i+=s)
#define rofn(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(n) for (int _ = 0; _ < n; _++)
#define each(x, a) for (auto& x: a)
#define debug(x) cout << #x << " = " << x << "\n";
#define vdebug(a) cout << #a << " = "; for(auto x: a) cout << x << " "; cout << "\n";

const int mod = 1e9+7;
const int INF = INT_MAX >> 1;
int add(int a, int b) {return (1LL * a + b) % mod;}
int mul(int a, int b) {return (1LL * a * b) % mod;}

void solve(){
	
}

template<class T> struct st {
	const T ID = 0;  // cmb(ID, a) = a
	T cmb (T a, T b) {return a + b;}  // Function for combining two nodes
	int n; vector<T> tree;
	void set(int size){  // Set segtree size
		for (n = 1; n < size;) n <<= 1;
		tree.assign(2 * n, ID);
	}
	void update(int i, T v){  // Set value at index i to v and update ancestors
		tree[n + i] = v;
		for (i = (n + i)/2; i >= 1; i /= 2) 
			tree[i] = cmb(tree[2 * i], tree[2 * i + 1]);
	}
	T query(int l, int r){  // Query for range [l, r]
		if (l > r) return 0;
		T ra = ID, rb = ID;
		for (l += n, r += n + 1; l < r; l /= 2, r /= 2){
			if (l & 1) ra = cmb(ra, tree[l++]);
			if (r & 1) rb = cmb(tree[--r], rb);
		}
		return cmb(ra, rb);
	}
};

int main () {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector<pair<ll, int > > h(n);
    forn(i, 0, n){
    	cin >> h[i].f;
    	h[i].s = i;
    }
    sor(h);
    st<int> cnt;
    cnt.set(n);
    ll ans = 0;
    forn(i, 0, n){
    	vi ers;
    	while (true){
    		ans += 1LL * cnt.query(0, h[i].s - 1) * cnt.query(h[i].s+1, n-1);
    		ers.pb(h[i].s);
    		if (i >= n - 1 || h[i].f != h[i+1].f) break;
    		i++;
    	}
    	// vdebug(ers)
    	each(i, ers) cnt.update(i, 1);
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 121 ms 14684 KB Output is correct
3 Correct 111 ms 14612 KB Output is correct
4 Correct 117 ms 14600 KB Output is correct
5 Correct 119 ms 14668 KB Output is correct
6 Correct 124 ms 14668 KB Output is correct
7 Correct 121 ms 14596 KB Output is correct
8 Correct 129 ms 14668 KB Output is correct
9 Correct 125 ms 14612 KB Output is correct
10 Correct 124 ms 14704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 10692 KB Output is correct
2 Correct 100 ms 11292 KB Output is correct
3 Correct 99 ms 11260 KB Output is correct
4 Correct 101 ms 11316 KB Output is correct
5 Correct 96 ms 11336 KB Output is correct
6 Correct 91 ms 11328 KB Output is correct
7 Correct 91 ms 11304 KB Output is correct
8 Correct 80 ms 11252 KB Output is correct
9 Correct 85 ms 11308 KB Output is correct
10 Correct 0 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 10692 KB Output is correct
2 Correct 100 ms 11292 KB Output is correct
3 Correct 99 ms 11260 KB Output is correct
4 Correct 101 ms 11316 KB Output is correct
5 Correct 96 ms 11336 KB Output is correct
6 Correct 91 ms 11328 KB Output is correct
7 Correct 91 ms 11304 KB Output is correct
8 Correct 80 ms 11252 KB Output is correct
9 Correct 85 ms 11308 KB Output is correct
10 Correct 0 ms 324 KB Output is correct
11 Correct 116 ms 10128 KB Output is correct
12 Correct 116 ms 10000 KB Output is correct
13 Correct 119 ms 9960 KB Output is correct
14 Correct 109 ms 9964 KB Output is correct
15 Correct 114 ms 9968 KB Output is correct
16 Correct 122 ms 10000 KB Output is correct
17 Correct 119 ms 10000 KB Output is correct
18 Correct 74 ms 10004 KB Output is correct
19 Correct 77 ms 10004 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 5 ms 724 KB Output is correct
12 Correct 5 ms 724 KB Output is correct
13 Correct 5 ms 724 KB Output is correct
14 Correct 5 ms 724 KB Output is correct
15 Correct 7 ms 852 KB Output is correct
16 Correct 7 ms 724 KB Output is correct
17 Correct 8 ms 724 KB Output is correct
18 Correct 6 ms 720 KB Output is correct
19 Correct 4 ms 596 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 10692 KB Output is correct
2 Correct 100 ms 11292 KB Output is correct
3 Correct 99 ms 11260 KB Output is correct
4 Correct 101 ms 11316 KB Output is correct
5 Correct 96 ms 11336 KB Output is correct
6 Correct 91 ms 11328 KB Output is correct
7 Correct 91 ms 11304 KB Output is correct
8 Correct 80 ms 11252 KB Output is correct
9 Correct 85 ms 11308 KB Output is correct
10 Correct 0 ms 324 KB Output is correct
11 Correct 116 ms 10128 KB Output is correct
12 Correct 116 ms 10000 KB Output is correct
13 Correct 119 ms 9960 KB Output is correct
14 Correct 109 ms 9964 KB Output is correct
15 Correct 114 ms 9968 KB Output is correct
16 Correct 122 ms 10000 KB Output is correct
17 Correct 119 ms 10000 KB Output is correct
18 Correct 74 ms 10004 KB Output is correct
19 Correct 77 ms 10004 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 146 ms 10852 KB Output is correct
22 Correct 150 ms 10848 KB Output is correct
23 Correct 139 ms 10968 KB Output is correct
24 Correct 150 ms 10968 KB Output is correct
25 Correct 154 ms 10760 KB Output is correct
26 Correct 130 ms 10832 KB Output is correct
27 Correct 141 ms 10852 KB Output is correct
28 Correct 104 ms 10828 KB Output is correct
29 Correct 93 ms 10848 KB Output is correct
30 Correct 0 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 121 ms 14684 KB Output is correct
3 Correct 111 ms 14612 KB Output is correct
4 Correct 117 ms 14600 KB Output is correct
5 Correct 119 ms 14668 KB Output is correct
6 Correct 124 ms 14668 KB Output is correct
7 Correct 121 ms 14596 KB Output is correct
8 Correct 129 ms 14668 KB Output is correct
9 Correct 125 ms 14612 KB Output is correct
10 Correct 124 ms 14704 KB Output is correct
11 Correct 92 ms 10692 KB Output is correct
12 Correct 100 ms 11292 KB Output is correct
13 Correct 99 ms 11260 KB Output is correct
14 Correct 101 ms 11316 KB Output is correct
15 Correct 96 ms 11336 KB Output is correct
16 Correct 91 ms 11328 KB Output is correct
17 Correct 91 ms 11304 KB Output is correct
18 Correct 80 ms 11252 KB Output is correct
19 Correct 85 ms 11308 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 116 ms 10128 KB Output is correct
22 Correct 116 ms 10000 KB Output is correct
23 Correct 119 ms 9960 KB Output is correct
24 Correct 109 ms 9964 KB Output is correct
25 Correct 114 ms 9968 KB Output is correct
26 Correct 122 ms 10000 KB Output is correct
27 Correct 119 ms 10000 KB Output is correct
28 Correct 74 ms 10004 KB Output is correct
29 Correct 77 ms 10004 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 5 ms 724 KB Output is correct
42 Correct 5 ms 724 KB Output is correct
43 Correct 5 ms 724 KB Output is correct
44 Correct 5 ms 724 KB Output is correct
45 Correct 7 ms 852 KB Output is correct
46 Correct 7 ms 724 KB Output is correct
47 Correct 8 ms 724 KB Output is correct
48 Correct 6 ms 720 KB Output is correct
49 Correct 4 ms 596 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 146 ms 10852 KB Output is correct
52 Correct 150 ms 10848 KB Output is correct
53 Correct 139 ms 10968 KB Output is correct
54 Correct 150 ms 10968 KB Output is correct
55 Correct 154 ms 10760 KB Output is correct
56 Correct 130 ms 10832 KB Output is correct
57 Correct 141 ms 10852 KB Output is correct
58 Correct 104 ms 10828 KB Output is correct
59 Correct 93 ms 10848 KB Output is correct
60 Correct 0 ms 324 KB Output is correct
61 Correct 150 ms 14668 KB Output is correct
62 Correct 156 ms 14752 KB Output is correct
63 Correct 164 ms 14608 KB Output is correct
64 Correct 150 ms 14660 KB Output is correct
65 Correct 152 ms 14736 KB Output is correct
66 Correct 162 ms 14720 KB Output is correct
67 Correct 165 ms 14600 KB Output is correct
68 Correct 156 ms 14600 KB Output is correct
69 Correct 146 ms 10960 KB Output is correct
70 Correct 0 ms 212 KB Output is correct