Submission #291081

# Submission time Handle Problem Language Result Execution time Memory
291081 2020-09-04T16:19:40 Z crossing0ver W (RMI18_w) C++17
50 / 100
113 ms 31680 KB
#include<bits/stdc++.h>
#define int long long 
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
const int mod = 1e9+7;
int cnt[1000005],arr[300005],n;
int POW[5][300005],IN[5][300005],sum[5][300005];
int pw(int a,int n) {
	int y =  1;
	for (;n;n/=2) {
		if (n&1) y = (ll)y*a%mod;
		a = (ll)a*a%mod;
	}
	return y;
}
void solve() {
	for (int i = 2; i <= 4; i++) {
		POW[i][0] = sum[i][0] = 1;
	for (int j = 1; j < 300005; j++) {
		POW[i][j] = (ll)POW[i][j-1]*i%mod;
		sum[i][j] = (sum[i][j-1] + POW[i][j])%mod;
	}
	}
	for (int i = 2; i <= 4; i++) {
		IN[i][0] = 1;
		IN[i][1] = pw(i,mod-2);
		for (int j = 2; j < 300005; j++)
		//	IN[i][j] = pw(POW[i][j],mod-2);
		IN[i][j] = (ll)IN[i][j-1]*IN[i][1]%mod;
	}
	ll ans = 0;
	
	for (int a = 2; a < n; a++) {
		ll z = (ll)(sum[2][n] - sum[2][a])*POW[2][n]%mod*IN[4][a+1]%mod;
		z -= (ll)IN[3][a+1]*(sum[3][n] - sum[3][a])%mod;
		z%=mod;
		z= z*(POW[2][a-2] - 1)%mod;
	//	if (a == 3) cout << (z%mod + mod)%mod <<'\n';
	ans = ans + z;
	}	
//	cout << (ans%mod + mod)%mod;return;
/*	for (int mx = a+1; mx <= n; mx++) {
		ll z = (ll)(POW[2][a-2] - 1)*POW[4][mx-a-1]%mod;
		z = z*POW[2][n-mx]%mod;
		z -= (ll)(POW[2][a-2]-1)*POW[3][mx-a-1]%mod;
		z = (z%mod + mod)%mod;
		ans += z;
	//	ans %= mod;
	}*/
	
	for (int a = 2; a < n; a++) {
	/*for (int mx = a+1; mx < n; mx++) {
		ans += (ll)POW[4][mx-a-1]*POW[2][n-mx]%mod;
		ans -= POW[3][mx-a-1]*2LL%mod;
	}*/
	ll z = (ll)(sum[2][n-1] - sum[2][a])*POW[2][n]%mod*IN[4][a+1]%mod;
	z-= (ll)(sum[3][n-1] - sum[3][a])*IN[3][a+1]*2%mod;
//	z += (ll)(sum[2][n-1] - sum[2][a])*IN[2][a+1]%mod;
	z%=mod;
	ans += z;
	int mx = n;
	ans += (ll)POW[4][mx - a - 1]*POW[2][n-mx]%mod;
	ans -= POW[3][mx-a-1]*2LL%mod;
	ans += POW[2][mx-a-1];
	}
	ans*=2;
	ans = (ans%mod + mod)%mod;
	cout << ans;
	
	
	
	exit(0);
}
main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i< n; i++) {
		cin >> arr[i];
		cnt[arr[i]]++;
	}
	sort(arr,arr+n);
	reverse(arr,arr+n);
	if (arr[n-1] == arr[0]) {
		cout << 0;
		return 0;
	}
	int diff= 1;
	for (int i = 1; i <= 1000000; i++) {
		if (cnt[i] > 1) diff= 0;
	}
	if (diff) solve();
 	for (int i = 1; i <= n; i++) {
		if (arr[i] != arr[i-1]) {
			ll left = i;
			ll right = n - left;
			if (left < 3 || right < 2) {
				cout << 0;
				return 0;
			}
			ll ans = 0;
			for (int i = 1; i <= left - 2; i++)
				ans += (left - i - 1);
			ans *= right - 1;
			cout << ans%(1000000007);
			return 0;
			
			
			
			
		}
	}
	int a[2] = {};
	int c= 0;
	ll ans = 1;
	for (int i = 1; i <= 1000000; i++) {
		if (cnt[i]) {
			c++;
			ans*=(cnt[i] - 1);
		}
	}
	cout << ans*(c/2);
		

}

Compilation message

w.cpp:80:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   80 | main() {
      |      ^
w.cpp: In function 'int main()':
w.cpp:119:6: warning: unused variable 'a' [-Wunused-variable]
  119 |  int a[2] = {};
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 8 ms 888 KB Output is correct
4 Correct 30 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 21496 KB Output is correct
2 Correct 24 ms 21624 KB Output is correct
3 Correct 36 ms 29560 KB Output is correct
4 Correct 55 ms 30076 KB Output is correct
5 Correct 76 ms 27000 KB Output is correct
6 Correct 113 ms 31680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Incorrect 3 ms 384 KB Output isn't correct
4 Incorrect 2 ms 384 KB Output isn't correct
5 Incorrect 3 ms 384 KB Output isn't correct
6 Incorrect 3 ms 384 KB Output isn't correct
7 Incorrect 4 ms 1152 KB Output isn't correct
8 Incorrect 16 ms 1536 KB Output isn't correct
9 Incorrect 31 ms 1920 KB Output isn't correct
10 Incorrect 81 ms 10488 KB Output isn't correct