답안 #894838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894838 2023-12-29T05:42:05 Z vjudge1 Diversity (CEOI21_diversity) C++11
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 3 * 1e5 + 10;
const ll mod = 1e9 + 7;

ll um(ll a, ll b){
	return ((1LL * a * b) % mod + mod) % mod;
}
ll subr(ll a, ll b){
	return ((1LL * a - b) % mod + mod) % mod;
}
ll add(ll a, ll b){
	return (1LL * a + b) % mod;
}
ll binpow(ll x, ll step){
	ll res = 1LL;
	while(step){
		if(step & 1) res = um(res, x);
		x = um(x, x);
		step /= 2;
	}
	return res;
}
int arr[N];
int main() {
	ios::sync_with_stdio(false);
  	cin.tie(NULL);
  	ll n, q;
  	cin >> n >> q;
  	for(ll i = 1; i <= n; i++){
  		cin >> arr[i];
  	}
  	if(n <= 11){
  		for(int i = 0, l, r; i < q; i++){
  			cin >> l >> r;
  			vector <int> vec;
  			for(int j = l; j <= r; j++){
  				vec.pb(arr[j]);
  			}
  			sort(vec.begin(), vec.end());
  			ll ans = 0, cur = 0, cnt = 0;
  			for(int j = 0; j < (int)vec.size(); j++){
  				if(j == 0) cnt++;
  				else{
  					if(vec[j] != vec[j - 1]) cnt++;
  				}
  				cur += cnt;
  			}
  			for(int j = 0; j < (int)vec.size(); j++){
  				ans += cur;
  				cur--;
  				if((int)vec.size() - 1 > j){
  					if(vec[j + 1] != vec[j]) cur -= ((int)vec.size() - j - 1);
  				}
  			}
  			cout << ans << endl;
  		}
  		return 0;
  	}
  	sort(arr + 1, arr + n + 1);
  	ll ans = 0, cnt= 0, cur = 0;
  	for(ll i = 1; i <= n; i++){
  		if(arr[i] != arr[i - 1]) cnt++;
  		cur += cnt;
  	}
  	for(ll i = 1; i <= n; i++){
  		ans += cur;
  		cur--;
  		if(arr[i] != arr[i + 1]) cur -= (n - i);
  	}
  	cout << ans;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -