답안 #1017452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017452 2024-07-09T08:07:43 Z cnn008 Mountains (NOI20_mountains) C++17
100 / 100
141 ms 20236 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef N_N_C
#include "debug.h"
#else
#define cebug(...) "Arya"
#endif

#define int long long

const int N=3e5+5;
const int mod=1e9+7;

int n,a[N],l[N],r[N],ans;
vector <int> compress;
struct BIT{
	#define gb(x) (x&(-x))
   	int n;
   	vector <int> bit;
   	void init(int _n){
   		bit.resize(_n,0);
   		n=_n;
   	}
   	void update(int pos, int val){
   		int i=pos;
      	for (; i<=n; i+=gb(i)) bit[i]+=val;
   	}
   	int get(int pos){
    	int ans=0,i=pos;
      	for (; i>=1; i-=gb(i)) ans+=bit[i];
      	return ans;
   	}
}fwl,fwr;
void sol(){
	fwl.init(N);
	fwr.init(N);
	cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i],compress.push_back(a[i]);
	sort(compress.begin(),compress.end());
	compress.erase(unique(compress.begin(),compress.end()),compress.end());
	for(int i=1; i<=n; i++) a[i]=lower_bound(compress.begin(),compress.end(),a[i])-compress.begin()+1;
	for(int i=1; i<=n; i++){
		l[i]=fwl.get(a[i]-1);
		fwl.update(a[i],1);
	}
	for(int i=n; i>=1; i--){
		r[i]=fwr.get(a[i]-1);
		fwr.update(a[i],1);
		ans+=r[i]*l[i];
	}
	cout<<ans;
}
signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen(".inp", "r", stdin);
    // freopen(".out", "w", stdout);
    int tt=1;
    //cin>>tt; 
    while(tt--){
    	sol();
    }
    cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    return 0;
}
/**  /\_/\
*   (= ._.)
*   / >💖 \>💕
**/

Compilation message

Mountains.cpp:67:9: warning: "/*" within comment [-Wcomment]
   67 | /**  /\_/\
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 64 ms 20144 KB Output is correct
3 Correct 64 ms 20164 KB Output is correct
4 Correct 65 ms 20160 KB Output is correct
5 Correct 64 ms 20160 KB Output is correct
6 Correct 64 ms 20164 KB Output is correct
7 Correct 64 ms 20164 KB Output is correct
8 Correct 68 ms 20236 KB Output is correct
9 Correct 65 ms 20208 KB Output is correct
10 Correct 65 ms 20048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 15196 KB Output is correct
2 Correct 53 ms 15240 KB Output is correct
3 Correct 50 ms 15036 KB Output is correct
4 Correct 52 ms 15040 KB Output is correct
5 Correct 50 ms 15024 KB Output is correct
6 Correct 57 ms 15024 KB Output is correct
7 Correct 54 ms 15164 KB Output is correct
8 Correct 47 ms 15044 KB Output is correct
9 Correct 49 ms 15236 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 15196 KB Output is correct
2 Correct 53 ms 15240 KB Output is correct
3 Correct 50 ms 15036 KB Output is correct
4 Correct 52 ms 15040 KB Output is correct
5 Correct 50 ms 15024 KB Output is correct
6 Correct 57 ms 15024 KB Output is correct
7 Correct 54 ms 15164 KB Output is correct
8 Correct 47 ms 15044 KB Output is correct
9 Correct 49 ms 15236 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 59 ms 15460 KB Output is correct
12 Correct 58 ms 15300 KB Output is correct
13 Correct 61 ms 15304 KB Output is correct
14 Correct 56 ms 15296 KB Output is correct
15 Correct 58 ms 15296 KB Output is correct
16 Correct 56 ms 15296 KB Output is correct
17 Correct 57 ms 15304 KB Output is correct
18 Correct 39 ms 15300 KB Output is correct
19 Correct 40 ms 15304 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 3 ms 5212 KB Output is correct
4 Correct 2 ms 5224 KB Output is correct
5 Correct 2 ms 5212 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 3 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 4 ms 5212 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 3 ms 5212 KB Output is correct
4 Correct 2 ms 5224 KB Output is correct
5 Correct 2 ms 5212 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 3 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 4 ms 5212 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 5 ms 5660 KB Output is correct
12 Correct 5 ms 5724 KB Output is correct
13 Correct 5 ms 5724 KB Output is correct
14 Correct 7 ms 5720 KB Output is correct
15 Correct 5 ms 5720 KB Output is correct
16 Correct 5 ms 5720 KB Output is correct
17 Correct 6 ms 5572 KB Output is correct
18 Correct 5 ms 5724 KB Output is correct
19 Correct 4 ms 5468 KB Output is correct
20 Correct 2 ms 5192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 15196 KB Output is correct
2 Correct 53 ms 15240 KB Output is correct
3 Correct 50 ms 15036 KB Output is correct
4 Correct 52 ms 15040 KB Output is correct
5 Correct 50 ms 15024 KB Output is correct
6 Correct 57 ms 15024 KB Output is correct
7 Correct 54 ms 15164 KB Output is correct
8 Correct 47 ms 15044 KB Output is correct
9 Correct 49 ms 15236 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 59 ms 15460 KB Output is correct
12 Correct 58 ms 15300 KB Output is correct
13 Correct 61 ms 15304 KB Output is correct
14 Correct 56 ms 15296 KB Output is correct
15 Correct 58 ms 15296 KB Output is correct
16 Correct 56 ms 15296 KB Output is correct
17 Correct 57 ms 15304 KB Output is correct
18 Correct 39 ms 15300 KB Output is correct
19 Correct 40 ms 15304 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 102 ms 16324 KB Output is correct
22 Correct 103 ms 16324 KB Output is correct
23 Correct 104 ms 16336 KB Output is correct
24 Correct 116 ms 16324 KB Output is correct
25 Correct 104 ms 16324 KB Output is correct
26 Correct 103 ms 16292 KB Output is correct
27 Correct 103 ms 16400 KB Output is correct
28 Correct 47 ms 16324 KB Output is correct
29 Correct 47 ms 16332 KB Output is correct
30 Correct 2 ms 5176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 64 ms 20144 KB Output is correct
3 Correct 64 ms 20164 KB Output is correct
4 Correct 65 ms 20160 KB Output is correct
5 Correct 64 ms 20160 KB Output is correct
6 Correct 64 ms 20164 KB Output is correct
7 Correct 64 ms 20164 KB Output is correct
8 Correct 68 ms 20236 KB Output is correct
9 Correct 65 ms 20208 KB Output is correct
10 Correct 65 ms 20048 KB Output is correct
11 Correct 51 ms 15196 KB Output is correct
12 Correct 53 ms 15240 KB Output is correct
13 Correct 50 ms 15036 KB Output is correct
14 Correct 52 ms 15040 KB Output is correct
15 Correct 50 ms 15024 KB Output is correct
16 Correct 57 ms 15024 KB Output is correct
17 Correct 54 ms 15164 KB Output is correct
18 Correct 47 ms 15044 KB Output is correct
19 Correct 49 ms 15236 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 59 ms 15460 KB Output is correct
22 Correct 58 ms 15300 KB Output is correct
23 Correct 61 ms 15304 KB Output is correct
24 Correct 56 ms 15296 KB Output is correct
25 Correct 58 ms 15296 KB Output is correct
26 Correct 56 ms 15296 KB Output is correct
27 Correct 57 ms 15304 KB Output is correct
28 Correct 39 ms 15300 KB Output is correct
29 Correct 40 ms 15304 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 5208 KB Output is correct
32 Correct 3 ms 5212 KB Output is correct
33 Correct 3 ms 5212 KB Output is correct
34 Correct 2 ms 5224 KB Output is correct
35 Correct 2 ms 5212 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
37 Correct 3 ms 5212 KB Output is correct
38 Correct 2 ms 5212 KB Output is correct
39 Correct 4 ms 5212 KB Output is correct
40 Correct 2 ms 4956 KB Output is correct
41 Correct 5 ms 5660 KB Output is correct
42 Correct 5 ms 5724 KB Output is correct
43 Correct 5 ms 5724 KB Output is correct
44 Correct 7 ms 5720 KB Output is correct
45 Correct 5 ms 5720 KB Output is correct
46 Correct 5 ms 5720 KB Output is correct
47 Correct 6 ms 5572 KB Output is correct
48 Correct 5 ms 5724 KB Output is correct
49 Correct 4 ms 5468 KB Output is correct
50 Correct 2 ms 5192 KB Output is correct
51 Correct 102 ms 16324 KB Output is correct
52 Correct 103 ms 16324 KB Output is correct
53 Correct 104 ms 16336 KB Output is correct
54 Correct 116 ms 16324 KB Output is correct
55 Correct 104 ms 16324 KB Output is correct
56 Correct 103 ms 16292 KB Output is correct
57 Correct 103 ms 16400 KB Output is correct
58 Correct 47 ms 16324 KB Output is correct
59 Correct 47 ms 16332 KB Output is correct
60 Correct 2 ms 5176 KB Output is correct
61 Correct 128 ms 20112 KB Output is correct
62 Correct 127 ms 20160 KB Output is correct
63 Correct 128 ms 20164 KB Output is correct
64 Correct 131 ms 20004 KB Output is correct
65 Correct 141 ms 20164 KB Output is correct
66 Correct 128 ms 20144 KB Output is correct
67 Correct 129 ms 20104 KB Output is correct
68 Correct 126 ms 20188 KB Output is correct
69 Correct 110 ms 16436 KB Output is correct
70 Correct 3 ms 4956 KB Output is correct