Submission #307116

# Submission time Handle Problem Language Result Execution time Memory
307116 2020-09-27T06:37:12 Z Hemimor Mountains (NOI20_mountains) C++14
100 / 100
1020 ms 36088 KB
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <random>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

vi vin(int n,int d=0){
	vi a(n);
	for(auto &i:a){
		cin>>i;
		i-=d;
	}
	return a;
}

vl vln(int n,int d=0){
	vl a(n);
	for(auto &i:a){
		cin>>i;
		i-=d;
	}
	return a;
}

vvi gin(int n,int m,int d=1){
	vvi g(n);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u-=d,v-=d;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	return g;
}

void vout(vi a){
	int n=a.size();
	cout<<n<<" :";
	for(auto i:a) cout<<' '<<i;
	cout<<endl;
}

class Segment_Tree{
	private:
	int n;
	vi date;
	public:
	Segment_Tree(int n_){
		n=1;
		while(n<n_) n*=2;
		date=vi(2*n-1);
	}
	void Update(int k,int x){
		k+=n-1;
		date[k]+=x;
		while(k>0){
			k=(k-1)/2;
			date[k]=date[k*2+1]+date[k*2+2];
		}
	}
	int Query(int a,int b){
		a+=n-1;b+=n-1;
		int m=0;
		while(a<b){
			if(a%2==0) m+=date[a++];
			if(b%2==0) m+=date[--b];
			a/=2;b/=2;
		}
		return m;
	}
	int Open(int k){return date[k+n-1];}
};

int n;
vl a;

vi f(){
	Segment_Tree st(n);
	vi b(n);
	for(int i=0;i<n;i++){
		b[i]=st.Query(0,a[i]);
		st.Update(a[i],1);
	}
	reverse(a.begin(),a.end());
	return b;
}

int main(){
	cin>>n;
	a=vln(n);
	vl b=a;
	sort(b.begin(),b.end());
	map<ll,int> mp;
	for(int i=0;i<n;i++) mp[b[i]]=i;
	for(int i=0;i<n;i++) a[i]=mp[a[i]];
	vi c=f(),d=f();
	ll res=0;
	for(int i=0;i<n;i++) res+=(ll)c[i]*d[n-i-1];
	cout<<res<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 640 ms 35848 KB Output is correct
3 Correct 640 ms 36088 KB Output is correct
4 Correct 637 ms 36084 KB Output is correct
5 Correct 643 ms 35828 KB Output is correct
6 Correct 633 ms 35972 KB Output is correct
7 Correct 634 ms 35956 KB Output is correct
8 Correct 644 ms 36084 KB Output is correct
9 Correct 619 ms 26996 KB Output is correct
10 Correct 611 ms 26740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 11424 KB Output is correct
2 Correct 150 ms 11508 KB Output is correct
3 Correct 168 ms 11548 KB Output is correct
4 Correct 150 ms 11420 KB Output is correct
5 Correct 150 ms 11512 KB Output is correct
6 Correct 152 ms 11508 KB Output is correct
7 Correct 149 ms 11508 KB Output is correct
8 Correct 144 ms 11508 KB Output is correct
9 Correct 142 ms 11508 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 11424 KB Output is correct
2 Correct 150 ms 11508 KB Output is correct
3 Correct 168 ms 11548 KB Output is correct
4 Correct 150 ms 11420 KB Output is correct
5 Correct 150 ms 11512 KB Output is correct
6 Correct 152 ms 11508 KB Output is correct
7 Correct 149 ms 11508 KB Output is correct
8 Correct 144 ms 11508 KB Output is correct
9 Correct 142 ms 11508 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 212 ms 11508 KB Output is correct
12 Correct 218 ms 11508 KB Output is correct
13 Correct 211 ms 11508 KB Output is correct
14 Correct 212 ms 11508 KB Output is correct
15 Correct 211 ms 11508 KB Output is correct
16 Correct 213 ms 11508 KB Output is correct
17 Correct 211 ms 11540 KB Output is correct
18 Correct 171 ms 11508 KB Output is correct
19 Correct 170 ms 11416 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 23 ms 1532 KB Output is correct
12 Correct 22 ms 1524 KB Output is correct
13 Correct 22 ms 1532 KB Output is correct
14 Correct 23 ms 1532 KB Output is correct
15 Correct 22 ms 1660 KB Output is correct
16 Correct 22 ms 1532 KB Output is correct
17 Correct 22 ms 1532 KB Output is correct
18 Correct 23 ms 1152 KB Output is correct
19 Correct 8 ms 768 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 11424 KB Output is correct
2 Correct 150 ms 11508 KB Output is correct
3 Correct 168 ms 11548 KB Output is correct
4 Correct 150 ms 11420 KB Output is correct
5 Correct 150 ms 11512 KB Output is correct
6 Correct 152 ms 11508 KB Output is correct
7 Correct 149 ms 11508 KB Output is correct
8 Correct 144 ms 11508 KB Output is correct
9 Correct 142 ms 11508 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 212 ms 11508 KB Output is correct
12 Correct 218 ms 11508 KB Output is correct
13 Correct 211 ms 11508 KB Output is correct
14 Correct 212 ms 11508 KB Output is correct
15 Correct 211 ms 11508 KB Output is correct
16 Correct 213 ms 11508 KB Output is correct
17 Correct 211 ms 11540 KB Output is correct
18 Correct 171 ms 11508 KB Output is correct
19 Correct 170 ms 11416 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 489 ms 17432 KB Output is correct
22 Correct 500 ms 17400 KB Output is correct
23 Correct 500 ms 17396 KB Output is correct
24 Correct 501 ms 17524 KB Output is correct
25 Correct 495 ms 17524 KB Output is correct
26 Correct 503 ms 17524 KB Output is correct
27 Correct 496 ms 17524 KB Output is correct
28 Correct 314 ms 17524 KB Output is correct
29 Correct 317 ms 17396 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 640 ms 35848 KB Output is correct
3 Correct 640 ms 36088 KB Output is correct
4 Correct 637 ms 36084 KB Output is correct
5 Correct 643 ms 35828 KB Output is correct
6 Correct 633 ms 35972 KB Output is correct
7 Correct 634 ms 35956 KB Output is correct
8 Correct 644 ms 36084 KB Output is correct
9 Correct 619 ms 26996 KB Output is correct
10 Correct 611 ms 26740 KB Output is correct
11 Correct 154 ms 11424 KB Output is correct
12 Correct 150 ms 11508 KB Output is correct
13 Correct 168 ms 11548 KB Output is correct
14 Correct 150 ms 11420 KB Output is correct
15 Correct 150 ms 11512 KB Output is correct
16 Correct 152 ms 11508 KB Output is correct
17 Correct 149 ms 11508 KB Output is correct
18 Correct 144 ms 11508 KB Output is correct
19 Correct 142 ms 11508 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 212 ms 11508 KB Output is correct
22 Correct 218 ms 11508 KB Output is correct
23 Correct 211 ms 11508 KB Output is correct
24 Correct 212 ms 11508 KB Output is correct
25 Correct 211 ms 11508 KB Output is correct
26 Correct 213 ms 11508 KB Output is correct
27 Correct 211 ms 11540 KB Output is correct
28 Correct 171 ms 11508 KB Output is correct
29 Correct 170 ms 11416 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 2 ms 416 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 0 ms 256 KB Output is correct
41 Correct 23 ms 1532 KB Output is correct
42 Correct 22 ms 1524 KB Output is correct
43 Correct 22 ms 1532 KB Output is correct
44 Correct 23 ms 1532 KB Output is correct
45 Correct 22 ms 1660 KB Output is correct
46 Correct 22 ms 1532 KB Output is correct
47 Correct 22 ms 1532 KB Output is correct
48 Correct 23 ms 1152 KB Output is correct
49 Correct 8 ms 768 KB Output is correct
50 Correct 1 ms 256 KB Output is correct
51 Correct 489 ms 17432 KB Output is correct
52 Correct 500 ms 17400 KB Output is correct
53 Correct 500 ms 17396 KB Output is correct
54 Correct 501 ms 17524 KB Output is correct
55 Correct 495 ms 17524 KB Output is correct
56 Correct 503 ms 17524 KB Output is correct
57 Correct 496 ms 17524 KB Output is correct
58 Correct 314 ms 17524 KB Output is correct
59 Correct 317 ms 17396 KB Output is correct
60 Correct 1 ms 256 KB Output is correct
61 Correct 979 ms 35828 KB Output is correct
62 Correct 968 ms 35868 KB Output is correct
63 Correct 1020 ms 35868 KB Output is correct
64 Correct 976 ms 35828 KB Output is correct
65 Correct 981 ms 35868 KB Output is correct
66 Correct 983 ms 35864 KB Output is correct
67 Correct 976 ms 35828 KB Output is correct
68 Correct 877 ms 26868 KB Output is correct
69 Correct 560 ms 21492 KB Output is correct
70 Correct 1 ms 256 KB Output is correct