답안 #225566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
225566 2020-04-20T21:21:13 Z AKaan37 Mountains (NOI20_mountains) C++17
0 / 100
161 ms 5752 KB
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 300005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,say,tree[li*4],lazy[li*4];
int cev;
map<int,int> mpp;
string s;
vector<int> v;

inline int add(int x,int y){
	if(x+y>=mod)return x+y-mod;
	return x+y;
}

inline int mul(int x,int y){
	return (x%mod)*(y%mod)%mod;
}

inline void push(int node,int start,int end){
	if(!lazy[node])return ;
	tree[node]=add(tree[node],mul((end-start+1),lazy[node]));
	if(start!=end){
		lazy[node*2]=add(lazy[node*2],lazy[node]);
		lazy[node*2+1]=add(lazy[node*2+1],lazy[node]);
	}
	lazy[node]=0;
}

inline void update(int node,int start,int end,int l,int r){
	push(node,start,end);
	if(start>end || start>r || end<l)return ;
	if(start>=l && end<=r){lazy[node]=add(lazy[node],1);push(node,start,end);return ;}
	update(node*2,start,mid,l,r),update(node*2+1,mid+1,end,l,r);
	tree[node]=add(tree[node*2],tree[node*2+1]);
}

inline int query(int node,int start,int end,int l,int r){
	if(start>end || start>r || end<l)return 0;
	push(node,start,end);
	if(start>=l && end<=r){return tree[node];}
	return query(node*2,start,mid,l,r)+query(node*2+1,mid+1,end,l,r);
}

main(void){
	scanf("%lld",&n);
	FOR{
		scanf("%lld",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	FOR{
		if(b[i]==b[i-1] && i!=1)continue;
		mpp[b[i]]=++say;
	}
	int carp=1;
	for(int i=n;i>=1;i--){
		update(1,1,n,mpp[a[i]]+1,n);
		cev=add(cev,mul(carp,query(1,1,n,mpp[a[i]],mpp[a[i]])));
		carp=mul(carp,(n-i+1));
	}
	printf("%lld\n",add(cev,1));
	return 0;
}

Compilation message

Mountains.cpp:71:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(void){
          ^
Mountains.cpp: In function 'int main()':
Mountains.cpp:72:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
  ~~~~~^~~~~~~~~~~
Mountains.cpp:74:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a[i]);
   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 161 ms 5752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 161 ms 5752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 161 ms 5752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -